spinach 0.10.0 → 0.10.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,84 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative '../../test_helper'
4
+
5
+ describe Spinach::Reporter::FailureFile do
6
+ let(:feature) { stub_everything(filename: 'features/test.feature') }
7
+ let(:scenario) { stub_everything(lines: [1,2]) }
8
+
9
+ describe '#initialize' do
10
+ it 'generates a distinctive output filename if none is provided' do
11
+ @reporter = Spinach::Reporter::FailureFile.new
12
+ @reporter.filename.wont_be_nil
13
+ @reporter.filename.must_be_kind_of String
14
+ end
15
+
16
+ it 'uses a provided output filename option' do
17
+ @reporter = Spinach::Reporter::FailureFile.new(failure_filename: 'foo')
18
+ @reporter.filename.must_equal 'foo'
19
+ end
20
+
21
+ it 'uses a provided output filename environment variable' do
22
+ ENV['SPINACH_FAILURE_FILE'] = 'asdf'
23
+ @reporter = Spinach::Reporter::FailureFile.new
24
+ @reporter.filename.must_equal 'asdf'
25
+ end
26
+
27
+ it 'initializes the array of failing scenarios' do
28
+ @reporter = Spinach::Reporter::FailureFile.new
29
+ @reporter.failing_scenarios.wont_be_nil
30
+ @reporter.failing_scenarios.must_be_kind_of Array
31
+ @reporter.failing_scenarios.must_be_empty
32
+ end
33
+
34
+ after do
35
+ ENV.delete('SPINACH_FAILURE_FILE')
36
+ end
37
+ end
38
+
39
+ describe 'hooks' do
40
+ before do
41
+ @reporter = Spinach::Reporter::FailureFile.new(failure_filename: "tmp/test-failures_#{Time.now.strftime('%F_%H-%M-%S-%L')}.txt")
42
+ @reporter.set_current_feature(feature)
43
+ @reporter.set_current_scenario(scenario)
44
+ end
45
+
46
+ describe '#on_failed_step' do
47
+ it 'collects the feature and line number for outputting later' do
48
+ @reporter.failing_scenarios.must_be_empty
49
+ @reporter.on_failed_step(anything)
50
+ @reporter.failing_scenarios.must_include "#{feature.filename}:#{scenario.lines[0]}"
51
+ end
52
+ end
53
+
54
+ describe '#on_error_step' do
55
+ it 'collects the feature and line number for outputting later' do
56
+ @reporter.failing_scenarios.must_be_empty
57
+ @reporter.on_error_step(anything)
58
+ @reporter.failing_scenarios.must_include "#{feature.filename}:#{scenario.lines[0]}"
59
+ end
60
+ end
61
+
62
+ describe '#after_run' do
63
+ describe 'when the run has succeeded' do
64
+ it 'no failure file is created' do
65
+ @reporter.after_run(true)
66
+ refute File.exist?(@reporter.filename), 'Output file should not exist when run is successful'
67
+ end
68
+ end
69
+
70
+ describe 'when the run has failed' do
71
+ it 'failure file is created and includes expected output' do
72
+ @reporter.on_failed_step(anything)
73
+ @reporter.after_run(false)
74
+ assert File.exist?(@reporter.filename)
75
+ f = File.open(@reporter.filename)
76
+ f.read.must_equal "#{feature.filename}:#{scenario.lines[0]}"
77
+ f.close
78
+ File.unlink(@reporter.filename)
79
+ end
80
+ end
81
+ end
82
+ end
83
+
84
+ end
@@ -1,24 +1,19 @@
1
1
  require_relative '../../test_helper'
2
2
 
3
3
  describe Spinach::Runner::FeatureRunner do
4
- let(:feature) {
5
- stub('feature',
6
- name: 'Feature',
7
- scenarios: [],
8
- background_steps: []
9
- )
10
- }
11
- subject{ Spinach::Runner::FeatureRunner.new(feature) }
4
+ let(:feature) do
5
+ stub('feature',
6
+ name: 'Feature',
7
+ scenarios: [],
8
+ background_steps: []
9
+ )
10
+ end
11
+ subject { Spinach::Runner::FeatureRunner.new(feature) }
12
12
 
13
13
  describe '#initialize' do
14
14
  it 'initializes the given filename' do
15
15
  subject.feature.must_equal feature
16
16
  end
17
-
18
- it 'initalizes the given scenario line' do
19
- @runner = Spinach::Runner::FeatureRunner.new(feature, '34')
20
- @runner.instance_variable_get(:@line).must_equal 34
21
- end
22
17
  end
23
18
 
24
19
  describe '#scenarios' do
@@ -29,24 +24,30 @@ describe Spinach::Runner::FeatureRunner do
29
24
  end
30
25
 
31
26
  describe '#run' do
32
- it 'runs the hooks in order' do
33
- hooks = sequence('hooks')
34
- Spinach.hooks.expects(:run_before_feature).with(feature).in_sequence(hooks)
35
- Spinach.expects(:find_step_definitions).returns(false).in_sequence(hooks)
36
- Spinach.hooks.expects(:run_after_feature).with(feature).in_sequence(hooks)
37
-
38
- subject.run
27
+ describe "when some steps don't exist" do
28
+ it 'runs the hooks in order' do
29
+ hooks = sequence('hooks')
30
+ Spinach.hooks.expects(:run_before_feature).with(feature).in_sequence(hooks)
31
+ Spinach.expects(:find_step_definitions).returns(false).in_sequence(hooks)
32
+ Spinach.hooks.expects(:run_after_feature).with(feature).in_sequence(hooks)
33
+
34
+ subject.run
35
+ end
39
36
  end
40
37
 
41
- describe 'when the steps exist' do
38
+ describe 'when all the steps exist' do
42
39
  before do
43
- @feature = stub('feature', name: 'Feature')
44
- Spinach.stubs(:find_step_definitions).returns(true)
45
40
  @scenarios = [
46
41
  scenario = stub(tags: []),
47
42
  another_scenario = stub(tags: [])
48
43
  ]
49
- @feature.stubs(:scenarios).returns @scenarios
44
+ @feature = stub('feature',
45
+ name: "Feature",
46
+ tags: [],
47
+ scenarios: @scenarios,
48
+ run_every_scenario?: true
49
+ )
50
+ Spinach.stubs(:find_step_definitions).returns(true)
50
51
  @runner = Spinach::Runner::FeatureRunner.new(@feature)
51
52
  end
52
53
 
@@ -62,13 +63,15 @@ describe Spinach::Runner::FeatureRunner do
62
63
  end
63
64
 
64
65
  describe 'and the scenarios fail' do
65
- it 'runs the scenarios and returns false' do
66
- @scenarios.each do |scenario|
67
- runner = stub(run: false)
68
- Spinach::Runner::ScenarioRunner.expects(:new).with(scenario).returns runner
69
- end
66
+ describe "without config option fail_fast set" do
67
+ it 'runs the scenarios and returns false' do
68
+ @scenarios.each do |scenario|
69
+ runner = stub(run: false)
70
+ Spinach::Runner::ScenarioRunner.expects(:new).with(scenario).returns runner
71
+ end
70
72
 
71
- @runner.run.must_equal false
73
+ @runner.run.must_equal false
74
+ end
72
75
  end
73
76
 
74
77
  describe "with config option fail_fast set" do
@@ -97,38 +100,46 @@ describe Spinach::Runner::FeatureRunner do
97
100
  end
98
101
  end
99
102
 
100
- describe "when a line is given" do
103
+ describe "when only running specific lines" do
101
104
  before do
102
- @feature = stub('feature', name: 'Feature')
103
- Spinach.stubs(:find_step_definitions).returns(true)
104
105
  @scenarios = [
105
- scenario = stub(line: 4, tags: []),
106
- another_scenario = stub(line: 12, tags: [])
106
+ stub(tags: [], lines: (4..8).to_a),
107
+ stub(tags: [], lines: (12..15).to_a),
107
108
  ]
108
- @feature.stubs(:scenarios).returns @scenarios
109
+ @feature = stub('feature',
110
+ name: 'Feature',
111
+ tags: [],
112
+ scenarios: @scenarios,
113
+ run_every_scenario?: false,
114
+ )
115
+ Spinach.stubs(:find_step_definitions).returns(true)
109
116
  end
110
117
 
111
118
  it "runs exactly matching scenario" do
112
119
  Spinach::Runner::ScenarioRunner.expects(:new).with(@scenarios[1]).returns stub(run: true)
113
- @runner = Spinach::Runner::FeatureRunner.new(@feature, "12")
120
+ @feature.stubs(:lines_to_run).returns([12])
121
+ @runner = Spinach::Runner::FeatureRunner.new(@feature)
114
122
  @runner.run
115
123
  end
116
124
 
117
125
  it "runs no scenario and returns false" do
118
126
  Spinach::Runner::ScenarioRunner.expects(:new).never
119
- @runner = Spinach::Runner::FeatureRunner.new(@feature, "3")
127
+ @feature.stubs(:lines_to_run).returns([3])
128
+ @runner = Spinach::Runner::FeatureRunner.new(@feature)
120
129
  @runner.run
121
130
  end
122
131
 
123
132
  it "runs matching scenario" do
124
133
  Spinach::Runner::ScenarioRunner.expects(:new).with(@scenarios[0]).returns stub(run: true)
125
- @runner = Spinach::Runner::FeatureRunner.new(@feature, "8")
134
+ @feature.stubs(:lines_to_run).returns([8])
135
+ @runner = Spinach::Runner::FeatureRunner.new(@feature)
126
136
  @runner.run
127
137
  end
128
138
 
129
139
  it "runs last scenario" do
130
140
  Spinach::Runner::ScenarioRunner.expects(:new).with(@scenarios[1]).returns stub(run: true)
131
- @runner = Spinach::Runner::FeatureRunner.new(@feature, "15")
141
+ @feature.stubs(:lines_to_run).returns([15])
142
+ @runner = Spinach::Runner::FeatureRunner.new(@feature)
132
143
  @runner.run
133
144
  end
134
145
  end
@@ -137,10 +148,14 @@ describe Spinach::Runner::FeatureRunner do
137
148
 
138
149
  describe "with feature" do
139
150
  before do
140
- @feature = stub('feature', name: 'Feature', tags: ["feature_tag"])
151
+ @scenario = stub(tags: [])
152
+ @feature = stub('feature',
153
+ name: 'Feature',
154
+ tags: ["feature_tag"],
155
+ scenarios: [@scenario],
156
+ run_every_scenario?: true,
157
+ )
141
158
  Spinach.stubs(:find_step_definitions).returns(true)
142
- @scenario = stub(line: 4, tags: [])
143
- @feature.stubs(:scenarios).returns [@scenario]
144
159
  end
145
160
 
146
161
  it "runs matching feature" do
@@ -154,10 +169,14 @@ describe Spinach::Runner::FeatureRunner do
154
169
 
155
170
  describe "with scenario" do
156
171
  before do
157
- @feature = stub('feature', name: 'Feature', tags: ["feature_tag"])
172
+ @scenario = stub(tags: ["scenario_tag"])
173
+ @feature = stub('feature',
174
+ name: 'Feature',
175
+ tags: ["feature_tag"],
176
+ scenarios: [@scenario],
177
+ run_every_scenario?: true,
178
+ )
158
179
  Spinach.stubs(:find_step_definitions).returns(true)
159
- @scenario = stub(line: 4, tags: ["scenario_tag"])
160
- @feature.stubs(:scenarios).returns [@scenario]
161
180
  end
162
181
 
163
182
  it "runs matching scenario" do
@@ -177,7 +196,7 @@ describe Spinach::Runner::FeatureRunner do
177
196
  end
178
197
 
179
198
  it "doesn't accumulate tags from one scenario to the next" do
180
- next_scenario = stub(line: 14, tags: [])
199
+ next_scenario = stub(tags: [])
181
200
  @feature.stubs(:scenarios).returns [@scenario, next_scenario]
182
201
 
183
202
  Spinach::TagsMatcher.expects(:match).with(["feature_tag", "scenario_tag"]).returns true
@@ -37,6 +37,31 @@ module Spinach
37
37
  end
38
38
 
39
39
  describe '#run' do
40
+ describe 'hooks (no #run_step stub)' do
41
+ before(:each) do
42
+ subject.stubs(:step_definitions).returns step_definitions = stub
43
+ step_definitions.stubs(:before_each)
44
+ step_definitions.stubs(:after_each)
45
+ step_definitions.stubs(:step_location_for)
46
+ end
47
+
48
+ let(:scenario) { stub(feature: feature, steps: [steps.first], name: 'test' ) }
49
+
50
+ it 'runs hooks in order (no #run_step stub)' do
51
+ hooks = sequence('hooks')
52
+
53
+ Spinach.hooks.expects(:run_before_scenario).with(scenario, step_definitions).in_sequence(hooks)
54
+ Spinach.hooks.expects(:run_around_scenario).with(scenario, step_definitions).in_sequence(hooks).yields
55
+
56
+ Spinach.hooks.expects(:run_before_step).with(steps.first, step_definitions).in_sequence(hooks)
57
+ Spinach.hooks.expects(:run_around_step).with(steps.first, step_definitions).in_sequence(hooks).yields
58
+ Spinach.hooks.expects(:run_after_step).with(steps.first, step_definitions).in_sequence(hooks)
59
+
60
+ Spinach.hooks.expects(:run_after_scenario).with(scenario, step_definitions).in_sequence(hooks)
61
+ subject.run
62
+ end
63
+ end
64
+
40
65
  describe 'hooks' do
41
66
  before(:each) do
42
67
  subject.stubs(:step_definitions).returns step_definitions = stub
@@ -78,14 +103,26 @@ module Spinach
78
103
  subject.run
79
104
  end
80
105
 
81
- it 'raises if around hook does not yield' do
106
+ it 'raises if around_scenario hook does not yield' do
82
107
  subject.stubs(:step_definitions).returns stub
83
108
 
84
109
  Spinach.hooks.stubs(:run_around_scenario).with(scenario, step_definitions)
85
110
 
86
- proc do
111
+ e = proc do
112
+ subject.run
113
+ end.must_raise Spinach::HookNotYieldException
114
+ e.hook.must_match /around_scenario/
115
+ end
116
+
117
+ it 'raises if around_step hook does not yield' do
118
+ step_definitions.stubs(:step_location_for)
119
+
120
+ Spinach.hooks.stubs(:run_around_step).with(steps.first, step_definitions)
121
+
122
+ e = proc do
87
123
  subject.run
88
- end.must_raise RuntimeError
124
+ end.must_raise Spinach::HookNotYieldException
125
+ e.hook.must_match /around_step/
89
126
  end
90
127
  end
91
128
  end
@@ -36,25 +36,25 @@ describe Spinach::Runner do
36
36
  end
37
37
  end
38
38
 
39
- describe '#init_reporter' do
40
- describe "when no reporter_class option is passed in" do
39
+ describe '#init_reporters' do
40
+ describe "when no reporter_classes option is passed in" do
41
41
  it 'inits the default reporter' do
42
42
  reporter = stub
43
43
  reporter.expects(:bind)
44
44
  Spinach::Reporter::Stdout.stubs(new: reporter)
45
- runner.init_reporter
45
+ runner.init_reporters
46
46
  end
47
47
  end
48
48
 
49
- describe "when reporter_class option is passed in" do
50
- it "inits the reporter class" do
49
+ describe "when reporter_classes option is passed in" do
50
+ it "inits the reporter classes" do
51
51
  config = Spinach::Config.new
52
52
  Spinach.stubs(:config).returns(config)
53
- config.reporter_class = "String"
53
+ config.reporter_classes = ["String"]
54
54
  reporter = stub
55
55
  reporter.expects(:bind)
56
56
  String.stubs(new: reporter)
57
- runner.init_reporter
57
+ runner.init_reporters
58
58
  end
59
59
  end
60
60
 
@@ -66,7 +66,7 @@ describe Spinach::Runner do
66
66
  reporter = stub
67
67
  reporter.stubs(:bind)
68
68
  Spinach::Reporter::Stdout.expects(new: reporter).with(backtrace: true)
69
- runner.init_reporter
69
+ runner.init_reporters
70
70
  end
71
71
  end
72
72
  end
@@ -86,8 +86,8 @@ describe Spinach::Runner do
86
86
  runner.stubs(required_files: [])
87
87
  end
88
88
 
89
- it "inits reporter" do
90
- runner.expects(:init_reporter)
89
+ it "inits reporters" do
90
+ runner.expects(:init_reporters)
91
91
  runner.run
92
92
  end
93
93
 
@@ -107,7 +107,7 @@ describe Spinach::Runner do
107
107
  let(:filenames) { ["#{filename}:#{line}"] }
108
108
  let(:runner) { Spinach::Runner.new(filenames) }
109
109
 
110
- it 'sets filename and line on the feature' do
110
+ it 'sets filename and lines_to_run on the feature' do
111
111
  @feature_runner = stub
112
112
  Spinach::Parser.stubs(:open_file).with(filename).returns parser = stub
113
113
  parser.stubs(:parse).returns feature = Spinach::Feature.new
@@ -119,7 +119,7 @@ describe Spinach::Runner do
119
119
 
120
120
  runner.run.must_equal true
121
121
  feature.filename.must_equal filename
122
- feature.lines.must_equal [line]
122
+ feature.lines_to_run.must_equal [line]
123
123
  end
124
124
  end
125
125
 
@@ -139,11 +139,11 @@ describe Spinach::Runner do
139
139
  runner.stubs(required_files: [])
140
140
  end
141
141
 
142
- it "sets filename and lines on the feature" do
142
+ it "sets filename and lines_to_run on the feature" do
143
143
  @feature_runner.stubs(:run).returns(true)
144
144
  runner.run.must_equal true
145
145
  @feature.filename.must_equal filename
146
- @feature.lines.must_equal line.split(":").map(&:to_i)
146
+ @feature.lines_to_run.must_equal line.split(":").map(&:to_i)
147
147
  end
148
148
 
149
149
  it "returns false if it fails" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spinach
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.10.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josep Jaume Rey
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2017-01-16 00:00:00.000000000 Z
14
+ date: 2018-02-21 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: gherkin-ruby
@@ -220,6 +220,7 @@ files:
220
220
  - features/reporting/show_step_source_location.feature
221
221
  - features/reporting/undefined_feature_reporting.feature
222
222
  - features/rspec_compatibility.feature
223
+ - features/running_specific_scenarios.feature
223
224
  - features/step_auditing.feature
224
225
  - features/steps/automatic_feature_generation.rb
225
226
  - features/steps/background.rb
@@ -236,6 +237,7 @@ files:
236
237
  - features/steps/reporting/undefined_feature_reporting.rb
237
238
  - features/steps/reporting/use_customized_reporter.rb
238
239
  - features/steps/rspec_compatibility.rb
240
+ - features/steps/running_specific_scenarios.rb
239
241
  - features/steps/step_auditing.rb
240
242
  - features/support/env.rb
241
243
  - features/support/error_reporting.rb
@@ -264,9 +266,11 @@ files:
264
266
  - lib/spinach/parser.rb
265
267
  - lib/spinach/parser/visitor.rb
266
268
  - lib/spinach/reporter.rb
269
+ - lib/spinach/reporter/failure_file.rb
267
270
  - lib/spinach/reporter/progress.rb
268
271
  - lib/spinach/reporter/reporting.rb
269
272
  - lib/spinach/reporter/stdout.rb
273
+ - lib/spinach/rspec/mocks.rb
270
274
  - lib/spinach/runner.rb
271
275
  - lib/spinach/runner/feature_runner.rb
272
276
  - lib/spinach/runner/scenario_runner.rb
@@ -291,6 +295,7 @@ files:
291
295
  - test/spinach/hooks_test.rb
292
296
  - test/spinach/parser/visitor_test.rb
293
297
  - test/spinach/parser_test.rb
298
+ - test/spinach/reporter/failure_file_test.rb
294
299
  - test/spinach/reporter/progress_test.rb
295
300
  - test/spinach/reporter/stdout/error_reporting_test.rb
296
301
  - test/spinach/reporter/stdout_test.rb
@@ -345,6 +350,7 @@ test_files:
345
350
  - features/reporting/show_step_source_location.feature
346
351
  - features/reporting/undefined_feature_reporting.feature
347
352
  - features/rspec_compatibility.feature
353
+ - features/running_specific_scenarios.feature
348
354
  - features/step_auditing.feature
349
355
  - features/steps/automatic_feature_generation.rb
350
356
  - features/steps/background.rb
@@ -361,6 +367,7 @@ test_files:
361
367
  - features/steps/reporting/undefined_feature_reporting.rb
362
368
  - features/steps/reporting/use_customized_reporter.rb
363
369
  - features/steps/rspec_compatibility.rb
370
+ - features/steps/running_specific_scenarios.rb
364
371
  - features/steps/step_auditing.rb
365
372
  - features/support/env.rb
366
373
  - features/support/error_reporting.rb
@@ -382,6 +389,7 @@ test_files:
382
389
  - test/spinach/hooks_test.rb
383
390
  - test/spinach/parser/visitor_test.rb
384
391
  - test/spinach/parser_test.rb
392
+ - test/spinach/reporter/failure_file_test.rb
385
393
  - test/spinach/reporter/progress_test.rb
386
394
  - test/spinach/reporter/stdout/error_reporting_test.rb
387
395
  - test/spinach/reporter/stdout_test.rb