turnip_formatter 0.6.0.pre.beta.6 → 0.6.0.pre.beta.7

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 726f004501517755e0b9d76679bd329a6db43265
4
- data.tar.gz: 0b024a138f3bcb88e0ca4fcc8e63d86d55b71935
3
+ metadata.gz: 03749d6d53a310780fc1e2595f537e7b35a9e73a
4
+ data.tar.gz: 1739d0a736c12f0e10b46c35192f2e0a321d1e7a
5
5
  SHA512:
6
- metadata.gz: 62233a172b7fe3e78a7d7bb4c8c07ecc0773d744335c88debdfa2e8eff859e9a9b866184d7b783cbd46c537b23d6bee2cdd89949ac3d05d3de03f20eebe50364
7
- data.tar.gz: bd5f739958168d28d624c6c40304f0115a3971ddf9feede29b230daa5300398ec1fb4e9fa173a9178c8b1b33888557018ff0a1c7b0e26e6e86756256b3f4e7ee
6
+ metadata.gz: a4b88812e427868f23695be4f9285afccf0970790521056e7f390669186a9e721ee94f033f9a5f51c9ca7ca7bdf85cb1e782c2d948c39c1a10ca6a6a72ab9a83
7
+ data.tar.gz: d9e4560bf2e3030a53842fa430a6e944714696a65e6ff8f0bfa1679a8e2f09a1aafcb00ef4811083b04dfb1e0892ce08a5af841f55829ed48cf933e4f2e062c0
data/.travis.yml CHANGED
@@ -17,7 +17,7 @@ rvm:
17
17
  - 2.2
18
18
  - 2.3.0
19
19
  - ruby-head
20
- - jruby-9.0.0.0
20
+ - jruby-9.0.5.0
21
21
 
22
22
  script:
23
23
  - bundle exec rake test
@@ -15,6 +15,20 @@ Feature: Battle a monster
15
15
  Then it should die
16
16
  And Fanfare
17
17
 
18
+ @aggregate_failures
19
+ Scenario: [ERROR] boss monster (aggregate_failures)
20
+
21
+ Even if error occurs during steps, test will run to the end
22
+
23
+ Given there is a boss monster
24
+ When I attack it
25
+ Then it should die
26
+ When I attack it
27
+ Then it should die
28
+ When I attack it
29
+ Then it should die
30
+ And Fanfare
31
+
18
32
  Scenario: [PENDING] spell magic
19
33
 
20
34
  This scenario will not success because he can't cast spell
@@ -8,7 +8,17 @@ Dir.glob(File.dirname(__FILE__) + '/steps/**/*steps.rb') { |f| load f, true }
8
8
 
9
9
  RSpec.configure do |config|
10
10
  config.before(:example, before_hook_error: true) do
11
- undefined_method # NameError
11
+ #
12
+ # Workaround for JRuby <= 9.1.7.0
13
+ #
14
+ # https://github.com/jruby/jruby/issues/4467
15
+ # https://github.com/rspec/rspec-core/pull/2381
16
+ #
17
+ begin
18
+ undefined_method # NameError
19
+ rescue => e
20
+ raise e
21
+ end
12
22
  end
13
23
 
14
24
  config.after(:example, after_hook_error: true) do
@@ -28,7 +28,7 @@ module TurnipFormatter
28
28
 
29
29
  def extra_information
30
30
  extra_information_templates.map do |template, method|
31
- template.send(method, @resource.example)
31
+ template.send(method, @resource)
32
32
  end.join("\n")
33
33
  end
34
34
 
@@ -1,5 +1,6 @@
1
1
  require 'forwardable'
2
- require 'turnip_formatter/resource/step'
2
+ require 'turnip_formatter/resource/step/pass'
3
+ require 'turnip_formatter/resource/step/unexecute'
3
4
 
4
5
  module TurnipFormatter
5
6
  module Resource
@@ -17,12 +18,6 @@ module TurnipFormatter
17
18
  @example = example
18
19
  end
19
20
 
20
- def steps
21
- @steps ||= (backgrounds.map(&:steps).flatten + raw.steps).map do |step|
22
- TurnipFormatter::Resource::Step.new(example, step)
23
- end
24
- end
25
-
26
21
  def id
27
22
  'scenario_' + object_id.to_s
28
23
  end
@@ -58,6 +53,10 @@ module TurnipFormatter
58
53
  example.metadata[:turnip_formatter][:feature]
59
54
  end
60
55
 
56
+ def raw_steps
57
+ backgrounds.map(&:steps).flatten + raw.steps
58
+ end
59
+
61
60
  private
62
61
 
63
62
  def raw
@@ -1,12 +1,12 @@
1
1
  require 'turnip_formatter/resource/scenario/base'
2
- require 'turnip_formatter/resource/hook'
2
+ require 'turnip_formatter/resource/step/failure'
3
+ require 'turnip_formatter/resource/step/hook'
4
+ require 'rspec/core/formatters/exception_presenter'
3
5
 
4
6
  module TurnipFormatter
5
7
  module Resource
6
8
  module Scenario
7
9
  class Failure < Base
8
- alias :super_steps :steps
9
-
10
10
  #
11
11
  # Return steps
12
12
  #
@@ -17,99 +17,127 @@ module TurnipFormatter
17
17
  # And baz <= failed line
18
18
  # Then piyo
19
19
  #
20
- # #<Step 'foo'>.status = :passed
21
- # #<Step 'bar'>.status = :passed
22
- # #<Step 'baz'>.status = :failed
23
- # #<Step 'piyo'>.status = :unexecute
24
- #
25
- # @TODO Correspond to multiple errors.
26
- #
27
- # example:
28
- #
29
- # # foo.feature
30
- # @after_hook
31
- # When foo
32
- # And bar <= failed line
33
- # Then baz
34
- #
35
- # # spec_helper.rb
36
- # RSpec.configure do |config|
37
- # config.after(:example, after_hook: true) do
38
- # raise RuntimeError
39
- # end
40
- # end
41
- #
42
- # Currently, display only first error (`And bar`).
20
+ # # => [
21
+ # # <Step::Pass 'foo'>
22
+ # # <Step::Pass 'bar'>
23
+ # # <Step::Failure 'baz'>
24
+ # # <Step::Unexecute 'piyo'>
25
+ # # ]
43
26
  #
44
27
  def steps
45
- case
46
- when error_in_steps?
47
- steps_with_error
48
- when error_in_before_hook?
49
- steps_with_error_in_before_hook
50
- when error_in_after_hook?
51
- steps_with_error_in_after_hook
28
+ exceptions = all_exception_group_by_line_number
29
+
30
+ if exceptions.has_key?(:before)
31
+ return steps_with_error_in_before_hook(exceptions[:before])
32
+ end
33
+
34
+ steps = steps_with_error(exceptions)
35
+
36
+ if exceptions.has_key?(:after)
37
+ return steps_with_error_in_after_hook(steps, exceptions[:after])
52
38
  end
39
+
40
+ steps
53
41
  end
54
42
 
55
43
  private
56
44
 
57
- def steps_with_error
58
- steps = super_steps
45
+ def steps_with_error(exceptions)
46
+ step_klass = TurnipFormatter::Resource::Step::Pass
59
47
 
60
- arys = steps.group_by { |s| (s.line <=> failed_line_number).to_s }
61
- arys['-1'].each { |s| s.status = :passed } unless arys['-1'].nil?
62
- arys['0'].each { |s| s.status = :failed } unless arys['0'].nil?
63
- arys['1'].each { |s| s.status = :unexecute } unless arys['1'].nil?
48
+ raw_steps.map do |rs|
49
+ ex = exceptions[rs.line]
50
+ next step_klass.new(example, rs) unless ex
64
51
 
65
- steps
52
+ # The status of step after error step is determined by `aggregate_failures` option
53
+ if example.metadata[:aggregate_failures]
54
+ step_klass = TurnipFormatter::Resource::Step::Pass
55
+ else
56
+ step_klass = TurnipFormatter::Resource::Step::Unexecute
57
+ end
58
+
59
+ TurnipFormatter::Resource::Step::Failure.new(example, rs).tap do |step|
60
+ step.set_exceptions(ex)
61
+ end
62
+ end
66
63
  end
67
64
 
68
- def steps_with_error_in_before_hook
69
- steps = super_steps
65
+ def steps_with_error_in_before_hook(exceptions)
66
+ before_step = TurnipFormatter::Resource::Step::BeforeHook.new(example)
67
+ before_step.set_exceptions(exceptions)
68
+
69
+ after_steps = raw_steps.map do |rs|
70
+ TurnipFormatter::Resource::Step::Unexecute.new(example, rs)
71
+ end
70
72
 
71
- steps.each { |s| s.status = :unexecute }
72
- [TurnipFormatter::Resource::Hook.new(example, 'BeforeHook', :failed)] + steps
73
+ [before_step] + after_steps
73
74
  end
74
75
 
75
- def steps_with_error_in_after_hook
76
- super_steps + [TurnipFormatter::Resource::Hook.new(example, 'AfterHook', :failed)]
76
+ def steps_with_error_in_after_hook(steps, exceptions)
77
+ after_step = TurnipFormatter::Resource::Step::AfterHook.new(example)
78
+ after_step.set_exceptions(exceptions)
79
+
80
+ steps + [after_step]
77
81
  end
78
82
 
79
- def error_in_steps?
80
- !failed_line_number.nil?
83
+ def error_in_before_hook?(exceptions)
84
+ exceptions.has_key?(:before)
81
85
  end
82
86
 
83
- def error_in_before_hook?
84
- exception.backtrace.any? do |backtrace|
85
- backtrace.match(/run_before_example/)
87
+ def error_in_after_hook?(exceptions)
88
+ exceptions.has_key?(:after)
89
+ end
90
+
91
+ def all_exception_group_by_line_number
92
+ all_exception(example.exception).group_by do |e|
93
+ line = failed_line_number(e)
94
+ next line unless line.nil?
95
+
96
+ case
97
+ when occurred_in_before_hook?(e)
98
+ :before
99
+ when occurred_in_after_hook?(e)
100
+ :after
101
+ end
86
102
  end
87
103
  end
88
104
 
89
- def error_in_after_hook?
90
- exception.backtrace.any? do |backtrace|
91
- backtrace.match(/run_after_example/)
105
+ def all_exception(exception)
106
+ unless exception.class.include?(RSpec::Core::MultipleExceptionError::InterfaceTag)
107
+ return [exception]
108
+ end
109
+
110
+ exception.all_exceptions.flat_map do |e|
111
+ all_exception(e)
92
112
  end
93
113
  end
94
114
 
95
- def failed_line_number
96
- @failed_line_number ||= (
97
- filepath = File.basename(feature_file_path)
98
- line = exception.backtrace.find do |backtrace|
99
- backtrace.match(/#{filepath}:(\d+)/)
100
- end
101
- Regexp.last_match[1].to_i if line
102
- )
115
+ def failed_line_number(exception)
116
+ filepath = File.basename(feature_file_path)
117
+ method = if RUBY_PLATFORM == 'java'
118
+ '<eval>'
119
+ else
120
+ 'run_step'
121
+ end
122
+ method = Regexp.escape(method)
123
+
124
+ line = exception.backtrace.find do |backtrace|
125
+ backtrace.match(/#{filepath}:(\d+):in `#{method}'/)
126
+ end
127
+
128
+ Regexp.last_match[1].to_i if line
103
129
  end
104
130
 
105
- def exception
106
- @exception ||= (
107
- if example.exception.is_a?(RSpec::Core::MultipleExceptionError)
108
- example.exception.all_exceptions.first
109
- else
110
- example.exception
111
- end
112
- )
131
+ def occurred_in_before_hook?(exception)
132
+ exception.backtrace.any? do |backtrace|
133
+ backtrace.match(/run_before_example/)
134
+ end
135
+ end
136
+
137
+ def occurred_in_after_hook?(exception)
138
+ exception.backtrace.any? do |backtrace|
139
+ backtrace.match(/run_after_example/)
140
+ end
113
141
  end
114
142
  end
115
143
  end
@@ -4,6 +4,11 @@ module TurnipFormatter
4
4
  module Resource
5
5
  module Scenario
6
6
  class Pass < Base
7
+ def steps
8
+ raw_steps.map do |rs|
9
+ TurnipFormatter::Resource::Step::Pass.new(example, rs)
10
+ end
11
+ end
7
12
  end
8
13
  end
9
14
  end
@@ -1,4 +1,5 @@
1
1
  require 'turnip_formatter/resource/scenario/base'
2
+ require 'turnip_formatter/resource/step/pending'
2
3
 
3
4
  module TurnipFormatter
4
5
  module Resource
@@ -14,21 +15,25 @@ module TurnipFormatter
14
15
  # And baz <= pending line
15
16
  # Then piyo
16
17
  #
17
- # #<Step 'foo'>.status = :passed
18
- # #<Step 'bar'>.status = :passed
19
- # #<Step 'baz'>.status = :pending
20
- # #<Step 'piyo'>.status = :unexecute
18
+ # # => [
19
+ # # <Step::Pass 'foo'>
20
+ # # <Step::Pass 'bar'>
21
+ # # <Step::Pending 'baz'>
22
+ # # <Step::Unexecute 'piyo'>
23
+ # # ]
21
24
  #
22
25
  def steps
23
- steps = super
26
+ raw_steps.map do |rs|
27
+ if rs.line < pending_line_number
28
+ klass = TurnipFormatter::Resource::Step::Pass
29
+ elsif rs.line == pending_line_number
30
+ klass = TurnipFormatter::Resource::Step::Pending
31
+ else
32
+ klass = TurnipFormatter::Resource::Step::Unexecute
33
+ end
24
34
 
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
35
+ klass.new(example, rs)
36
+ end
32
37
  end
33
38
 
34
39
  private
@@ -0,0 +1,24 @@
1
+ require 'forwardable'
2
+
3
+ module TurnipFormatter
4
+ module Resource
5
+ module Step
6
+ class Base
7
+ extend Forwardable
8
+ def_delegators :@raw, :keyword, :text, :line, :argument
9
+
10
+ attr_reader :example
11
+ attr_accessor :status
12
+
13
+ #
14
+ # @param [RSpec::Core::Example] example
15
+ # @param [Turnip::Node::Step] raw
16
+ #
17
+ def initialize(example, raw)
18
+ @example = example
19
+ @raw = raw
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,27 @@
1
+ require 'turnip_formatter/resource/step/base'
2
+
3
+ module TurnipFormatter
4
+ module Resource
5
+ module Step
6
+ class Failure < Base
7
+ attr_reader :exceptions
8
+
9
+ def initialize(example, raw)
10
+ super
11
+ @exceptions = []
12
+ end
13
+
14
+ def status
15
+ :failed
16
+ end
17
+
18
+ #
19
+ # @param [Array<Exception>] exceptions
20
+ #
21
+ def set_exceptions(exceptions)
22
+ @exceptions = exceptions
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,50 @@
1
+ module TurnipFormatter
2
+ module Resource
3
+ module Step
4
+ class HookBase
5
+ attr_reader :example
6
+ attr_reader :exceptions
7
+
8
+ #
9
+ # @param [RSpec::Core::Example] example
10
+ #
11
+ def initialize(example)
12
+ @example = example
13
+ @exceptions = []
14
+ end
15
+
16
+ def set_exceptions(exceptions)
17
+ @exceptions = exceptions
18
+ end
19
+
20
+ def status
21
+ :failed
22
+ end
23
+
24
+ def text
25
+ ''
26
+ end
27
+
28
+ def line
29
+ -1
30
+ end
31
+
32
+ def argument
33
+ nil
34
+ end
35
+ end
36
+
37
+ class BeforeHook < HookBase
38
+ def keyword
39
+ 'BeforeHook'
40
+ end
41
+ end
42
+
43
+ class AfterHook < HookBase
44
+ def keyword
45
+ 'AfterHook'
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,13 @@
1
+ require 'turnip_formatter/resource/step/base'
2
+
3
+ module TurnipFormatter
4
+ module Resource
5
+ module Step
6
+ class Pass < Base
7
+ def status
8
+ :passed
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,21 @@
1
+ require 'turnip_formatter/resource/step/base'
2
+
3
+ module TurnipFormatter
4
+ module Resource
5
+ module Step
6
+ class Pending < Base
7
+ def status
8
+ :pending
9
+ end
10
+
11
+ def pending_message
12
+ example.execution_result.pending_message
13
+ end
14
+
15
+ def pending_location
16
+ example.location
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,13 @@
1
+ require 'forwardable'
2
+
3
+ module TurnipFormatter
4
+ module Resource
5
+ module Step
6
+ class Unexecute < Base
7
+ def status
8
+ :unexecute
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -29,10 +29,6 @@ module TurnipFormatter
29
29
  ''
30
30
  end
31
31
  end
32
-
33
- def formatted_backtrace(example, exception = nil)
34
- RSpec::Core::Formatters::TurnipFormatter.formatted_backtrace(example, exception)
35
- end
36
32
  end
37
33
  end
38
34
  end
@@ -0,0 +1,21 @@
1
+ <% exceptions.each do |e| %>
2
+ <div class="step_exception">
3
+ <dl>
4
+ <dt>Failure:</dt>
5
+ <dd>
6
+ <pre><%= ERB::Util.h(e[:message]) %></pre>
7
+ </dd>
8
+ <dt>Backtrace:</dt>
9
+ <dd>
10
+ <ol>
11
+ <% e[:backtrace].each do |line| %>
12
+ <li><%= ERB::Util.h(line) %></li>
13
+ <% end %>
14
+ </ol>
15
+ </dd>
16
+ </dl>
17
+ </div>
18
+ <% unless e[:code].nil? %>
19
+ <pre class="source"><code class="ruby"><%= e[:code] %></code></pre>
20
+ <% end %>
21
+ <% end %>
@@ -1,5 +1,6 @@
1
1
  require 'turnip_formatter/step_template/base'
2
- require 'slim'
2
+ require 'erb'
3
+ require 'ostruct'
3
4
 
4
5
  module TurnipFormatter
5
6
  module StepTemplate
@@ -21,37 +22,85 @@ module TurnipFormatter
21
22
  margin-top: 1em;
22
23
  margin-left: 1em;
23
24
  }
25
+
26
+ pre.source {
27
+ font-size: 12px;
28
+ font-family: monospace;
29
+ background-color: #073642;
30
+ color: #dddddd;
31
+ }
32
+
33
+ pre.source code.ruby {
34
+ padding: 0.1em 0 0.2em 0;
35
+ }
36
+
37
+ pre.source code.ruby .linenum {
38
+ width: 75px;
39
+ color: #fffbd3;
40
+ padding-right: 1em;
41
+ }
42
+
43
+ pre.source code.ruby .offending {
44
+ background-color: gray;
45
+ }
24
46
  EOS
25
47
  end
26
48
 
27
49
  #
28
- # @param [RSpec::Core::Example] example
50
+ # @param [TurnipFormatter::Resource::Step::Failure] step
29
51
  #
30
- def build_failed(example)
31
- exception = example.exception
52
+ def build_failed(step)
53
+ datas = step.exceptions.map do |e|
54
+ backtrace = formatted_backtrace(step.example, e)
55
+ code = extractor.snippet([backtrace.first])
32
56
 
33
- if example.exception.is_a?(RSpec::Core::MultipleExceptionError)
34
- exception = example.exception.all_exceptions.first
57
+ {
58
+ code: code,
59
+ message: e.to_s,
60
+ backtrace: backtrace,
61
+ }
35
62
  end
36
63
 
37
- build(exception.to_s, formatted_backtrace(example, exception))
64
+ render(exceptions: datas)
38
65
  end
39
66
 
40
67
  #
41
- # @param [RSpec::Core::Example] example
68
+ # @param [TurnipFormatter::Resource::Step::Pending] step
42
69
  #
43
- def build_pending(example)
44
- build(example.execution_result.pending_message, [example.location])
70
+ def build_pending(step)
71
+ datas = [{
72
+ code: nil,
73
+ message: step.pending_message,
74
+ backtrace: [step.pending_location]
75
+ }]
76
+
77
+ render(exceptions: datas)
45
78
  end
46
79
 
47
80
  private
48
81
 
49
- def build(message, backtrace)
50
- template_step_exception.render(Object.new, { message: message, backtrace: backtrace })
82
+ def render(args)
83
+ view.result(OpenStruct.new(args).instance_eval { binding })
84
+ end
85
+
86
+ def view
87
+ @view ||= ::ERB.new(File.read(File.dirname(__FILE__) + '/exception.html.erb'))
88
+ end
89
+
90
+ def extractor
91
+ @extractor ||= begin
92
+ # RSpec 3.4
93
+ require 'rspec/core/formatters/html_snippet_extractor'
94
+ ::RSpec::Core::Formatters::HtmlSnippetExtractor.new
95
+ rescue LoadError
96
+ # RSpec 3.3 or earlier
97
+ require 'rspec/core/formatters/snippet_extractor'
98
+ ::RSpec::Core::Formatters::SnippetExtractor.new
99
+ end
51
100
  end
52
101
 
53
- def template_step_exception
54
- @template_step_exception ||= Slim::Template.new(File.dirname(__FILE__) + "/exception.slim")
102
+ def formatted_backtrace(example, exception = nil)
103
+ RSpec::Core::Formatters::TurnipFormatter.formatted_backtrace(example, exception)
55
104
  end
56
105
  end
57
106
  end
@@ -1,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  module TurnipFormatter
4
- VERSION = '0.6.0-beta.6'
4
+ VERSION = '0.6.0-beta.7'
5
5
  end
@@ -45,7 +45,6 @@ module TurnipFormatter
45
45
 
46
46
  require 'rspec/core/formatters/turnip_formatter'
47
47
  require 'turnip_formatter/step_template/exception'
48
- require 'turnip_formatter/step_template/source'
49
48
  require 'turnip_formatter/ext/turnip/rspec'
50
49
  end
51
50
 
data/test/helper.rb CHANGED
@@ -72,7 +72,17 @@ module TurnipFormatter
72
72
  rspec_context.include(ExecuteWrapper)
73
73
 
74
74
  rspec_context.before(:example, before_hook_error: true) do
75
- undefined_method # NameError
75
+ #
76
+ # Workaround for JRuby <= 9.1.7.0
77
+ #
78
+ # https://github.com/jruby/jruby/issues/4467
79
+ # https://github.com/rspec/rspec-core/pull/2381
80
+ #
81
+ begin
82
+ undefined_method # NameError
83
+ rescue => e
84
+ raise e
85
+ end
76
86
  end
77
87
 
78
88
  rspec_context.after(:example, after_hook_error: true) do
@@ -1,6 +1,5 @@
1
1
  require 'helper'
2
2
  require 'turnip_formatter/renderer/html/step'
3
- require 'turnip_formatter/resource/step'
4
3
 
5
4
  module TurnipFormatter::Renderer::Html
6
5
  class TestStep < Test::Unit::TestCase
@@ -8,7 +7,7 @@ module TurnipFormatter::Renderer::Html
8
7
 
9
8
  sub_test_case 'step without argument' do
10
9
  def setup
11
- resource = TurnipFormatter::Resource::Step.new(nil, sample_step)
10
+ resource = TurnipFormatter::Resource::Step::Pass.new(nil, sample_step)
12
11
  @renderer = Step.new(resource)
13
12
  end
14
13
 
@@ -23,7 +22,7 @@ module TurnipFormatter::Renderer::Html
23
22
 
24
23
  sub_test_case 'step with argument' do
25
24
  def setup
26
- resource = TurnipFormatter::Resource::Step.new(nil, sample_step_with_docstring)
25
+ resource = TurnipFormatter::Resource::Step::Pass.new(nil, sample_step_with_docstring)
27
26
  @renderer = Step.new(resource)
28
27
  end
29
28
 
@@ -37,7 +36,7 @@ module TurnipFormatter::Renderer::Html
37
36
 
38
37
  sub_test_case 'step should be escaped html style' do
39
38
  def setup
40
- resource = TurnipFormatter::Resource::Step.new(nil, sample_step_should_escaping)
39
+ resource = TurnipFormatter::Resource::Step::Pass.new(nil, sample_step_should_escaping)
41
40
  @renderer = Step.new(resource)
42
41
  end
43
42
 
@@ -6,12 +6,21 @@ module TurnipFormatter::Resource::Scenario
6
6
  include TurnipFormatter::TestHelper
7
7
 
8
8
  def test_status
9
- @resource = Failure.new(scenario_example)
9
+ @resource = Failure.new(make_scenario(<<-EOS))
10
+ Scenario: This is a simple feature
11
+ Then [ERROR] it should die
12
+ EOS
13
+
10
14
  assert_equal(:failed, @resource.status)
11
15
  end
12
16
 
13
17
  def test_steps
14
- @resource = Failure.new(scenario_example)
18
+ @resource = Failure.new(make_scenario(<<-EOS))
19
+ Scenario: This is a simple feature
20
+ When I attack it
21
+ Then [ERROR] it should die
22
+ And I get drop items
23
+ EOS
15
24
 
16
25
  expect = [:passed, :failed, :unexecute]
17
26
  actual = @resource.steps.map(&:status)
@@ -19,86 +28,78 @@ module TurnipFormatter::Resource::Scenario
19
28
  assert_equal(expect, actual)
20
29
  end
21
30
 
31
+ def test_steps_has_multiple_error
32
+ @resource = Failure.new(make_scenario(<<-EOS))
33
+ @aggregate_failures
34
+ Scenario: Error in after hook
35
+ When I attack it
36
+ Then [ERROR] it should die
37
+ When retry
38
+ Then [ERROR] it should die
39
+ And I get drop items
40
+ EOS
41
+
42
+ expect = [:passed, :failed, :passed, :failed, :passed]
43
+ actual = @resource.steps.map(&:status)
44
+
45
+ assert_equal(expect, actual)
46
+ end
47
+
22
48
  def test_steps_has_error_in_before_hook
23
- @resource = Failure.new(scenario_error_before_hook)
49
+ @resource = Failure.new(make_scenario(<<-EOS))
50
+ @before_hook_error
51
+ Scenario: Error in before hook
52
+ When I attack it
53
+ Then it should die
54
+ EOS
24
55
 
25
56
  expect = [:failed, :unexecute, :unexecute]
26
57
  actual = @resource.steps.map(&:status)
27
58
 
28
59
  assert_equal(expect, actual)
29
- assert_equal(TurnipFormatter::Resource::Hook, @resource.steps.first.class)
60
+ assert_equal(TurnipFormatter::Resource::Step::BeforeHook, @resource.steps.first.class)
30
61
  end
31
62
 
32
63
  def test_steps_has_error_in_after_hook
33
- @resource = Failure.new(scenario_error_after_hook)
64
+ @resource = Failure.new(make_scenario(<<-EOS))
65
+ @after_hook_error
66
+ Scenario: Error in after hook
67
+ When I attack it
68
+ Then it should die
69
+ EOS
34
70
 
35
71
  expect = [:passed, :passed, :failed]
36
72
  actual = @resource.steps.map(&:status)
37
73
 
38
74
  assert_equal(expect, actual)
39
- assert_equal(TurnipFormatter::Resource::Hook, @resource.steps.last.class)
75
+ assert_equal(TurnipFormatter::Resource::Step::AfterHook, @resource.steps.last.class)
40
76
  end
41
77
 
42
78
  def test_steps_has_error_in_steps_and_after_hook
43
- @resource = Failure.new(scenario_error_step_and_after_hook)
79
+ @resource = Failure.new(make_scenario(<<-EOS))
80
+ @after_hook_error
81
+ Scenario: Error in after hook
82
+ When I attack it
83
+ Then [ERROR] it should die
84
+ And I get drop items
85
+ EOS
44
86
 
45
- expect = [:passed, :failed, :unexecute]
87
+ expect = [:passed, :failed, :unexecute, :failed]
46
88
  actual = @resource.steps.map(&:status)
47
89
 
48
90
  assert_equal(expect, actual)
49
- assert_equal(TurnipFormatter::Resource::Step, @resource.steps.last.class)
91
+ assert_equal(TurnipFormatter::Resource::Step::AfterHook, @resource.steps.last.class)
50
92
  end
51
93
 
52
94
  private
53
95
 
54
- def scenario_example
55
- scenario_examples[0]
56
- end
57
-
58
- def scenario_error_before_hook
59
- scenario_examples[1]
60
- end
61
-
62
- def scenario_error_after_hook
63
- scenario_examples[2]
64
- end
65
-
66
- def scenario_error_step_and_after_hook
67
- scenario_examples[3]
68
- end
69
-
70
- def scenario_examples
71
- @@scenario_examples ||= (
72
- feature = feature_build(feature_text)
73
- run_feature(feature, '/path/to/test.feature')
74
- )
75
- end
76
-
77
- def feature_text
78
- <<-EOS
96
+ def make_scenario(scenario_text)
97
+ feature_text = <<-EOS
79
98
  Feature: A simple feature
80
- Scenario: This is a simple feature
81
- When I attack it
82
- Then [ERROR] it should die
83
- And I get drop items
84
-
85
- @before_hook_error
86
- Scenario: Error in before hook
87
- When I attack it
88
- Then it should die
89
-
90
- @after_hook_error
91
- Scenario: Error in after hook
92
- When I attack it
93
- Then it should die
94
-
95
- @after_hook_error
96
- Scenario: Error in after hook
97
- When I attack it
98
- Then [ERROR] it should die
99
- And I get drop items
100
-
99
+ #{scenario_text}
101
100
  EOS
101
+ feature = feature_build(feature_text)
102
+ run_feature(feature, '/path/to/test.feature').first
102
103
  end
103
104
  end
104
105
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turnip_formatter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0.pre.beta.6
4
+ version: 0.6.0.pre.beta.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wataru MIYAGUNI
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-19 00:00:00.000000000 Z
11
+ date: 2017-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: turnip
@@ -246,16 +246,19 @@ files:
246
246
  - lib/turnip_formatter/renderer/html/views/statistics_speed.html.erb
247
247
  - lib/turnip_formatter/renderer/html/views/statistics_tag.html.erb
248
248
  - lib/turnip_formatter/renderer/html/views/step.html.erb
249
- - lib/turnip_formatter/resource/hook.rb
250
249
  - lib/turnip_formatter/resource/scenario/base.rb
251
250
  - lib/turnip_formatter/resource/scenario/failure.rb
252
251
  - lib/turnip_formatter/resource/scenario/pass.rb
253
252
  - lib/turnip_formatter/resource/scenario/pending.rb
254
- - lib/turnip_formatter/resource/step.rb
253
+ - lib/turnip_formatter/resource/step/base.rb
254
+ - lib/turnip_formatter/resource/step/failure.rb
255
+ - lib/turnip_formatter/resource/step/hook.rb
256
+ - lib/turnip_formatter/resource/step/pass.rb
257
+ - lib/turnip_formatter/resource/step/pending.rb
258
+ - lib/turnip_formatter/resource/step/unexecute.rb
255
259
  - lib/turnip_formatter/step_template/base.rb
260
+ - lib/turnip_formatter/step_template/exception.html.erb
256
261
  - lib/turnip_formatter/step_template/exception.rb
257
- - lib/turnip_formatter/step_template/exception.slim
258
- - lib/turnip_formatter/step_template/source.rb
259
262
  - lib/turnip_formatter/template.rb
260
263
  - lib/turnip_formatter/version.rb
261
264
  - spec/spec_helper.rb
@@ -1,30 +0,0 @@
1
- module TurnipFormatter
2
- module Resource
3
- class Hook
4
- attr_reader :example
5
- attr_reader :keyword
6
- attr_reader :status
7
-
8
- #
9
- # @param [RSpec::Core::Example] example
10
- #
11
- def initialize(example, keyword, status)
12
- @example = example
13
- @keyword = keyword
14
- @status = status
15
- end
16
-
17
- def text
18
- ''
19
- end
20
-
21
- def line
22
- -1
23
- end
24
-
25
- def argument
26
- nil
27
- end
28
- end
29
- end
30
- end
@@ -1,23 +0,0 @@
1
- require 'forwardable'
2
-
3
- module TurnipFormatter
4
- module Resource
5
- class Step
6
- extend Forwardable
7
- def_delegators :@raw, :keyword, :text, :line, :argument
8
-
9
- attr_reader :example
10
- attr_accessor :status
11
-
12
- #
13
- # @param [RSpec::Core::Example] example
14
- # @param [Turnip::Node::Step] raw
15
- #
16
- def initialize(example, raw)
17
- @example = example
18
- @raw = raw
19
- @status = :passed
20
- end
21
- end
22
- end
23
- end
@@ -1,10 +0,0 @@
1
- div.step_exception
2
- dl
3
- dt Failure:
4
- dd
5
- pre= message
6
- dt Backtrace:
7
- dd
8
- ol
9
- - backtrace.each do |line|
10
- li= line
@@ -1,63 +0,0 @@
1
- require 'turnip_formatter/step_template/base'
2
-
3
- module TurnipFormatter
4
- module StepTemplate
5
- class Source < Base
6
- on_failed :build
7
-
8
- def self.css
9
- <<-EOS
10
- pre.source {
11
- font-size: 12px;
12
- font-family: monospace;
13
- background-color: #073642;
14
- color: #dddddd;
15
- }
16
-
17
- pre.source code.ruby {
18
- padding: 0.1em 0 0.2em 0;
19
- }
20
-
21
- pre.source code.ruby .linenum {
22
- width: 75px;
23
- color: #fffbd3;
24
- padding-right: 1em;
25
- }
26
-
27
- pre.source code.ruby .offending {
28
- background-color: gray;
29
- }
30
- EOS
31
- end
32
-
33
- def build(example)
34
- code = extractor.snippet([location(example)])
35
- '<pre class="source"><code class="ruby">' + code + '</code></pre>'
36
- end
37
-
38
- private
39
-
40
- def location(example)
41
- exception = example.exception
42
-
43
- if example.exception.is_a?(RSpec::Core::MultipleExceptionError)
44
- exception = example.exception.all_exceptions.first
45
- end
46
-
47
- formatted_backtrace(example, exception).first
48
- end
49
-
50
- def extractor
51
- @extractor ||= begin
52
- # RSpec 3.4
53
- require 'rspec/core/formatters/html_snippet_extractor'
54
- ::RSpec::Core::Formatters::HtmlSnippetExtractor.new
55
- rescue LoadError
56
- # RSpec 3.3 or earlier
57
- require 'rspec/core/formatters/snippet_extractor'
58
- ::RSpec::Core::Formatters::SnippetExtractor.new
59
- end
60
- end
61
- end
62
- end
63
- end