turnip_formatter 0.6.0.pre.beta.2 → 0.6.0.pre.beta.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +0 -1
  3. data/Rakefile +3 -2
  4. data/lib/rspec/core/formatters/turnip_formatter.rb +8 -9
  5. data/lib/turnip_formatter/ext/turnip/rspec.rb +6 -5
  6. data/lib/turnip_formatter/{template → renderer/html/assets}/turnip_formatter.css +1 -1
  7. data/lib/turnip_formatter/{template → renderer/html/assets}/turnip_formatter.js +0 -0
  8. data/lib/turnip_formatter/{template → renderer/html/assets}/turnip_formatter.scss +1 -1
  9. data/lib/turnip_formatter/renderer/html/base.rb +4 -4
  10. data/lib/turnip_formatter/renderer/html/index.rb +83 -0
  11. data/lib/turnip_formatter/renderer/html/runtime_error.rb +20 -0
  12. data/lib/turnip_formatter/renderer/html/scenario.rb +20 -0
  13. data/lib/turnip_formatter/renderer/html/statistics_feature.rb +45 -0
  14. data/lib/turnip_formatter/renderer/html/statistics_speed.rb +39 -0
  15. data/lib/turnip_formatter/renderer/html/statistics_tag.rb +53 -0
  16. data/lib/turnip_formatter/renderer/html/views/index.html.erb +94 -0
  17. data/lib/turnip_formatter/renderer/html/views/runtime_error.html.erb +20 -0
  18. data/lib/turnip_formatter/renderer/html/views/scenario.html.erb +23 -0
  19. data/lib/turnip_formatter/renderer/html/views/statistics_feature.html.erb +24 -0
  20. data/lib/turnip_formatter/renderer/html/views/statistics_speed.html.erb +24 -0
  21. data/lib/turnip_formatter/renderer/html/views/statistics_tag.html.erb +24 -0
  22. data/lib/turnip_formatter/renderer/html.rb +84 -0
  23. data/lib/turnip_formatter/resource/scenario/base.rb +80 -0
  24. data/lib/turnip_formatter/resource/scenario/failure.rb +50 -0
  25. data/lib/turnip_formatter/resource/scenario/pass.rb +10 -0
  26. data/lib/turnip_formatter/resource/scenario/pending.rb +42 -0
  27. data/lib/turnip_formatter/version.rb +1 -1
  28. data/lib/turnip_formatter.rb +8 -4
  29. data/test/helper.rb +64 -12
  30. data/test/turnip_formatter/renderer/html/test_index.rb +102 -0
  31. data/test/turnip_formatter/renderer/html/test_runtime_error.rb +40 -0
  32. data/test/turnip_formatter/renderer/html/test_statistics_feature.rb +102 -0
  33. data/test/turnip_formatter/renderer/html/test_statistics_speed.rb +77 -0
  34. data/test/turnip_formatter/renderer/html/test_statistics_tag.rb +112 -0
  35. data/test/turnip_formatter/renderer/html/test_step.rb +27 -0
  36. data/test/turnip_formatter/renderer/test_html.rb +75 -0
  37. data/test/turnip_formatter/resource/scenario/test_failure.rb +39 -0
  38. data/test/turnip_formatter/resource/scenario/test_pass.rb +65 -0
  39. data/test/turnip_formatter/resource/scenario/test_pending.rb +39 -0
  40. data/turnip_formatter.gemspec +1 -1
  41. metadata +45 -57
  42. data/lib/turnip_formatter/printer/index.rb +0 -26
  43. data/lib/turnip_formatter/printer/runtime_error.rb +0 -36
  44. data/lib/turnip_formatter/printer/scenario.rb +0 -22
  45. data/lib/turnip_formatter/printer/tab_feature_statistics.rb +0 -46
  46. data/lib/turnip_formatter/printer/tab_speed_statistics.rb +0 -35
  47. data/lib/turnip_formatter/printer/tab_tag_statistics.rb +0 -76
  48. data/lib/turnip_formatter/printer.rb +0 -29
  49. data/lib/turnip_formatter/scenario/base.rb +0 -99
  50. data/lib/turnip_formatter/scenario/failure.rb +0 -44
  51. data/lib/turnip_formatter/scenario/pass.rb +0 -8
  52. data/lib/turnip_formatter/scenario/pending.rb +0 -40
  53. data/lib/turnip_formatter/step.rb +0 -23
  54. data/lib/turnip_formatter/template/exception.slim +0 -8
  55. data/lib/turnip_formatter/template/index.slim +0 -86
  56. data/lib/turnip_formatter/template/runtime_exception.slim +0 -13
  57. data/lib/turnip_formatter/template/scenario.slim +0 -15
  58. data/lib/turnip_formatter/template/tab_feature_statistics.slim +0 -18
  59. data/lib/turnip_formatter/template/tab_speed_statistics.slim +0 -16
  60. data/lib/turnip_formatter/template/tab_tag_statistics.slim +0 -18
  61. data/spec/turnip_formatter/printer/index_spec.rb +0 -38
  62. data/spec/turnip_formatter/printer/scenario_spec.rb +0 -42
  63. data/spec/turnip_formatter/printer/tab_feature_statistics_spec.rb +0 -80
  64. data/spec/turnip_formatter/printer/tab_speed_statistics_spec.rb +0 -48
  65. data/spec/turnip_formatter/printer/tab_tag_statistics_spec.rb +0 -103
  66. data/spec/turnip_formatter/scenario/base_spec.rb +0 -67
  67. data/spec/turnip_formatter/scenario/failure_spec.rb +0 -55
  68. data/spec/turnip_formatter/scenario/pending_spec.rb +0 -51
  69. data/spec/turnip_formatter/template_spec.rb +0 -119
  70. data/test/sample.feature +0 -16
@@ -0,0 +1,50 @@
1
+ require 'turnip_formatter/resource/scenario/base'
2
+
3
+ module TurnipFormatter
4
+ module Resource
5
+ module Scenario
6
+ class Failure < Base
7
+ #
8
+ # Return steps
9
+ #
10
+ # example:
11
+ #
12
+ # When foo
13
+ # And bar
14
+ # And baz <= failed line
15
+ # Then piyo
16
+ #
17
+ # #<Step 'foo'>.status = :passed
18
+ # #<Step 'bar'>.status = :passed
19
+ # #<Step 'baz'>.status = :failed
20
+ # #<Step 'piyo'>.status = :unexecute
21
+ #
22
+ #
23
+ # @todo failed_at_before_hook, failed_at_after_hook GH-67
24
+ #
25
+ def steps
26
+ steps = super
27
+
28
+ arys = steps.group_by { |s| (s.line <=> failed_line_number).to_s }
29
+ arys['-1'].each { |s| s.status = :passed } unless arys['-1'].nil?
30
+ arys['0'].each { |s| s.status = :failed } unless arys['0'].nil?
31
+ arys['1'].each { |s| s.status = :unexecute } unless arys['1'].nil?
32
+
33
+ steps
34
+ end
35
+
36
+ private
37
+
38
+ def failed_line_number
39
+ @failed_line_number ||= (
40
+ filepath = File.basename(feature_file_path)
41
+ line = example.exception.backtrace.find do |backtrace|
42
+ backtrace.match(/#{filepath}:(\d+)/)
43
+ end
44
+ Regexp.last_match[1].to_i if line
45
+ )
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,10 @@
1
+ require 'turnip_formatter/resource/scenario/base'
2
+
3
+ module TurnipFormatter
4
+ module Resource
5
+ module Scenario
6
+ class Pass < Base
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,42 @@
1
+ require 'turnip_formatter/resource/scenario/base'
2
+
3
+ module TurnipFormatter
4
+ module Resource
5
+ module Scenario
6
+ class Pending < Base
7
+ #
8
+ # Return steps
9
+ #
10
+ # example:
11
+ #
12
+ # When foo
13
+ # And bar
14
+ # And baz <= pending line
15
+ # Then piyo
16
+ #
17
+ # #<Step 'foo'>.status = :passed
18
+ # #<Step 'bar'>.status = :passed
19
+ # #<Step 'baz'>.status = :pending
20
+ # #<Step 'piyo'>.status = :unexecute
21
+ #
22
+ def steps
23
+ steps = super
24
+
25
+ arys = steps.group_by { |s| (s.line <=> pending_line_number).to_s }
26
+
27
+ arys['-1'].each { |s| s.status = :passed } unless arys['-1'].nil?
28
+ arys['0'].each { |s| s.status = :pending } unless arys['0'].nil?
29
+ arys['1'].each { |s| s.status = :unexecute } unless arys['1'].nil?
30
+
31
+ steps
32
+ end
33
+
34
+ private
35
+
36
+ def pending_line_number
37
+ example.metadata[:line_number]
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -1,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  module TurnipFormatter
4
- VERSION = '0.6.0-beta.2'
4
+ VERSION = '0.6.0-beta.3'
5
5
  end
@@ -1,5 +1,6 @@
1
1
  require 'turnip_formatter/version'
2
2
  require 'turnip'
3
+ require 'turnip_formatter/renderer/html'
3
4
 
4
5
  module TurnipFormatter
5
6
  class << self
@@ -21,7 +22,7 @@ module TurnipFormatter
21
22
  stylesheets = [stylesheets] if stylesheets.is_a? String
22
23
 
23
24
  stylesheets.each do |s|
24
- TurnipFormatter::Template.add_stylesheet(s)
25
+ TurnipFormatter::Renderer::Html.add_stylesheet(s)
25
26
  end
26
27
  end
27
28
 
@@ -29,7 +30,7 @@ module TurnipFormatter
29
30
  scripts = [scripts] if scripts.is_a? String
30
31
 
31
32
  scripts.each do |s|
32
- TurnipFormatter::Template.add_javascript(s)
33
+ TurnipFormatter::Renderer::Html.add_javascript(s)
33
34
  end
34
35
  end
35
36
 
@@ -43,11 +44,9 @@ module TurnipFormatter
43
44
  end
44
45
 
45
46
  require 'rspec/core/formatters/turnip_formatter'
46
- require 'turnip_formatter/template'
47
47
  require 'turnip_formatter/step_template/exception'
48
48
  require 'turnip_formatter/step_template/source'
49
49
  require 'turnip_formatter/ext/turnip/rspec'
50
- require 'turnip_formatter/printer/index'
51
50
  end
52
51
 
53
52
  RSpecTurnipFormatter = RSpec::Core::Formatters::TurnipFormatter
@@ -55,3 +54,8 @@ RSpecTurnipFormatter = RSpec::Core::Formatters::TurnipFormatter
55
54
  TurnipFormatter.configure do |config|
56
55
  config.title = 'Turnip'
57
56
  end
57
+
58
+ (File.dirname(__FILE__) + '/turnip_formatter/renderer/html/assets').tap do |dirname|
59
+ TurnipFormatter::Renderer::Html.add_stylesheet(dirname + '/turnip_formatter.css')
60
+ TurnipFormatter::Renderer::Html.add_javascript(dirname + '/turnip_formatter.js')
61
+ end
data/test/helper.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require 'test/unit'
2
2
  require 'oga'
3
+ require 'tempfile'
4
+ require 'turnip_formatter/ext/turnip/rspec'
3
5
 
4
6
  def html_parse(str)
5
7
  Oga.parse_xml(str)
@@ -7,25 +9,75 @@ end
7
9
 
8
10
  module TurnipFormatter
9
11
  module TestHelper
10
- @@sample_feature = nil
11
-
12
- def sample_step
13
- sample_feature.scenarios[0].steps[0]
12
+ class NoopObject
13
+ def method_missing(name, *args, &block)
14
+ # nooooooop
15
+ end
14
16
  end
15
17
 
16
- def sample_step_with_docstring
17
- sample_feature.scenarios[0].steps[1]
18
+ #
19
+ # @param text [String] feature text
20
+ # @return [Turnip::Node::Feature]
21
+ #
22
+ def feature_build(text)
23
+ Tempfile.create(['turnip_formatter_test', '.feature']) do |f|
24
+ f.write(text)
25
+ f.flush
26
+ Turnip::Builder.build(f.path)
27
+ end
18
28
  end
19
29
 
20
- def sample_step_with_datatable
21
- sample_feature.scenarios[0].steps[2]
30
+ #
31
+ # Override Turnip::Execute#step
32
+ #
33
+ module ExecuteWrapper
34
+ def step(s)
35
+ case s.text
36
+ when /^\[ERROR\]/
37
+ expect(true).to be false
38
+ when /^\[PENDING\]/
39
+ raise Turnip::Pending
40
+ else
41
+ expect(true).to be true
42
+ end
43
+ end
22
44
  end
23
45
 
24
- def sample_feature
25
- return @@sample_feature if @@sample_feature
46
+ #
47
+ # Emulate Turnip::RSpec#run_feature
48
+ #
49
+ # @param feature [Turnip::Node::Feature]
50
+ # @param failed_at [Array<Interger>] Line numbers to assume that test fails
51
+ # @param feature_file_path [String]
52
+ #
53
+ # @return [Array<RSpec::Core::Example>] Array of example for scenarios.
54
+ #
55
+ # e.g.:
56
+ #
57
+ # Feature: ...
58
+ # Scenario: xxx
59
+ # When I
60
+ # Then do
61
+ # Scenario: yyy
62
+ # When He
63
+ # Then do
64
+ #
65
+ # # => [<RSpec::Core::Example "I->do">, <RSpec::Core::Example "He->do">]
66
+ #
67
+ # @see {Turnip::RSpec.run_feature}
68
+ #
69
+ def run_feature(feature, filename)
70
+ rspec_context = ::RSpec::Core::ExampleGroup.describe(feature.name)
71
+ rspec_context.include(Turnip::RSpec::Execute)
72
+ rspec_context.include(ExecuteWrapper)
73
+
74
+ Turnip::RSpec.__send__(:run_feature, rspec_context, feature, filename)
75
+ rspec_context.run(NoopObject.new)
76
+ Turnip::RSpec.update_metadata(feature, rspec_context)
26
77
 
27
- filename = File.expand_path('./sample.feature', File.dirname(__FILE__))
28
- @@sample_feature = Turnip::Builder.build(filename)
78
+ rspec_context.children.map do |scenario|
79
+ scenario.examples.first
80
+ end
29
81
  end
30
82
  end
31
83
  end
@@ -0,0 +1,102 @@
1
+ require 'helper'
2
+ require 'turnip_formatter/renderer/html/index'
3
+ require 'turnip_formatter/resource/scenario/pass'
4
+ require 'turnip_formatter/resource/scenario/failure'
5
+ require 'turnip_formatter/resource/scenario/pending'
6
+
7
+ module TurnipFormatter::Renderer::Html
8
+ class TestIndex < Test::Unit::TestCase
9
+ include TurnipFormatter::TestHelper
10
+
11
+ def setup
12
+ @renderer = Index.new(index_params)
13
+ end
14
+
15
+ def test_style_links
16
+ assert_equal(String, @renderer.style_links.class)
17
+ end
18
+
19
+ def test_style_codes
20
+ assert_equal(String, @renderer.style_codes.class)
21
+ end
22
+
23
+ def test_script_links
24
+ assert_equal(String, @renderer.script_links.class)
25
+ end
26
+
27
+ def test_script_codes
28
+ assert_equal(String, @renderer.script_codes.class)
29
+ end
30
+
31
+ def test_title
32
+ mock(TurnipFormatter::Renderer::Html).project_name { 'Perfect Turnip' }
33
+ assert_equal('Perfect Turnip report', @renderer.title)
34
+ end
35
+
36
+ def test_scenarios_html
37
+ assert_equal(String, @renderer.scenarios_html.class)
38
+ end
39
+
40
+ def test_statistics_feature_html
41
+ assert_equal(String, @renderer.statistics_feature_html.class)
42
+ end
43
+
44
+ def test_statistics_tag_html
45
+ assert_equal(String, @renderer.statistics_tag_html.class)
46
+ end
47
+
48
+ def test_statistics_speed_html
49
+ assert_equal(String, @renderer.statistics_speed_html.class)
50
+ end
51
+
52
+ def test_result_status
53
+ assert_equal('3 Scenario (1 failed 1 pending)', @renderer.result_status)
54
+ end
55
+
56
+ def test_total_time
57
+ assert_equal("20.0", @renderer.total_time)
58
+ end
59
+
60
+ def test_turnip_version
61
+ assert_equal(Turnip::VERSION, @renderer.turnip_version)
62
+ end
63
+
64
+ private
65
+
66
+ def index_params
67
+ {
68
+ scenarios: scenarios,
69
+ failed_count: 1,
70
+ pending_count: 1,
71
+ total_time: 20.0
72
+ }
73
+ end
74
+
75
+ def scenarios
76
+ @@scenarios ||= (
77
+ ss = []
78
+
79
+ feature = feature_build(feature_text)
80
+ examples = run_feature(feature, '/path/to/test1.feature')
81
+ ss << TurnipFormatter::Resource::Scenario::Pass.new(examples[0])
82
+ ss << TurnipFormatter::Resource::Scenario::Failure.new(examples[1])
83
+ ss << TurnipFormatter::Resource::Scenario::Pending.new(examples[2])
84
+ ss
85
+ )
86
+ end
87
+
88
+ def feature_text
89
+ <<-EOS
90
+ Feature: Feature
91
+ Scenario: Pass Scenario
92
+ When A
93
+
94
+ Scenario: Failure Scenario
95
+ When [ERROR] B
96
+
97
+ Scenario: Pending Scenario
98
+ When [PENDING] C
99
+ EOS
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,40 @@
1
+ require 'helper'
2
+ require 'turnip_formatter/renderer/html/runtime_error'
3
+ require 'turnip_formatter/resource/scenario/pass'
4
+
5
+ module TurnipFormatter::Renderer::Html
6
+ class TestRuntimeError < Test::Unit::TestCase
7
+ include TurnipFormatter::TestHelper
8
+
9
+ def setup
10
+ @renderer = RuntimeError.new([exception, scenario])
11
+ end
12
+
13
+ def test_runtime_exception
14
+ assert_equal(exception, @renderer.runtime_exception)
15
+ end
16
+
17
+ def test_scenario
18
+ assert_equal(scenario, @renderer.scenario)
19
+ end
20
+
21
+ private
22
+
23
+ def exception
24
+ @@exception ||= Exception.new('TFERROR')
25
+ end
26
+
27
+ def scenario
28
+ @@scenario ||= (
29
+ feature = feature_build(<<-EOS)
30
+ Feature: F
31
+ Scenario: S
32
+ When I attack it
33
+ EOS
34
+
35
+ scenario_example = run_feature(feature, '/path/to/test.feature').first
36
+ TurnipFormatter::Resource::Scenario::Pass.new(scenario_example)
37
+ )
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,102 @@
1
+ require 'helper'
2
+ require 'turnip_formatter/renderer/html/statistics_feature'
3
+ require 'turnip_formatter/resource/scenario/pass'
4
+ require 'turnip_formatter/resource/scenario/failure'
5
+ require 'turnip_formatter/resource/scenario/pending'
6
+
7
+ module TurnipFormatter::Renderer::Html
8
+ class TestStatisticsFeature < Test::Unit::TestCase
9
+ include TurnipFormatter::TestHelper
10
+
11
+
12
+ def setup
13
+ @renderer = StatisticsFeature.new(scenarios)
14
+ end
15
+
16
+ def test_results
17
+ fa = @renderer.results[0]
18
+ assert_equal(['A', 2, 1, 1, 0, :failed], actual(fa))
19
+
20
+ fb = @renderer.results[1]
21
+ assert_equal(['B', 1, 0, 0, 1, :pending], actual(fb))
22
+
23
+ fc = @renderer.results[2]
24
+ assert_equal(['C', 2, 2, 0, 0, :passed], actual(fc))
25
+ end
26
+
27
+ private
28
+
29
+ def actual(f)
30
+ [f.name, f.scenario_count, f.passed_count, f.failed_count, f.pending_count, f.status]
31
+ end
32
+
33
+ #
34
+ # name | scenario | passed | failed | pending | result
35
+ # --------- | -------- | ------ | ------ | ------- | ------
36
+ # Feature A | 2 | 1 | 1 | 0 | failed
37
+ # Feature B | 1 | 0 | 0 | 1 | pending
38
+ # Feature C | 2 | 2 | 0 | 0 | passed
39
+ #
40
+ def scenarios
41
+ @@scenarios ||= (
42
+ ss = []
43
+
44
+ feature = feature_build(feature_a)
45
+ examples = run_feature(feature, '/path/to/test1.feature')
46
+ ss << TurnipFormatter::Resource::Scenario::Pass.new(examples[0])
47
+ ss << TurnipFormatter::Resource::Scenario::Failure.new(examples[1])
48
+
49
+ feature = feature_build(feature_b)
50
+ examples = run_feature(feature, '/path/to/test2.feature')
51
+ ss << TurnipFormatter::Resource::Scenario::Pending.new(examples[0])
52
+
53
+ feature = feature_build(feature_c)
54
+ examples = run_feature(feature, '/path/to/test3.feature')
55
+ ss << TurnipFormatter::Resource::Scenario::Pass.new(examples[0])
56
+ ss << TurnipFormatter::Resource::Scenario::Pass.new(examples[1])
57
+
58
+ ss
59
+ )
60
+ end
61
+
62
+ def feature_a
63
+ <<-EOS
64
+ Feature: A
65
+ Scenario: Pass Scenario
66
+ When A
67
+ Then B
68
+ And C
69
+
70
+ Scenario: Failure Scenario
71
+ When A
72
+ Then [ERROR] B
73
+ And C
74
+ EOS
75
+ end
76
+
77
+ def feature_b
78
+ <<-EOS
79
+ Feature: B
80
+ Scenario: Pending Scenario
81
+ When A
82
+ Then [PENDING] B
83
+ And C
84
+ EOS
85
+ end
86
+
87
+ def feature_c
88
+ <<-EOS
89
+ Feature: C
90
+ Scenario: Pass Scenario 1
91
+ When A
92
+ Then B
93
+ And C
94
+
95
+ Scenario: Pass Scenario 2
96
+ When A
97
+ Then B
98
+ And C
99
+ EOS
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,77 @@
1
+ require 'helper'
2
+ require 'test/unit/rr'
3
+ require 'turnip_formatter/renderer/html/statistics_speed'
4
+ require 'turnip_formatter/resource/scenario/pass'
5
+ require 'turnip_formatter/resource/scenario/failure'
6
+ require 'turnip_formatter/resource/scenario/pending'
7
+
8
+ module TurnipFormatter::Renderer::Html
9
+ class TestStatisticsSpeed < Test::Unit::TestCase
10
+ include TurnipFormatter::TestHelper
11
+
12
+ def setup
13
+ @renderer = StatisticsSpeed.new(scenarios)
14
+ end
15
+
16
+ def test_results
17
+ results = @renderer.results
18
+
19
+ assert_equal(3, results.size)
20
+ assert_equal(['B', 3.0], [results[0].name, results[0].run_time])
21
+ assert_equal(['E', 4.0], [results[1].name, results[1].run_time])
22
+ assert_equal(['A', 10.0], [results[2].name, results[2].run_time])
23
+ end
24
+
25
+ private
26
+
27
+ #
28
+ # name | duration | in ranking
29
+ # ---- | -------- | ----------
30
+ # C | 1.0 | false (failed)
31
+ # B | 3.0 | true
32
+ # E | 4.0 | true
33
+ # D | 5.0 | false (pending)
34
+ # A | 10.0 | true
35
+ #
36
+ def scenarios
37
+ @@scenarios ||= (
38
+ examples = run_feature(feature_build(feature), '/path/to/test.feature')
39
+
40
+ s1 = TurnipFormatter::Resource::Scenario::Pass.new(examples[0])
41
+ s2 = TurnipFormatter::Resource::Scenario::Pass.new(examples[1])
42
+ s3 = TurnipFormatter::Resource::Scenario::Failure.new(examples[2])
43
+ s4 = TurnipFormatter::Resource::Scenario::Pending.new(examples[3])
44
+ s5 = TurnipFormatter::Resource::Scenario::Pass.new(examples[4])
45
+
46
+ stub(s1).run_time { 10.0 }
47
+ stub(s2).run_time { 3.0 }
48
+ stub(s3).run_time { 1.0 }
49
+ stub(s4).run_time { 5.0 }
50
+ stub(s5).run_time { 4.0 }
51
+
52
+ [s1, s2, s3, s4, s5]
53
+ )
54
+ end
55
+
56
+ def feature
57
+ <<-EOS
58
+ Feature: A
59
+
60
+ Scenario: A
61
+ When A
62
+
63
+ Scenario: B
64
+ When B
65
+
66
+ Scenario: C
67
+ When [ERROR] C
68
+
69
+ Scenario: D
70
+ When [PENDING] D
71
+
72
+ Scenario: E
73
+ When E
74
+ EOS
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,112 @@
1
+ require 'helper'
2
+ require 'turnip_formatter/renderer/html/statistics_tag'
3
+ require 'turnip_formatter/resource/scenario/pass'
4
+ require 'turnip_formatter/resource/scenario/failure'
5
+ require 'turnip_formatter/resource/scenario/pending'
6
+
7
+ module TurnipFormatter::Renderer::Html
8
+ class TestStatisticsTag < Test::Unit::TestCase
9
+ include TurnipFormatter::TestHelper
10
+
11
+ def setup
12
+ @renderer = StatisticsTag.new(scenarios)
13
+ end
14
+
15
+ def test_results
16
+ ta = @renderer.results[0]
17
+ assert_equal(['@bar', 2, 1, 1, 0, :failed], actual(ta))
18
+
19
+ tb = @renderer.results[1]
20
+ assert_equal(['@baz', 2, 1, 0, 1, :pending], actual(tb))
21
+
22
+ tc = @renderer.results[2]
23
+ assert_equal(['@foo', 2, 2, 0, 0, :passed], actual(tc))
24
+
25
+ td = @renderer.results[3]
26
+ assert_equal(['no_tag', 1, 1, 0, 0, :passed], actual(td))
27
+ end
28
+
29
+ private
30
+
31
+ def actual(f)
32
+ [f.name, f.scenario_count, f.passed_count, f.failed_count, f.pending_count, f.status]
33
+ end
34
+
35
+ #
36
+ # name | scenario | passed | failed | pending | result
37
+ # ------ | -------- | ------ | ------ | ------- | -------
38
+ # @bar | 2 | 1 | 1 | 0 | failed
39
+ # @baz | 2 | 1 | 0 | 1 | pending
40
+ # @foo | 2 | 2 | 0 | 0 | passed
41
+ # no_tag | 1 | 1 | 0 | 0 | passed
42
+ #
43
+ def scenarios
44
+ @@scenarios ||= (
45
+ ss = []
46
+
47
+ feature = feature_build(feature_a)
48
+ examples = run_feature(feature, '/path/to/test1.feature')
49
+ ss << TurnipFormatter::Resource::Scenario::Pass.new(examples[0])
50
+ ss << TurnipFormatter::Resource::Scenario::Failure.new(examples[1])
51
+
52
+ feature = feature_build(feature_b)
53
+ examples = run_feature(feature, '/path/to/test2.feature')
54
+ ss << TurnipFormatter::Resource::Scenario::Pending.new(examples[0])
55
+
56
+ feature = feature_build(feature_c)
57
+ examples = run_feature(feature, '/path/to/test3.feature')
58
+ ss << TurnipFormatter::Resource::Scenario::Pass.new(examples[0])
59
+ ss << TurnipFormatter::Resource::Scenario::Pass.new(examples[1])
60
+
61
+ ss
62
+ )
63
+ end
64
+
65
+ def feature_a
66
+ <<-EOS
67
+ Feature: A
68
+
69
+ Scenario: Pass Scenario
70
+ When A
71
+ Then B
72
+ And C
73
+
74
+ @bar
75
+ Scenario: Failure Scenario
76
+ When A
77
+ Then [ERROR] B
78
+ And C
79
+ EOS
80
+ end
81
+
82
+ def feature_b
83
+ <<-EOS
84
+ @baz
85
+ Feature: B
86
+ Scenario: Pending Scenario
87
+ When A
88
+ Then [PENDING] B
89
+ And C
90
+ EOS
91
+ end
92
+
93
+ def feature_c
94
+ <<-EOS
95
+ @foo
96
+ Feature: C
97
+
98
+ @bar
99
+ Scenario: Pass Scenario 1
100
+ When A
101
+ Then B
102
+ And C
103
+
104
+ @baz
105
+ Scenario: Pass Scenario 2
106
+ When A
107
+ Then B
108
+ And C
109
+ EOS
110
+ end
111
+ end
112
+ end