turnip_formatter 0.6.0.pre.beta.6 → 0.6.0.pre.beta.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/example/spec/features/basic.feature +14 -0
- data/example/spec/spec_helper.rb +11 -1
- data/lib/turnip_formatter/renderer/html/step.rb +1 -1
- data/lib/turnip_formatter/resource/scenario/base.rb +6 -7
- data/lib/turnip_formatter/resource/scenario/failure.rb +98 -70
- data/lib/turnip_formatter/resource/scenario/pass.rb +5 -0
- data/lib/turnip_formatter/resource/scenario/pending.rb +17 -12
- data/lib/turnip_formatter/resource/step/base.rb +24 -0
- data/lib/turnip_formatter/resource/step/failure.rb +27 -0
- data/lib/turnip_formatter/resource/step/hook.rb +50 -0
- data/lib/turnip_formatter/resource/step/pass.rb +13 -0
- data/lib/turnip_formatter/resource/step/pending.rb +21 -0
- data/lib/turnip_formatter/resource/step/unexecute.rb +13 -0
- data/lib/turnip_formatter/step_template/base.rb +0 -4
- data/lib/turnip_formatter/step_template/exception.html.erb +21 -0
- data/lib/turnip_formatter/step_template/exception.rb +63 -14
- data/lib/turnip_formatter/version.rb +1 -1
- data/lib/turnip_formatter.rb +0 -1
- data/test/helper.rb +11 -1
- data/test/turnip_formatter/renderer/html/test_step.rb +3 -4
- data/test/turnip_formatter/resource/scenario/test_failure.rb +56 -55
- metadata +9 -6
- data/lib/turnip_formatter/resource/hook.rb +0 -30
- data/lib/turnip_formatter/resource/step.rb +0 -23
- data/lib/turnip_formatter/step_template/exception.slim +0 -10
- data/lib/turnip_formatter/step_template/source.rb +0 -63
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03749d6d53a310780fc1e2595f537e7b35a9e73a
|
4
|
+
data.tar.gz: 1739d0a736c12f0e10b46c35192f2e0a321d1e7a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4b88812e427868f23695be4f9285afccf0970790521056e7f390669186a9e721ee94f033f9a5f51c9ca7ca7bdf85cb1e782c2d948c39c1a10ca6a6a72ab9a83
|
7
|
+
data.tar.gz: d9e4560bf2e3030a53842fa430a6e944714696a65e6ff8f0bfa1679a8e2f09a1aafcb00ef4811083b04dfb1e0892ce08a5af841f55829ed48cf933e4f2e062c0
|
data/.travis.yml
CHANGED
@@ -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
|
data/example/spec/spec_helper.rb
CHANGED
@@ -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
|
-
|
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
|
@@ -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/
|
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
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
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
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
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
|
-
|
45
|
+
def steps_with_error(exceptions)
|
46
|
+
step_klass = TurnipFormatter::Resource::Step::Pass
|
59
47
|
|
60
|
-
|
61
|
-
|
62
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
80
|
-
|
83
|
+
def error_in_before_hook?(exceptions)
|
84
|
+
exceptions.has_key?(:before)
|
81
85
|
end
|
82
86
|
|
83
|
-
def
|
84
|
-
|
85
|
-
|
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
|
90
|
-
exception.
|
91
|
-
|
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
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
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
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
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
|
@@ -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
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
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
|
-
|
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
|
-
|
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,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,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 '
|
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 [
|
50
|
+
# @param [TurnipFormatter::Resource::Step::Failure] step
|
29
51
|
#
|
30
|
-
def build_failed(
|
31
|
-
|
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
|
-
|
34
|
-
|
57
|
+
{
|
58
|
+
code: code,
|
59
|
+
message: e.to_s,
|
60
|
+
backtrace: backtrace,
|
61
|
+
}
|
35
62
|
end
|
36
63
|
|
37
|
-
|
64
|
+
render(exceptions: datas)
|
38
65
|
end
|
39
66
|
|
40
67
|
#
|
41
|
-
# @param [
|
68
|
+
# @param [TurnipFormatter::Resource::Step::Pending] step
|
42
69
|
#
|
43
|
-
def build_pending(
|
44
|
-
|
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
|
50
|
-
|
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
|
54
|
-
|
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
|
data/lib/turnip_formatter.rb
CHANGED
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
|
-
|
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(
|
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(
|
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(
|
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::
|
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(
|
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::
|
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(
|
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
|
55
|
-
|
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
|
-
|
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.
|
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-
|
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,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
|