turnip_formatter 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. data/lib/rspec/core/formatters/turnip_formatter.rb +7 -34
  2. data/lib/turnip_formatter/ext/turnip/rspec.rb +2 -0
  3. data/lib/turnip_formatter/printer/index.rb +29 -0
  4. data/lib/turnip_formatter/printer/runtime_error.rb +41 -0
  5. data/lib/turnip_formatter/printer/scenario.rb +20 -0
  6. data/lib/turnip_formatter/printer/step.rb +34 -0
  7. data/lib/turnip_formatter/printer/step_extra_args.rb +21 -0
  8. data/lib/turnip_formatter/printer/tab_feature_statistics.rb +47 -0
  9. data/lib/turnip_formatter/printer/tab_speed_statistics.rb +34 -0
  10. data/lib/turnip_formatter/printer/tab_tag_statistics.rb +72 -0
  11. data/lib/turnip_formatter/printer.rb +34 -0
  12. data/lib/turnip_formatter/template/exception.erb +9 -25
  13. data/lib/turnip_formatter/template/index.erb +65 -0
  14. data/lib/turnip_formatter/template/runtime_exception.erb +16 -0
  15. data/lib/turnip_formatter/template/scenario.erb +9 -8
  16. data/lib/turnip_formatter/template/step.erb +4 -0
  17. data/lib/turnip_formatter/template/tab_feature_statistics.erb +24 -0
  18. data/lib/turnip_formatter/template/tab_speed_statistics.erb +18 -0
  19. data/lib/turnip_formatter/template/tab_tag_statistics.erb +24 -0
  20. data/lib/turnip_formatter/template/turnip_formatter.js +51 -0
  21. data/lib/turnip_formatter/{formatter.scss → template/turnip_formatter.scss} +0 -0
  22. data/lib/turnip_formatter/template.rb +21 -254
  23. data/lib/turnip_formatter/version.rb +1 -1
  24. data/lib/turnip_formatter.rb +1 -1
  25. data/spec/rspec/core/formatters/turnip_formatter_spec.rb +11 -28
  26. data/spec/turnip_formatter/printer/scenario_spec.rb +33 -0
  27. data/spec/turnip_formatter/printer/step_extra_args_spec.rb +32 -0
  28. data/spec/turnip_formatter/printer/step_spec.rb +86 -0
  29. data/spec/turnip_formatter/printer/tab_feature_statistics_spec.rb +83 -0
  30. data/spec/turnip_formatter/printer/tab_speed_statistics_spec.rb +51 -0
  31. data/spec/turnip_formatter/printer/tab_tag_statistics_spec.rb +90 -0
  32. data/spec/turnip_formatter/template_spec.rb +0 -173
  33. data/turnip_formatter.gemspec +2 -0
  34. metadata +63 -14
  35. data/lib/turnip_formatter/formatter.css +0 -205
  36. data/lib/turnip_formatter/template/scenario_tags.erb +0 -5
  37. data/lib/turnip_formatter/template/tab/feature_statistics.rb +0 -78
  38. data/lib/turnip_formatter/template/tab/speed_statistics.rb +0 -61
  39. data/lib/turnip_formatter/template/tab/tag_statistics.rb +0 -101
  40. data/spec/turnip_formatter/template/tab/feature_statistics_spec.rb +0 -87
  41. data/spec/turnip_formatter/template/tab/speed_statistics_spec.rb +0 -56
  42. data/spec/turnip_formatter/template/tab/tag_statistics_spec.rb +0 -88
@@ -1,78 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- require 'turnip_formatter/template'
4
-
5
- module TurnipFormatter
6
- class Template
7
- module Tab
8
- class FeatureStatistics
9
- attr_reader :features
10
-
11
- #
12
- # @param [Array] passed_examples Array of TurnipFormatter::Scenario
13
- #
14
- def initialize(scenarios)
15
- @features = scenarios.group_by { |s| s.feature_name }
16
- end
17
-
18
- def build
19
- html = <<-EOS
20
- <table>
21
- <thead>
22
- <tr>
23
- <th>Feature</th>
24
- <th>Scearios</th>
25
- <th>passed</th>
26
- <th>failed</th>
27
- <th>pending</th>
28
- <th>status</th>
29
- </tr>
30
- </thead>
31
- <tbody>
32
- EOS
33
-
34
- html += @features.map do |feature_name, scenarios|
35
- info = feature_analysis(feature_name, scenarios)
36
- build_tr(info)
37
- end.join
38
-
39
- html += '</tbody></table>'
40
- end
41
-
42
- private
43
-
44
- def feature_analysis(name, scenarios)
45
- status_group = scenarios.group_by { |s| s.status }
46
-
47
- info = {
48
- name: name,
49
- scenarios: scenarios.count,
50
- passed: status_count(status_group["passed"]),
51
- failed: status_count(status_group["failed"]),
52
- pending: status_count(status_group["pending"])
53
- }
54
- info[:status] = info[:failed].zero? ? (info[:pending].zero? ? 'passed' : 'pending') : 'failed'
55
-
56
- info
57
- end
58
-
59
- def status_count(scenarios)
60
- scenarios.nil? ? 0 : scenarios.count
61
- end
62
-
63
- def build_tr(info)
64
- <<-EOS
65
- <tr>
66
- <td>#{info[:name]}</td>
67
- <td>#{info[:scenarios]}</td>
68
- <td>#{info[:passed]}</td>
69
- <td>#{info[:failed]}</td>
70
- <td>#{info[:pending]}</td>
71
- <td class="#{info[:status]}">#{info[:status]}</td>
72
- </tr>
73
- EOS
74
- end
75
- end
76
- end
77
- end
78
- end
@@ -1,61 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- require 'turnip_formatter/template'
4
- require 'ostruct'
5
-
6
- module TurnipFormatter
7
- class Template
8
- module Tab
9
- class SpeedStatistics
10
- attr_reader :scenarios
11
-
12
- #
13
- # @param [Array] passed_examples Array of TurnipFormatter::Scenario::Pass
14
- #
15
- def initialize(passed_scenarios)
16
- @scenarios = passed_scenarios.map do |s|
17
- OpenStruct.new(
18
- {
19
- id: s.id,
20
- feature_name: s.feature_name,
21
- name: s.name,
22
- run_time: s.run_time
23
- }
24
- )
25
- end.sort { |a, b| a.run_time <=> b.run_time }
26
- end
27
-
28
- def build
29
- html = <<-EOS
30
- <table>
31
- <thead>
32
- <tr>
33
- <th>Feature</th>
34
- <th>Scenario</th>
35
- <th>Duration</th>
36
- </tr>
37
- </thead>
38
- <tbody>
39
- EOS
40
-
41
- html += scenarios.map do |scenario|
42
- <<-EOS
43
- <tr>
44
- <td><span>#{scenario.feature_name}</span></td>
45
- <td><a href=\"\##{scenario.id}\">#{scenario.name}</a></td>
46
- <td><span>#{scenario.run_time}</span> sec</td>
47
- </tr>
48
- EOS
49
- end.join
50
-
51
- html += <<-EOS
52
- </tbody>
53
- </table>
54
- EOS
55
-
56
- html
57
- end
58
- end
59
- end
60
- end
61
- end
@@ -1,101 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- require 'turnip_formatter/template'
4
-
5
- module TurnipFormatter
6
- class Template
7
- module Tab
8
- class TagStatistics
9
- attr_reader :scenarios
10
-
11
- #
12
- # @param [Array] passed_examples Array of TurnipFormatter::Scenario
13
- #
14
- def initialize(scenarios)
15
- @scenarios = scenarios
16
- end
17
-
18
- def build
19
- html = <<-EOS
20
- <table>
21
- <thead>
22
- <tr>
23
- <th>Tag</th>
24
- <th>Scearios</th>
25
- <th>passed</th>
26
- <th>failed</th>
27
- <th>pending</th>
28
- <th>status</th>
29
- </tr>
30
- </thead>
31
- <tbody>
32
- EOS
33
-
34
- html += tag_analysis.map { |info| build_tr(info) }.join
35
- html += '</tbody></table>'
36
- end
37
-
38
- private
39
-
40
- def tag_analysis
41
- group_by_tag.map do |tag, scenarios|
42
- status_group = scenarios.group_by { |s| s[:scenario].status }
43
- info = OpenStruct.new(
44
- name: tag,
45
- scenarios: scenarios.count,
46
- passed: status_count(status_group["passed"]),
47
- failed: status_count(status_group["failed"]),
48
- pending: status_count(status_group["pending"]),
49
- status: 'failed'
50
- )
51
- info.status = (info.pending.zero? ? 'passed' : 'pending') if info.failed.zero?
52
- info
53
- end
54
- end
55
-
56
- #
57
- # Image...
58
- #
59
- # [
60
- # { tags: [:a, :b], val: 3 },
61
- # { tags: [:a], val: 4 },
62
- # { tags: [:b], val: 5 },
63
- # ]
64
- # # => [
65
- # a: [3, 4],
66
- # b: [3, 5]
67
- # ]
68
- #
69
- #
70
- def group_by_tag
71
- scenarios.map do |scenario|
72
- if scenario.tags.empty?
73
- { name: 'turnip', scenario: scenario }
74
- else
75
- scenario.tags.map do |tag|
76
- { name: '@' + tag, scenario: scenario }
77
- end
78
- end
79
- end.flatten.group_by { |s| s[:name] }.sort
80
- end
81
-
82
- def status_count(scenarios)
83
- scenarios.nil? ? 0 : scenarios.count
84
- end
85
-
86
- def build_tr(info)
87
- <<-EOS
88
- <tr>
89
- <td>#{info.name}</td>
90
- <td>#{info.scenarios}</td>
91
- <td>#{info.passed}</td>
92
- <td>#{info.failed}</td>
93
- <td>#{info.pending}</td>
94
- <td class="#{info.status}">#{info.status}</td>
95
- </tr>
96
- EOS
97
- end
98
- end
99
- end
100
- end
101
- end
@@ -1,87 +0,0 @@
1
- require 'spec_helper'
2
- require 'turnip_formatter/template/tab/feature_statistics'
3
-
4
- module TurnipFormatter
5
- class Template
6
- module Tab
7
- describe FeatureStatistics do
8
- include_context 'turnip_formatter scenario setup'
9
- include_context 'turnip_formatter standard scenario metadata'
10
-
11
- let :base_scenario do
12
- TurnipFormatter::Scenario::Pass.new(example)
13
- end
14
-
15
- let :statistics do
16
- FeatureStatistics.new(scenarios)
17
- end
18
-
19
- context 'feature only passed scenario' do
20
- let :scenarios do
21
- # Feature: Hago (passed:2 failed:0, pending:0)
22
- ['passed', 'passed'].map do |status|
23
- scenario = base_scenario.dup
24
- scenario.stub(:status).and_return(status)
25
- scenario
26
- end
27
- end
28
-
29
- describe '#feature_analysis' do
30
- it 'should get passed feature information' do
31
- info = statistics.send(:feature_analysis, 'Hoge', scenarios)
32
- expect(info[:name]).to eq 'Hoge'
33
- expect(info[:passed]).to eq 2
34
- expect(info[:failed]).to be_zero
35
- expect(info[:pending]).to be_zero
36
- expect(info[:status]).to eq 'passed'
37
- end
38
- end
39
- end
40
-
41
- context 'feature with failed scenario' do
42
- let :scenarios do
43
- # Feature: Hoge (passed:1 failed:2, pending:0)
44
- ['passed', 'failed', 'failed'].map do |status|
45
- scenario = base_scenario.dup
46
- scenario.stub(:status).and_return(status)
47
- scenario
48
- end
49
- end
50
-
51
- describe '#feature_analysis' do
52
- it 'should get failed feature information' do
53
- info = statistics.send(:feature_analysis, 'Fuga', scenarios)
54
- expect(info[:name]).to eq 'Fuga'
55
- expect(info[:passed]).to eq 1
56
- expect(info[:failed]).to eq 2
57
- expect(info[:pending]).to be_zero
58
- expect(info[:status]).to eq 'failed'
59
- end
60
- end
61
- end
62
-
63
- context 'feature with pending scenario' do
64
- let :scenarios do
65
- # Feature: Fuga (passed:1 failed:0, pending:1)
66
- ['passed', 'pending'].map do |status|
67
- scenario = base_scenario.dup
68
- scenario.stub(:status).and_return(status)
69
- scenario
70
- end
71
- end
72
-
73
- describe '#feature_analysis' do
74
- it 'should get pending feature information' do
75
- info = statistics.send(:feature_analysis, 'Hago', scenarios)
76
- expect(info[:name]).to eq 'Hago'
77
- expect(info[:passed]).to eq 1
78
- expect(info[:failed]).to be_zero
79
- expect(info[:pending]).to eq 1
80
- expect(info[:status]).to eq 'pending'
81
- end
82
- end
83
- end
84
- end
85
- end
86
- end
87
- end
@@ -1,56 +0,0 @@
1
- require 'spec_helper'
2
- require 'turnip_formatter/template/tab/speed_statistics'
3
-
4
- module TurnipFormatter
5
- class Template
6
- module Tab
7
- describe SpeedStatistics do
8
- include_context 'turnip_formatter scenario setup'
9
- include_context 'turnip_formatter standard scenario metadata'
10
-
11
- let :passed_scenarios do
12
- ([example] * 3).map do |ex|
13
- TurnipFormatter::Scenario::Pass.new(ex)
14
- end.each { |s| s.stub(:run_time).and_return(rand) }
15
- end
16
-
17
- let :statistics do
18
- SpeedStatistics.new(passed_scenarios)
19
- end
20
-
21
- describe '#build' do
22
- it 'should get string as HTML table' do
23
- scenarios = statistics.scenarios
24
- html = statistics.build
25
-
26
- scenarios.each do |scenario|
27
- tag_scenario_name = "<a href=\"\##{scenario.id}\">#{scenario.name}</a>"
28
- tag_run_time = "<span>#{scenario.run_time}</span>"
29
- tag_feature_name = "<span>#{scenario.feature_name}</span>"
30
-
31
- expect_match = [
32
- '<tr>',
33
- "<td>#{tag_feature_name}</td>",
34
- "<td>#{tag_scenario_name}</td>",
35
- "<td>#{tag_run_time} sec</td>",
36
- '</tr>'
37
- ].join('[[:space:]]+')
38
-
39
- expect(html).to match %r(#{expect_match})
40
- end
41
- end
42
- end
43
-
44
- describe '#scenarios' do
45
- it 'should get array of scenario' do
46
- scenarios = statistics.scenarios
47
- expect(scenarios).to have(3).elements
48
-
49
- run_time_list = scenarios.map(&:run_time)
50
- expect(run_time_list.sort).to eq run_time_list
51
- end
52
- end
53
- end
54
- end
55
- end
56
- end
@@ -1,88 +0,0 @@
1
- require 'spec_helper'
2
- require 'turnip_formatter/template/tab/tag_statistics'
3
-
4
- module TurnipFormatter
5
- class Template
6
- module Tab
7
- describe TagStatistics do
8
- include_context 'turnip_formatter scenario setup'
9
- include_context 'turnip_formatter standard scenario metadata'
10
-
11
- let :base_scenario do
12
- TurnipFormatter::Scenario::Pass.new(example)
13
- end
14
-
15
- let :scenarios do
16
- scenarios = []
17
-
18
- # | tag | scenarios | passed | failed | pending | status |
19
- # |-------+-----------+--------+--------+---------+---------|
20
- # | none | 1 | 1 | 0 | 0 | status |
21
- # | @bar | 2 | 0 | 1 | 1 | failed |
22
- # | @foo | 1 | 0 | 1 | 0 | failed |
23
- # | @hoge | 1 | 1 | 0 | 1 | pending |
24
-
25
- # Failed scenario have tags @hoge and @fuga
26
- scenario = base_scenario.dup
27
- scenario.stub(:tags).and_return(['foo', 'bar'])
28
- scenario.stub(:status).and_return('failed')
29
- scenarios << scenario
30
-
31
- # Passed scenario no have tags
32
- scenario = base_scenario.dup
33
- scenario.stub(:tags).and_return([])
34
- scenario.stub(:status).and_return('passed')
35
- scenarios << scenario
36
-
37
- # Passed scenario have tags @hoge
38
- scenario = base_scenario.dup
39
- scenario.stub(:tags).and_return(['hoge'])
40
- scenario.stub(:status).and_return('passed')
41
- scenarios << scenario
42
-
43
- # Pending scenario have tags @fuga and @hago
44
- scenario = base_scenario.dup
45
- scenario.stub(:tags).and_return(['bar', 'hoge'])
46
- scenario.stub(:status).and_return('pending')
47
- scenarios << scenario
48
- end
49
-
50
- let :statistics do
51
- TagStatistics.new(scenarios)
52
- end
53
-
54
- describe '#tag_analysis' do
55
- let :results do
56
- statistics.send(:tag_analysis)
57
- end
58
-
59
- it 'should get results sort by tag name' do
60
- expect(results.map(&:name)).to eq ['@bar', '@foo', '@hoge', 'turnip']
61
- end
62
-
63
- it 'should get count of each status' do
64
- # @bar
65
- res = results[0]
66
- expect([res.passed, res.failed, res.pending]).to eq [0, 1, 1]
67
- expect(res.status).to eq 'failed'
68
-
69
- # @foo
70
- res = results[1]
71
- expect([res.passed, res.failed, res.pending]).to eq [0, 1, 0]
72
- expect(res.status).to eq 'failed'
73
-
74
- # @hoge
75
- res = results[2]
76
- expect([res.passed, res.failed, res.pending]).to eq [1, 0, 1]
77
- expect(res.status).to eq 'pending'
78
-
79
- # no tags (turnip)
80
- res = results[3]
81
- expect([res.passed, res.failed, res.pending]).to eq [1, 0, 0]
82
- expect(res.status).to eq 'passed'
83
- end
84
- end
85
- end
86
- end
87
- end
88
- end