class RoxClient::RSpec::Formatter

Public Class Methods

new(output) click to toggle source
# File lib/rox-client-rspec/formatter.rb, line 12
def initialize output

  config = RoxClient::RSpec.config
  @client = Client.new config.server, config.client_options
  @test_run = TestRun.new config.project

  @groups = []
end

Public Instance Methods

close(notification) click to toggle source
# File lib/rox-client-rspec/formatter.rb, line 52
def close notification
  @client.process @test_run
end
example_failed(example_notification) click to toggle source
# File lib/rox-client-rspec/formatter.rb, line 42
def example_failed example_notification
  add_result example_notification, false
end
example_group_finished(group_notification) click to toggle source
# File lib/rox-client-rspec/formatter.rb, line 30
def example_group_finished group_notification
  @groups.pop
end
example_group_started(group_notification) click to toggle source
# File lib/rox-client-rspec/formatter.rb, line 26
def example_group_started group_notification
  @groups << group_notification.group
end
example_passed(example_notification) click to toggle source
# File lib/rox-client-rspec/formatter.rb, line 38
def example_passed example_notification
  add_result example_notification, true
end
example_started(example_notification) click to toggle source
# File lib/rox-client-rspec/formatter.rb, line 34
def example_started example_notification
  @current_time = Time.now
end
start(notification) click to toggle source
# File lib/rox-client-rspec/formatter.rb, line 21
def start notification
  # TODO: measure milliseconds
  @start_time = Time.now
end
stop(notification) click to toggle source
# File lib/rox-client-rspec/formatter.rb, line 46
def stop notification
  end_time = Time.now
  @test_run.end_time = end_time.to_i * 1000
  @test_run.duration = ((end_time - @start_time) * 1000).round
end

Private Instance Methods

add_result(example_notification, successful) click to toggle source
# File lib/rox-client-rspec/formatter.rb, line 58
def add_result example_notification, successful

  options = {
    passed: successful,
    duration: ((Time.now - @current_time) * 1000).round
  }

  options[:message] = failure_message example_notification unless successful

  @test_run.add_result example_notification.example, @groups, options
end
failure_message(example_notification) click to toggle source
# File lib/rox-client-rspec/formatter.rb, line 70
def failure_message example_notification
  String.new.tap do |m|
    m << example_notification.description
    m << "\n"
    m << example_notification.message_lines.collect{ |l| "  #{l}" }.join("\n")
    m << "\n"
    m << example_notification.formatted_backtrace.collect{ |l| "  # #{l}" }.join("\n")
  end
end
full_example_name(example) click to toggle source
# File lib/rox-client-rspec/formatter.rb, line 80
def full_example_name example
  (@groups.collect{ |g| g.description.strip } << example.description.strip).join ' '
end