turnip_formatter 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/turnip_formatter/ext/turnip/rspec.rb +7 -3
- data/lib/turnip_formatter/step/dsl.rb +15 -4
- data/lib/turnip_formatter/step.rb +8 -3
- data/lib/turnip_formatter/template.rb +11 -5
- data/lib/turnip_formatter/version.rb +1 -1
- data/spec/examples/features/battle2.feature +9 -0
- data/spec/examples/steps/steps.rb +4 -0
- data/spec/turnip_formatter/step/failure_spec.rb +22 -0
- data/spec/turnip_formatter/step/pending_spec.rb +22 -0
- data/spec/turnip_formatter/step_spec.rb +48 -0
- data/spec/turnip_formatter/template_spec.rb +52 -15
- metadata +3 -3
@@ -39,6 +39,10 @@ module Turnip
|
|
39
39
|
def run(feature_file)
|
40
40
|
Turnip::Builder.build(feature_file).features.each do |feature|
|
41
41
|
describe feature.name, feature.metadata_hash do
|
42
|
+
let :background_steps do
|
43
|
+
feature.backgrounds.map(&:steps).flatten
|
44
|
+
end
|
45
|
+
|
42
46
|
before do
|
43
47
|
example.metadata[:file_path] = feature_file
|
44
48
|
initialize_scenario_metadata
|
@@ -46,8 +50,8 @@ module Turnip
|
|
46
50
|
feature.backgrounds.each do |background|
|
47
51
|
push_scenario_metadata(background)
|
48
52
|
end
|
49
|
-
|
50
|
-
|
53
|
+
|
54
|
+
background_steps.each.with_index do |step, index|
|
51
55
|
run_step(feature_file, step, index)
|
52
56
|
end
|
53
57
|
end
|
@@ -58,7 +62,7 @@ module Turnip
|
|
58
62
|
end
|
59
63
|
|
60
64
|
it scenario.steps.map(&:description).join(' -> ') do
|
61
|
-
scenario.steps.each.with_index do |step, index|
|
65
|
+
scenario.steps.each.with_index(background_steps.size) do |step, index|
|
62
66
|
run_step(feature_file, step, index)
|
63
67
|
end
|
64
68
|
end
|
@@ -9,13 +9,24 @@ module TurnipFormatter
|
|
9
9
|
# @param [TurnipFormatter::Step] step
|
10
10
|
#
|
11
11
|
def extended(step)
|
12
|
-
|
13
|
-
step.docs[style] =
|
12
|
+
templates.each do |style, template|
|
13
|
+
step.docs[style] = {
|
14
|
+
klass: template[:klass],
|
15
|
+
value: step.instance_eval(&template[:block])
|
16
|
+
}
|
14
17
|
end
|
15
18
|
end
|
16
19
|
|
17
|
-
def add_template(style, &block)
|
18
|
-
::TurnipFormatter::Step.add_template(status, style, &block)
|
20
|
+
def add_template(style, template = nil, &block)
|
21
|
+
::TurnipFormatter::Step.add_template(status, style, template, &block)
|
22
|
+
end
|
23
|
+
|
24
|
+
def remove_template(style)
|
25
|
+
::TurnipFormatter::Step.remove_template(status, style)
|
26
|
+
end
|
27
|
+
|
28
|
+
def templates
|
29
|
+
::TurnipFormatter::Step.templates[status]
|
19
30
|
end
|
20
31
|
end
|
21
32
|
end
|
@@ -9,9 +9,14 @@ module TurnipFormatter
|
|
9
9
|
@templates ||= {}
|
10
10
|
end
|
11
11
|
|
12
|
-
def add_template(status, style, &block)
|
12
|
+
def add_template(status, style, klass = nil, &block)
|
13
13
|
templates[status] ||= {}
|
14
|
-
templates[status][style] = block
|
14
|
+
templates[status][style] = { klass: klass, block: block }
|
15
|
+
end
|
16
|
+
|
17
|
+
def remove_template(status, style)
|
18
|
+
templates[status].delete(style)
|
19
|
+
templates.delete(status.to_sym) if templates[status.to_sym].empty?
|
15
20
|
end
|
16
21
|
|
17
22
|
def status
|
@@ -26,7 +31,7 @@ module TurnipFormatter
|
|
26
31
|
def initialize(example, description)
|
27
32
|
@example = example
|
28
33
|
@name = description[:keyword] + description[:name]
|
29
|
-
@docs = { extra_args: description[:extra_args] }
|
34
|
+
@docs = { extra_args: { klass: nil, value: description[:extra_args] } }
|
30
35
|
end
|
31
36
|
|
32
37
|
def attention?
|
@@ -95,13 +95,11 @@ module TurnipFormatter
|
|
95
95
|
def step_args(step)
|
96
96
|
output = []
|
97
97
|
|
98
|
-
step.docs.each do |style,
|
98
|
+
step.docs.each do |style, template|
|
99
99
|
if style == :extra_args
|
100
|
-
output << step_extra_args(value)
|
100
|
+
output << step_extra_args(template[:value])
|
101
101
|
else
|
102
|
-
|
103
|
-
klass = ['step', style.to_s].map(&:capitalize).join
|
104
|
-
output << self.class.const_get(klass).build(value)
|
102
|
+
output << step_template(style, template[:klass]).build(template[:value])
|
105
103
|
end
|
106
104
|
end
|
107
105
|
|
@@ -115,6 +113,14 @@ module TurnipFormatter
|
|
115
113
|
end.join("\n")
|
116
114
|
end
|
117
115
|
|
116
|
+
def step_template(style, klass)
|
117
|
+
return klass if !!klass
|
118
|
+
|
119
|
+
# call Built-in template (StepException, StepSource, etc...)
|
120
|
+
klass = ['step', style.to_s].map(&:capitalize).join
|
121
|
+
self.class.const_get(klass)
|
122
|
+
end
|
123
|
+
|
118
124
|
def report_area
|
119
125
|
<<-EOS
|
120
126
|
<div id="report">
|
@@ -15,3 +15,12 @@ Feature: Battle a monster with weapon
|
|
15
15
|
Then it should die
|
16
16
|
And Fanfare
|
17
17
|
|
18
|
+
Scenario: boss monster
|
19
|
+
|
20
|
+
This scenario will error
|
21
|
+
So, fanfare is not...oh...
|
22
|
+
|
23
|
+
Given there is a boss monster
|
24
|
+
When I attack it
|
25
|
+
Then it should die
|
26
|
+
And Fanfare
|
@@ -15,6 +15,28 @@ module TurnipFormatter
|
|
15
15
|
step
|
16
16
|
end
|
17
17
|
|
18
|
+
it 'exists built-in step template' do
|
19
|
+
templates = TurnipFormatter::Step::Failure.templates
|
20
|
+
expect(templates.keys).to eq([:source, :exception])
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'add custom step template' do
|
24
|
+
before do
|
25
|
+
TurnipFormatter::Step::Failure.add_template :custom do
|
26
|
+
example.example_group.description
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
after do
|
31
|
+
TurnipFormatter::Step::Failure.remove_template :custom
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should get custom step template' do
|
35
|
+
templates = TurnipFormatter::Step::Failure.templates
|
36
|
+
expect(templates.keys).to eq([:source, :exception, :custom])
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
18
40
|
describe '#attention?' do
|
19
41
|
subject { step.attention? }
|
20
42
|
it { should be_true }
|
@@ -13,6 +13,28 @@ module TurnipFormatter
|
|
13
13
|
step
|
14
14
|
end
|
15
15
|
|
16
|
+
it 'exists built-in step template' do
|
17
|
+
templates = TurnipFormatter::Step::Pending.templates
|
18
|
+
expect(templates.keys).to eq([:exception])
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'add custom step template' do
|
22
|
+
before do
|
23
|
+
TurnipFormatter::Step::Pending.add_template :custom do
|
24
|
+
example.example_group.description
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
after do
|
29
|
+
TurnipFormatter::Step::Failure.remove_template :custom
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should get custom step template' do
|
33
|
+
templates = TurnipFormatter::Step::Pending.templates
|
34
|
+
expect(templates.keys).to eq([:exception, :custom])
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
16
38
|
describe '#attention?' do
|
17
39
|
subject { step.attention? }
|
18
40
|
it { should be_true }
|
@@ -21,5 +21,53 @@ module TurnipFormatter
|
|
21
21
|
subject { step.docs }
|
22
22
|
it { should include :extra_args }
|
23
23
|
end
|
24
|
+
|
25
|
+
describe '#add_template' do
|
26
|
+
let :custom_template do
|
27
|
+
Module.new do
|
28
|
+
def self.build(hoge)
|
29
|
+
hoge * 3
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
before do
|
35
|
+
TurnipFormatter::Step.add_template :hoge, :source1 do
|
36
|
+
'aiueo'
|
37
|
+
end
|
38
|
+
|
39
|
+
TurnipFormatter::Step.add_template :hoge, :source2, custom_template do
|
40
|
+
'12345'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
after do
|
45
|
+
TurnipFormatter::Step.remove_template(:hoge, :source1)
|
46
|
+
TurnipFormatter::Step.remove_template(:hoge, :source2)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'can add step template' do
|
50
|
+
style = TurnipFormatter::Step.templates[:hoge][:source1]
|
51
|
+
expect(style[:block].call).to eq('aiueo')
|
52
|
+
|
53
|
+
style = TurnipFormatter::Step.templates[:hoge][:source2]
|
54
|
+
expect(style[:klass].build(style[:block].call)).to eq('123451234512345')
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe '#remove_template' do
|
59
|
+
it 'can remove step template' do
|
60
|
+
TurnipFormatter::Step.add_template :hoge, :style1 do ; 'aiueo' end
|
61
|
+
TurnipFormatter::Step.add_template :hoge, :style2 do ; '12345' end
|
62
|
+
expect(TurnipFormatter::Step.templates[:hoge]).to have_key :style1
|
63
|
+
expect(TurnipFormatter::Step.templates[:hoge]).to have_key :style2
|
64
|
+
|
65
|
+
TurnipFormatter::Step.remove_template(:hoge, :style1)
|
66
|
+
expect(TurnipFormatter::Step.templates[:hoge]).to have_key :style2
|
67
|
+
|
68
|
+
TurnipFormatter::Step.remove_template(:hoge, :style2)
|
69
|
+
expect(TurnipFormatter::Step.templates).not_to have_key(:hoge)
|
70
|
+
end
|
71
|
+
end
|
24
72
|
end
|
25
73
|
end
|
@@ -56,24 +56,61 @@ module TurnipFormatter
|
|
56
56
|
end
|
57
57
|
|
58
58
|
context 'Step has arguments' do
|
59
|
-
|
60
|
-
let(:table) { Turnip::Table.new [] }
|
59
|
+
let(:table) { Turnip::Table.new [] }
|
61
60
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
61
|
+
context 'original template' do
|
62
|
+
describe '#step_args' do
|
63
|
+
let(:step) do
|
64
|
+
step = double
|
65
|
+
step.stub(:docs).and_return(
|
66
|
+
extra_args: { klass: nil, value: ['a', table] },
|
67
|
+
source: { klass: nil, value: 'b' },
|
68
|
+
exception: { klass: nil, value: 'c' }
|
69
|
+
)
|
70
|
+
step
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'should call corresponding method in step' do
|
74
|
+
Template::StepMultiline.should_receive(:build).with('a').and_return('extra_args1')
|
75
|
+
Template::StepOutline.should_receive(:build).with(table).and_return('extra_args2')
|
76
|
+
Template::StepSource.should_receive(:build).with('b').and_return('source')
|
77
|
+
Template::StepException.should_receive(:build).with('c').and_return('exception')
|
78
|
+
|
79
|
+
expect(template.send(:step_args, step)).to eq("extra_args1\nextra_args2\nsource\nexception")
|
80
|
+
end
|
68
81
|
end
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
82
|
+
end
|
83
|
+
|
84
|
+
context 'custom template' do
|
85
|
+
describe '#step_args' do
|
86
|
+
let(:custom_template_1) do
|
87
|
+
Module.new do
|
88
|
+
def self.build(value)
|
89
|
+
"<html>#{value}</html>"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
let(:custom_template_2) do
|
95
|
+
Module.new do
|
96
|
+
def self.build(value)
|
97
|
+
"<strong>#{value}</strong>"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
75
101
|
|
76
|
-
|
102
|
+
let(:step) do
|
103
|
+
step = double
|
104
|
+
step.stub(:docs).and_return(
|
105
|
+
source: { klass: custom_template_1, value: 'aiueo' },
|
106
|
+
exception: { klass: custom_template_2, value: '12345' }
|
107
|
+
)
|
108
|
+
step
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'should call corresponding method in step' do
|
112
|
+
expect(template.send(:step_args, step)).to eq("<html>aiueo</html>\n<strong>12345</strong>")
|
113
|
+
end
|
77
114
|
end
|
78
115
|
end
|
79
116
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: turnip_formatter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -172,7 +172,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
172
172
|
version: '0'
|
173
173
|
segments:
|
174
174
|
- 0
|
175
|
-
hash: -
|
175
|
+
hash: -1609512988288769776
|
176
176
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
177
177
|
none: false
|
178
178
|
requirements:
|
@@ -181,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
181
181
|
version: '0'
|
182
182
|
segments:
|
183
183
|
- 0
|
184
|
-
hash: -
|
184
|
+
hash: -1609512988288769776
|
185
185
|
requirements: []
|
186
186
|
rubyforge_project:
|
187
187
|
rubygems_version: 1.8.23
|