cucumber-core 0.2.0 → 1.0.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -1
  3. data/cucumber-core.gemspec +1 -1
  4. data/lib/cucumber/core.rb +6 -6
  5. data/lib/cucumber/core/ast/data_table.rb +8 -0
  6. data/lib/cucumber/core/ast/describes_itself.rb +1 -1
  7. data/lib/cucumber/core/ast/examples_table.rb +8 -2
  8. data/lib/cucumber/core/ast/feature.rb +2 -3
  9. data/lib/cucumber/core/ast/location.rb +11 -6
  10. data/lib/cucumber/core/ast/names.rb +10 -1
  11. data/lib/cucumber/core/ast/outline_step.rb +6 -3
  12. data/lib/cucumber/core/ast/scenario.rb +0 -1
  13. data/lib/cucumber/core/ast/scenario_outline.rb +2 -3
  14. data/lib/cucumber/core/ast/step.rb +2 -2
  15. data/lib/cucumber/core/gherkin/ast_builder.rb +4 -1
  16. data/lib/cucumber/core/test/case.rb +10 -6
  17. data/lib/cucumber/core/test/filters/debug_filter.rb +28 -0
  18. data/lib/cucumber/core/test/filters/tag_filter.rb +1 -1
  19. data/lib/cucumber/core/test/hooks.rb +76 -0
  20. data/lib/cucumber/core/test/mapper.rb +101 -19
  21. data/lib/cucumber/core/test/mapping.rb +15 -4
  22. data/lib/cucumber/core/test/result.rb +39 -27
  23. data/lib/cucumber/core/test/runner.rb +76 -81
  24. data/lib/cucumber/core/test/step.rb +10 -18
  25. data/lib/cucumber/core/version.rb +1 -1
  26. data/spec/cucumber/core/ast/data_table_spec.rb +12 -0
  27. data/spec/cucumber/core/ast/location_spec.rb +8 -1
  28. data/spec/cucumber/core/ast/outline_step_spec.rb +11 -4
  29. data/spec/cucumber/core/ast/step_spec.rb +2 -2
  30. data/spec/cucumber/core/compiler_spec.rb +6 -6
  31. data/spec/cucumber/core/gherkin/parser_spec.rb +31 -18
  32. data/spec/cucumber/core/test/case_spec.rb +24 -24
  33. data/spec/cucumber/core/test/hooks_spec.rb +30 -0
  34. data/spec/cucumber/core/test/mapper_spec.rb +115 -1
  35. data/spec/cucumber/core/test/mapping_spec.rb +22 -6
  36. data/spec/cucumber/core/test/result_spec.rb +0 -8
  37. data/spec/cucumber/core/test/runner_spec.rb +31 -97
  38. data/spec/cucumber/core/test/step_spec.rb +24 -16
  39. data/spec/cucumber/core_spec.rb +109 -16
  40. data/spec/report_api_spy.rb +24 -0
  41. metadata +32 -28
  42. data/lib/cucumber/core/test/hook_compiler.rb +0 -109
  43. data/spec/cucumber/core/test/hook_compiler_spec.rb +0 -78
@@ -1,3 +1,4 @@
1
+ require 'report_api_spy'
1
2
  require 'cucumber/core'
2
3
  require 'cucumber/core/gherkin/writer'
3
4
  require 'cucumber/core/platform'
@@ -28,11 +29,9 @@ module Cucumber
28
29
  end
29
30
 
30
31
  describe "compiling features to a test suite" do
32
+
31
33
  it "compiles two scenarios into two test cases" do
32
- visitor = double
33
- expect( visitor ).to receive(:test_case).exactly(2).times.and_yield.ordered
34
- expect( visitor ).to receive(:test_step).exactly(5).times.ordered
35
- expect( visitor ).to receive(:done).once.ordered
34
+ visitor = ReportAPISpy.new
36
35
 
37
36
  compile([
38
37
  gherkin do
@@ -50,6 +49,17 @@ module Cucumber
50
49
  end
51
50
  end
52
51
  ], visitor)
52
+
53
+ expect( visitor.messages ).to eq [
54
+ :test_case,
55
+ :test_step,
56
+ :test_step,
57
+ :test_case,
58
+ :test_step,
59
+ :test_step,
60
+ :test_step,
61
+ :done,
62
+ ]
53
63
  end
54
64
 
55
65
  it "filters out test cases based on a tag expression" do
@@ -214,6 +224,10 @@ module Cucumber
214
224
  @test_steps = Core::Test::Result::Summary.new
215
225
  end
216
226
 
227
+ def before_test_case(*)
228
+ yield if block_given?
229
+ end
230
+
217
231
  def after_test_case(test_case, result)
218
232
  result.describe_to test_cases
219
233
  end
@@ -275,25 +289,61 @@ module Cucumber
275
289
  context "with hooks" do
276
290
  class HookTestMappings
277
291
  Failure = Class.new(StandardError)
292
+ attr_reader :logger
293
+
294
+ def initialize
295
+ @logger = []
296
+ end
278
297
 
279
298
  def test_case(test_case, mapper)
299
+ mapper.before { @logger << ['--'] }
300
+ failing_before = -> do
301
+ @logger << [:failing_before, test_case.name]
302
+ raise Failure
303
+ end
304
+ passing_after = -> do
305
+ @logger << [:passing_after, test_case.name]
306
+ end
307
+ passing_before = -> do
308
+ @logger << [:passing_before, test_case.name]
309
+ end
310
+ failing_after = -> do
311
+ @logger << [:failing_after, test_case.name]
312
+ raise Failure
313
+ end
314
+
280
315
  case test_case.name
316
+
281
317
  when /fail before/
282
- mapper.before { raise Failure }
283
- mapper.after { 'This hook will be skipped' }
318
+ mapper.before( &failing_before )
319
+ mapper.after( &passing_after )
320
+
284
321
  when /fail after/
285
- mapper.after { raise Failure }
322
+ mapper.before( &passing_before )
323
+ mapper.after( &failing_after )
324
+
325
+ else
326
+ mapper.before( &passing_before )
327
+ mapper.after( &passing_after )
328
+
286
329
  end
330
+
287
331
  self
288
332
  end
289
333
 
290
- def test_step(step, mapper)
291
- mapper.map {} # all steps pass
334
+ def test_step(test_step, mapper)
335
+ mapper.map { @logger << [:step, test_step.name] } # all steps pass
336
+ if test_step.name == 'fail after'
337
+ mapper.after do
338
+ @logger << :failing_after_step
339
+ raise Failure
340
+ end
341
+ end
292
342
  self
293
343
  end
294
344
  end
295
345
 
296
- it "executes the test cases in the suite" do
346
+ it "executes the steps and hooks in the right order" do
297
347
  gherkin = gherkin do
298
348
  feature do
299
349
  scenario 'fail before' do
@@ -304,6 +354,10 @@ module Cucumber
304
354
  step 'passing'
305
355
  end
306
356
 
357
+ scenario 'fail step' do
358
+ step 'fail after'
359
+ end
360
+
307
361
  scenario 'passing' do
308
362
  step 'passing'
309
363
  end
@@ -314,11 +368,29 @@ module Cucumber
314
368
 
315
369
  execute [gherkin], mappings, report
316
370
 
317
- expect( report.test_steps.total ).to eq(6)
318
- expect( report.test_steps.total_failed ).to eq(2)
319
- expect( report.test_cases.total ).to eq(3)
371
+ expect( report.test_steps.total ).to eq(17)
372
+ expect( report.test_steps.total_failed ).to eq(3)
373
+ expect( report.test_cases.total ).to eq(4)
320
374
  expect( report.test_cases.total_passed ).to eq(1)
321
- expect( report.test_cases.total_failed ).to eq(2)
375
+ expect( report.test_cases.total_failed ).to eq(3)
376
+ expect( mappings.logger ).to eq [
377
+ ["--"],
378
+ [:failing_before, "Scenario: fail before"],
379
+ [:passing_after, "Scenario: fail before"],
380
+ ["--"],
381
+ [:passing_before, "Scenario: fail after"],
382
+ [:step, "passing"],
383
+ [:failing_after, "Scenario: fail after"],
384
+ ["--"],
385
+ [:passing_before, "Scenario: fail step"],
386
+ [:step, "fail after"],
387
+ :failing_after_step,
388
+ [:passing_after, "Scenario: fail step"],
389
+ ["--"],
390
+ [:passing_before, "Scenario: passing"],
391
+ [:step, "passing"],
392
+ [:passing_after, "Scenario: passing"]
393
+ ]
322
394
  end
323
395
  end
324
396
 
@@ -333,10 +405,16 @@ module Cucumber
333
405
  def test_case(test_case, mapper)
334
406
  logger = @logger
335
407
  mapper.around do |run_scenario|
336
- logger << :before
408
+ logger << :before_all
337
409
  run_scenario.call
338
410
  logger << :middle
339
411
  run_scenario.call
412
+ logger << :after_all
413
+ end
414
+ mapper.before do
415
+ logger << :before
416
+ end
417
+ mapper.after do
340
418
  logger << :after
341
419
  end
342
420
  self
@@ -347,6 +425,9 @@ module Cucumber
347
425
  mapper.map do
348
426
  logger << :during
349
427
  end
428
+ mapper.after do
429
+ logger << :after_step
430
+ end
350
431
  self
351
432
  end
352
433
  end
@@ -367,7 +448,19 @@ module Cucumber
367
448
  expect( report.test_cases.total ).to eq 1
368
449
  expect( report.test_cases.total_passed ).to eq 1
369
450
  expect( report.test_cases.total_failed ).to eq 0
370
- expect( mappings.logger ).to eq [:before, :during, :middle, :during, :after]
451
+ expect( mappings.logger ).to eq [
452
+ :before_all,
453
+ :before,
454
+ :during,
455
+ :after_step,
456
+ :after,
457
+ :middle,
458
+ :before,
459
+ :during,
460
+ :after_step,
461
+ :after,
462
+ :after_all
463
+ ]
371
464
  end
372
465
  end
373
466
 
@@ -0,0 +1,24 @@
1
+ class ReportAPISpy
2
+ def initialize
3
+ @result = []
4
+ end
5
+
6
+ def test_case(*args)
7
+ @result << [:test_case, *args]
8
+ yield self if block_given?
9
+ end
10
+
11
+ def test_step(*args)
12
+ @result << [:test_step, *args]
13
+ yield self if block_given?
14
+ end
15
+
16
+ def done(*args)
17
+ @result << [:done, *args]
18
+ yield self if block_given?
19
+ end
20
+
21
+ def messages
22
+ @result.map(&:first)
23
+ end
24
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cucumber-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.0.beta.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aslak Hellesøy
@@ -12,90 +12,90 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2014-02-28 00:00:00.000000000 Z
15
+ date: 2014-08-22 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: gherkin
19
19
  requirement: !ruby/object:Gem::Requirement
20
20
  requirements:
21
- - - ~>
21
+ - - "~>"
22
22
  - !ruby/object:Gem::Version
23
23
  version: 2.12.0
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
27
27
  requirements:
28
- - - ~>
28
+ - - "~>"
29
29
  - !ruby/object:Gem::Version
30
30
  version: 2.12.0
31
31
  - !ruby/object:Gem::Dependency
32
32
  name: bundler
33
33
  requirement: !ruby/object:Gem::Requirement
34
34
  requirements:
35
- - - '>='
35
+ - - ">="
36
36
  - !ruby/object:Gem::Version
37
37
  version: 1.3.5
38
38
  type: :development
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
41
  requirements:
42
- - - '>='
42
+ - - ">="
43
43
  - !ruby/object:Gem::Version
44
44
  version: 1.3.5
45
45
  - !ruby/object:Gem::Dependency
46
46
  name: rake
47
47
  requirement: !ruby/object:Gem::Requirement
48
48
  requirements:
49
- - - '>='
49
+ - - ">="
50
50
  - !ruby/object:Gem::Version
51
51
  version: 0.9.2
52
52
  type: :development
53
53
  prerelease: false
54
54
  version_requirements: !ruby/object:Gem::Requirement
55
55
  requirements:
56
- - - '>='
56
+ - - ">="
57
57
  - !ruby/object:Gem::Version
58
58
  version: 0.9.2
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: rspec
61
61
  requirement: !ruby/object:Gem::Requirement
62
62
  requirements:
63
- - - '>='
63
+ - - "~>"
64
64
  - !ruby/object:Gem::Version
65
- version: '2.13'
65
+ version: '3'
66
66
  type: :development
67
67
  prerelease: false
68
68
  version_requirements: !ruby/object:Gem::Requirement
69
69
  requirements:
70
- - - '>='
70
+ - - "~>"
71
71
  - !ruby/object:Gem::Version
72
- version: '2.13'
72
+ version: '3'
73
73
  - !ruby/object:Gem::Dependency
74
74
  name: unindent
75
75
  requirement: !ruby/object:Gem::Requirement
76
76
  requirements:
77
- - - '>='
77
+ - - ">="
78
78
  - !ruby/object:Gem::Version
79
79
  version: '1.0'
80
80
  type: :development
81
81
  prerelease: false
82
82
  version_requirements: !ruby/object:Gem::Requirement
83
83
  requirements:
84
- - - '>='
84
+ - - ">="
85
85
  - !ruby/object:Gem::Version
86
86
  version: '1.0'
87
87
  - !ruby/object:Gem::Dependency
88
88
  name: coveralls
89
89
  requirement: !ruby/object:Gem::Requirement
90
90
  requirements:
91
- - - ~>
91
+ - - "~>"
92
92
  - !ruby/object:Gem::Version
93
93
  version: '0.7'
94
94
  type: :development
95
95
  prerelease: false
96
96
  version_requirements: !ruby/object:Gem::Requirement
97
97
  requirements:
98
- - - ~>
98
+ - - "~>"
99
99
  - !ruby/object:Gem::Version
100
100
  version: '0.7'
101
101
  description: Core library for the Cucumber BDD app
@@ -104,10 +104,10 @@ executables: []
104
104
  extensions: []
105
105
  extra_rdoc_files: []
106
106
  files:
107
- - .coveralls.yml
108
- - .rspec
109
- - .ruby-gemset
110
- - .travis.yml
107
+ - ".coveralls.yml"
108
+ - ".rspec"
109
+ - ".ruby-gemset"
110
+ - ".travis.yml"
111
111
  - Gemfile
112
112
  - LICENSE
113
113
  - README.md
@@ -141,8 +141,9 @@ files:
141
141
  - lib/cucumber/core/platform.rb
142
142
  - lib/cucumber/core/test/case.rb
143
143
  - lib/cucumber/core/test/filters.rb
144
+ - lib/cucumber/core/test/filters/debug_filter.rb
144
145
  - lib/cucumber/core/test/filters/tag_filter.rb
145
- - lib/cucumber/core/test/hook_compiler.rb
146
+ - lib/cucumber/core/test/hooks.rb
146
147
  - lib/cucumber/core/test/mapper.rb
147
148
  - lib/cucumber/core/test/mapping.rb
148
149
  - lib/cucumber/core/test/result.rb
@@ -163,7 +164,7 @@ files:
163
164
  - spec/cucumber/core/gherkin/parser_spec.rb
164
165
  - spec/cucumber/core/gherkin/writer_spec.rb
165
166
  - spec/cucumber/core/test/case_spec.rb
166
- - spec/cucumber/core/test/hook_compiler_spec.rb
167
+ - spec/cucumber/core/test/hooks_spec.rb
167
168
  - spec/cucumber/core/test/mapper_spec.rb
168
169
  - spec/cucumber/core/test/mapping_spec.rb
169
170
  - spec/cucumber/core/test/result_spec.rb
@@ -172,31 +173,32 @@ files:
172
173
  - spec/cucumber/core/test/timer_spec.rb
173
174
  - spec/cucumber/core_spec.rb
174
175
  - spec/cucumber/initializer_spec.rb
176
+ - spec/report_api_spy.rb
175
177
  homepage: http://cukes.info
176
178
  licenses:
177
179
  - MIT
178
180
  metadata: {}
179
181
  post_install_message:
180
182
  rdoc_options:
181
- - --charset=UTF-8
183
+ - "--charset=UTF-8"
182
184
  require_paths:
183
185
  - lib
184
186
  required_ruby_version: !ruby/object:Gem::Requirement
185
187
  requirements:
186
- - - '>='
188
+ - - ">="
187
189
  - !ruby/object:Gem::Version
188
190
  version: 1.9.3
189
191
  required_rubygems_version: !ruby/object:Gem::Requirement
190
192
  requirements:
191
- - - '>='
193
+ - - ">"
192
194
  - !ruby/object:Gem::Version
193
- version: '0'
195
+ version: 1.3.1
194
196
  requirements: []
195
197
  rubyforge_project:
196
198
  rubygems_version: 2.0.14
197
199
  signing_key:
198
200
  specification_version: 4
199
- summary: cucumber-core-0.2.0
201
+ summary: cucumber-core-1.0.0.beta.1
200
202
  test_files:
201
203
  - spec/capture_warnings.rb
202
204
  - spec/coverage.rb
@@ -210,7 +212,7 @@ test_files:
210
212
  - spec/cucumber/core/gherkin/parser_spec.rb
211
213
  - spec/cucumber/core/gherkin/writer_spec.rb
212
214
  - spec/cucumber/core/test/case_spec.rb
213
- - spec/cucumber/core/test/hook_compiler_spec.rb
215
+ - spec/cucumber/core/test/hooks_spec.rb
214
216
  - spec/cucumber/core/test/mapper_spec.rb
215
217
  - spec/cucumber/core/test/mapping_spec.rb
216
218
  - spec/cucumber/core/test/result_spec.rb
@@ -219,3 +221,5 @@ test_files:
219
221
  - spec/cucumber/core/test/timer_spec.rb
220
222
  - spec/cucumber/core_spec.rb
221
223
  - spec/cucumber/initializer_spec.rb
224
+ - spec/report_api_spy.rb
225
+ has_rdoc:
@@ -1,109 +0,0 @@
1
- require 'cucumber/initializer'
2
-
3
- module Cucumber
4
- module Core
5
- module Test
6
- class HookStep
7
- def initialize(source, &block)
8
- @mapping = Test::Mapping.new(&block)
9
- @source = source
10
- end
11
-
12
- def describe_to(visitor, *args)
13
- visitor.test_step(self, *args)
14
- end
15
-
16
- def describe_source_to(visitor, *args)
17
- visitor.hook(*args)
18
- end
19
-
20
- def execute
21
- @mapping.execute
22
- end
23
-
24
- def skip
25
- execute
26
- end
27
-
28
- def map
29
- self
30
- end
31
-
32
- def match_locations?(locations)
33
- false
34
- end
35
-
36
- def inspect
37
- "#{self.class}"
38
- end
39
- end
40
-
41
- class HookCompiler
42
- include Cucumber.initializer(:mappings, :receiver)
43
-
44
- def done
45
- receiver.done
46
- self
47
- end
48
-
49
- def test_case(test_case, &descend)
50
- @before_hooks, @after_hooks, @around_hooks, @steps = [], [], [], []
51
- mapper = HookMapper.new(self, test_case.source)
52
- test_case.describe_to mappings, mapper
53
- descend.call
54
- test_case.
55
- with_steps(@before_hooks + @steps + @after_hooks).
56
- with_around_hooks(@around_hooks).
57
- describe_to(receiver)
58
- end
59
-
60
- def before_hook(hook)
61
- @before_hooks << hook
62
- end
63
-
64
- def after_hook(hook)
65
- @after_hooks << hook
66
- end
67
-
68
- def around_hook(hook)
69
- @around_hooks << hook
70
- end
71
-
72
- def test_step(step)
73
- @steps << step
74
- end
75
-
76
- class HookMapper
77
- include Cucumber.initializer(:compiler, :source)
78
-
79
- def before(&block)
80
- compiler.before_hook HookStep.new(source, &block)
81
- end
82
-
83
- def after(&block)
84
- compiler.after_hook HookStep.new(source, &block)
85
- end
86
-
87
- def around(&block)
88
- compiler.around_hook AroundHook.new(source, &block)
89
- end
90
-
91
- class AroundHook
92
- def initialize(source, &block)
93
- @source = source
94
- @block = block
95
- end
96
-
97
- def call(continue)
98
- @block.call(continue)
99
- end
100
-
101
- def describe_to(visitor, *args, &continue)
102
- visitor.around_hook(self, *args, &continue)
103
- end
104
- end
105
- end
106
- end
107
- end
108
- end
109
- end