Class: RightDevelop::CI::Formatters::RSpecV1

Inherits:
Spec::Runner::Formatter::BaseTextFormatter
  • Object
show all
Defined in:
lib/right_develop/ci/formatters/rspec_v1.rb

Overview

JUnit XML output formatter for RSpec 1.x

Instance Method Summary collapse

Constructor Details

#initialize(options, output) ⇒ RSpecV1

Returns a new instance of RSpecV1.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/right_develop/ci/formatters/rspec_v1.rb', line 9

def initialize(options, output)
  super
  @current_example_group = nil
  @test_times = {}
  @test_groups = {}
  @test_results = {}
  @test_failures = {}
  @progress = Spec::Runner::Formatter::ProgressBarFormatter.new(options, STDOUT)
  @summary = Spec::Runner::Formatter::BaseTextFormatter.new(options, STDOUT)

  if ENV.key?('RIGHT_DEVELOP_FAIL_FAST')
    Spec::Runner.configuration.prepend_before(:each) do
      pending if (ENV['RIGHT_DEVELOP_FAIL_FAST'].to_i == 0)
    end
  end
end

Instance Method Details

#dump_failure(counter, failure) ⇒ Object



107
108
109
# File 'lib/right_develop/ci/formatters/rspec_v1.rb', line 107

def dump_failure(counter, failure)
  # no-op; our XML summary contains everything
end

#dump_pendingObject



111
112
113
# File 'lib/right_develop/ci/formatters/rspec_v1.rb', line 111

def dump_pending()
  @summary.dump_pending if @test_failures.size == 0
end

#dump_summary(duration, example_count, failure_count, pending_count) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/right_develop/ci/formatters/rspec_v1.rb', line 74

def dump_summary(duration, example_count, failure_count, pending_count)
  builder = Builder::XmlMarkup.new :indent => 2
  builder.instruct! :xml, :version => "1.0", :encoding => "UTF-8"
  builder.testsuite :errors => 0, :failures => failure_count, :skipped => pending_count, :tests => example_count, :time => duration, :timestamp => Time.now.iso8601 do
    builder.properties
    @test_results.each_pair do |test, result|
      classname        = purify(classname_for(test))
      full_description = purify(test.description)

      # The full description always begins with the classname, but this is useless info when
      # generating the XML report.
      if full_description.start_with?(classname)
        full_description = full_description[classname.length..-1].strip
      end

      builder.testcase(:classname => classname.to_sym, :name => full_description, :time => @test_times[test]) do
        case result
        when "failed"
          builder.failure :message => "failed #{full_description}", :type => "failed" do
            builder.cdata! purify(failure_details_for(test))
          end
        when "pending" then
          builder.skipped
        end
      end
    end
  end
  output.puts builder.target!

  puts
  @summary.dump_summary(duration, example_count, failure_count, pending_count)
end

#example_failed(example, counter, failure) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/right_develop/ci/formatters/rspec_v1.rb', line 49

def example_failed(example, counter, failure)
  @test_groups[example] ||= @current_example_group
  @test_times[example] = Time.now - @example_started_at
  @test_results[example] = 'failed'
  @test_failures[example] = failure

  @progress.example_failed(example, counter, failure)

  puts
  @summary.dump_failure(counter, failure)

  # Decrease fail-fast counter by 1
  if ENV.key?('RIGHT_DEVELOP_FAIL_FAST')
    ENV['RIGHT_DEVELOP_FAIL_FAST'] = String(ENV['RIGHT_DEVELOP_FAIL_FAST'].to_i - 1)
  end
end

#example_group_started(example) ⇒ Object



26
27
28
29
30
31
# File 'lib/right_develop/ci/formatters/rspec_v1.rb', line 26

def example_group_started(example)
  @current_example_group = example

  @progress.example_group_started(example)
  @summary.example_group_started(example)
end

#example_passed(example) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/right_develop/ci/formatters/rspec_v1.rb', line 41

def example_passed(example)
  @test_groups[example] ||= @current_example_group
  @test_times[example] = Time.now - @example_started_at
  @test_results[example] = 'passed'

  @progress.example_passed(example)
end

#example_pending(example, message, deprecated_pending_location = nil) ⇒ Object



66
67
68
69
70
71
72
# File 'lib/right_develop/ci/formatters/rspec_v1.rb', line 66

def example_pending(example, message, deprecated_pending_location=nil)
  @test_groups[example] ||= @current_example_group
  @test_times[example] = Time.now - @example_started_at
  @test_results[example] = 'pending'

  @progress.example_pending(example, message, deprecated_pending_location)
end

#example_started(example) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/right_develop/ci/formatters/rspec_v1.rb', line 33

def example_started(example)
  @test_groups[example] ||= @current_example_group
  @example_started_at = Time.now

  @progress.example_started(example)
  #@summary.example_started(example)
end