cucumber-core 1.0.0.beta.4 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -0
  3. data/CONTRIBUTING.md +14 -0
  4. data/HISTORY.md +14 -1
  5. data/README.md +34 -33
  6. data/lib/cucumber/core.rb +3 -5
  7. data/lib/cucumber/core/ast/background.rb +13 -2
  8. data/lib/cucumber/core/ast/comment.rb +8 -2
  9. data/lib/cucumber/core/ast/examples_table.rb +14 -5
  10. data/lib/cucumber/core/ast/feature.rb +15 -6
  11. data/lib/cucumber/core/ast/scenario.rb +17 -4
  12. data/lib/cucumber/core/ast/scenario_outline.rb +20 -8
  13. data/lib/cucumber/core/ast/tag.rb +5 -3
  14. data/lib/cucumber/core/compiler.rb +39 -7
  15. data/lib/cucumber/core/filter.rb +83 -0
  16. data/lib/cucumber/core/gherkin/ast_builder.rb +7 -2
  17. data/lib/cucumber/core/gherkin/document.rb +5 -2
  18. data/lib/cucumber/core/gherkin/parser.rb +6 -1
  19. data/lib/cucumber/core/test/action.rb +8 -8
  20. data/lib/cucumber/core/test/around_hook.rb +19 -0
  21. data/lib/cucumber/core/test/case.rb +6 -4
  22. data/lib/cucumber/core/test/filters/locations_filter.rb +3 -6
  23. data/lib/cucumber/core/test/filters/name_filter.rb +3 -7
  24. data/lib/cucumber/core/test/filters/tag_filter.rb +4 -2
  25. data/lib/cucumber/core/test/result.rb +5 -7
  26. data/lib/cucumber/core/test/runner.rb +39 -40
  27. data/lib/cucumber/core/test/step.rb +7 -10
  28. data/lib/cucumber/core/version.rb +1 -1
  29. data/spec/capture_warnings.rb +5 -0
  30. data/spec/cucumber/core/filter_spec.rb +100 -0
  31. data/spec/cucumber/core/gherkin/parser_spec.rb +0 -1
  32. data/spec/cucumber/core/test/action_spec.rb +29 -31
  33. data/spec/cucumber/core/test/runner_spec.rb +5 -5
  34. data/spec/cucumber/core/test/step_spec.rb +18 -9
  35. data/spec/cucumber/core_spec.rb +40 -172
  36. metadata +11 -16
  37. data/lib/cucumber/core/test/hooks.rb +0 -93
  38. data/lib/cucumber/core/test/mapper.rb +0 -150
  39. data/lib/cucumber/initializer.rb +0 -18
  40. data/spec/cucumber/core/test/hooks_spec.rb +0 -30
  41. data/spec/cucumber/core/test/mapper_spec.rb +0 -203
  42. data/spec/cucumber/initializer_spec.rb +0 -49
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 92d80d8c2127d6475aef16ab947d0bb6123cb65d
4
- data.tar.gz: 17c84ce6fef0048f020350837ea4ce963a2983d8
3
+ metadata.gz: f2cd168ae1424fa32f265677b4a2dfc7ae18a94d
4
+ data.tar.gz: ebbf8b1933b4bb5e7cc16bce682ee62c5887a19c
5
5
  SHA512:
6
- metadata.gz: 1bd15d9ca8acc459edfe0be347c0de3e4e3a6fc60dbec47f03e3c71824ba71a08dd707c7363a98e55a1d1ea0fea3b43d519a9daf598fc81120061fb28d6d5179
7
- data.tar.gz: 3dc08914e80026d9eedc136b4d47f0efda584ebc2094213aebcb06c6886df6cd6091f1da7458b7c6f27e5f706cd1f6f3b628736997c3d6059324ef289f293cc4
6
+ metadata.gz: 2ed2fa52877d2ddae9912e9a4db6c2c019bebd424709b759997826ef7d5e061d01a5a31c8f37829b33dc8ba32b9969b6003fc3d65eeaa5403af9845424fb613d
7
+ data.tar.gz: c63b934c43c8e8e57869d8f52db24f4e1dd6fa6352c1a1e69569a290eb70f6a71f8a3ac37da0b7b7b208996e32b621f26698c1fda2470e763a7f4e5eab40bad6
data/.travis.yml CHANGED
@@ -1,4 +1,5 @@
1
1
  rvm:
2
+ - 2.2
2
3
  - 2.1
3
4
  - 2.0.0
4
5
  - 1.9.3
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,14 @@
1
+ Release Process
2
+ ===============
3
+
4
+ * Bump the version number in `lib/cucumber/core/version.rb`
5
+ * Update `HISTORY.md` is updated with the upcoming version number and entries
6
+ for all changes recorded.
7
+ * Now release it
8
+
9
+ ```
10
+ bundle update
11
+ bundle exec rake
12
+ git commit -m "Release X.Y.Z"
13
+ rake release
14
+ ```
data/HISTORY.md CHANGED
@@ -1,4 +1,17 @@
1
- ## [In Git](https://github.com/cucumber/cucumber-ruby-core/compare/v1.0.0.beta.3...master)
1
+ ## [In Git](https://github.com/cucumber/cucumber-ruby-core/compare/v1.0.0...master)
2
+
3
+ ## [v1.0.0](https://github.com/cucumber/cucumber-ruby-core/compare/v1.0.0.beta.4...v1.0.0)
4
+
5
+ ### Features Removed
6
+
7
+ * Removed the Mapper DSL (@mattwynne, @tooky)
8
+ * Removed Cucumber.initializer (@tooky)
9
+
10
+ ### New Features
11
+
12
+ * Added dynamic filter class constructor (@mattwynne)
13
+
14
+ ## [v1.0.0.beta.4](https://github.com/cucumber/cucumber-ruby-core/compare/v1.0.0.beta.3...v1.0.0.beta.4)
2
15
 
3
16
  ### New Features
4
17
 
data/README.md CHANGED
@@ -15,9 +15,8 @@ The entry-point is a single method on the module `Cucumber::Core` called [`#exec
15
15
 
16
16
  1. Parses the plain-text Gherkin documents into an **AST**
17
17
  2. Compiles the AST down to **test cases**
18
- 3. Passes the test cases through your **mappings** to activate them
19
- 4. Passes the activated test cases through any **filters**
20
- 5. Executes the test cases, calling back to the **report**
18
+ 3. Passes the activated test cases through any **filters**
19
+ 4. Executes the test cases, calling back to the **report**
21
20
 
22
21
  We've introduced a number of concepts here, so let's go through them in detail.
23
22
 
@@ -31,19 +30,13 @@ These are immutable value objects.
31
30
 
32
31
  Your gherkin might contain scenarios, as well as examples from tables beneath a scenario outline.
33
32
 
34
- Test cases represent the general case of both of these. We compile the AST down to instances of [`Cucumber::Core::Test::Case`](http://rubydoc.info/gems/cucumber-core/Cucumber/Core/Test/Case), each containing a number of instances of [`Cucumber::Core::Test::Step`](http://rubydoc.info/gems/cucumber-core/Cucumber/Core/Test/Step). It's these that are then mapped, filtered, and executed.
33
+ Test cases represent the general case of both of these. We compile the AST down to instances of [`Cucumber::Core::Test::Case`](http://rubydoc.info/gems/cucumber-core/Cucumber/Core/Test/Case), each containing a number of instances of [`Cucumber::Core::Test::Step`](http://rubydoc.info/gems/cucumber-core/Cucumber/Core/Test/Step). It's these that are then filtered and executed.
35
34
 
36
35
  Test cases and their test steps are also immutable value objects.
37
36
 
38
- ### Mappings
39
-
40
- When test cases are first compiled from the AST, they contain no information about how to execute them. Mappings are how we connect them to the code they need to run in order to execute your tests.
41
-
42
37
  ### Filters
43
38
 
44
- Once we have the test cases, and they've been activated by the mappings, you may want to pass them through a filter or two. Filters can be used to do things like sort, replace or remove some of the test cases or their steps before they're executed.
45
-
46
- In fact, the mappings are just a special case of a filter.
39
+ Once we have the test cases, and they've been activated by the mappings, you may want to pass them through a filter or two. Filters can be used to do things like activate, sort, replace or remove some of the test cases or their steps before they're executed.
47
40
 
48
41
  ### Report
49
42
 
@@ -65,42 +58,50 @@ Here's an example of how you might use [`Cucumber::Core#execute`](http://rubydoc
65
58
 
66
59
  ```ruby
67
60
  require 'cucumber/core'
61
+ require 'cucumber/core/filter'
68
62
 
69
63
  class MyRunner
70
64
  include Cucumber::Core
65
+ end
71
66
 
72
- def run(features)
73
- execute features, Mappings.new, Report.new
74
- end
75
-
76
- class Mappings
77
- def test_case(test_case, mapper)
67
+ class ActivateSteps < Cucumber::Core::Filter.new
68
+ def test_case(test_case)
69
+ test_steps = test_case.test_steps.map do |step|
70
+ activate(step)
78
71
  end
79
72
 
80
- def test_step(test_step, mapper)
81
- mapper.map { fail } if test_step.name =~ /fail/
82
- mapper.map { } if test_step.name =~ /pass/
83
- end
73
+ test_case.with_steps(test_steps).describe_to(receiver)
84
74
  end
85
75
 
86
- class Report
87
- def before_test_step(test_step)
76
+ private
77
+ def activate(step)
78
+ case step.name
79
+ when /fail/
80
+ step.with_action { raise Failure }
81
+ when /pass/
82
+ step.with_action {}
83
+ else
84
+ step
88
85
  end
86
+ end
87
+ end
89
88
 
90
- def after_test_step(test_step, result)
91
- puts "#{test_step.name} #{result}"
92
- end
89
+ class Report
90
+ def before_test_step(test_step)
91
+ end
93
92
 
94
- def before_test_case(test_case)
95
- end
93
+ def after_test_step(test_step, result)
94
+ puts "#{test_step.name} #{result}"
95
+ end
96
96
 
97
- def after_test_case(test_case, result)
98
- end
97
+ def before_test_case(test_case)
98
+ end
99
99
 
100
- def done
101
- end
100
+ def after_test_case(test_case, result)
102
101
  end
103
102
 
103
+ def done
104
+ end
104
105
  end
105
106
 
106
107
  feature = Cucumber::Core::Gherkin::Document.new(__FILE__, <<-GHERKIN)
@@ -111,7 +112,7 @@ Feature:
111
112
  And undefined
112
113
  GHERKIN
113
114
 
114
- MyRunner.new.run([feature])
115
+ MyRunner.new.execute([feature], Report.new, [ActivateSteps.new])
115
116
  ```
116
117
 
117
118
  If you run this little Ruby script, you should see the following output:
data/lib/cucumber/core.rb CHANGED
@@ -2,14 +2,12 @@ require 'cucumber/core/gherkin/parser'
2
2
  require 'cucumber/core/gherkin/document'
3
3
  require 'cucumber/core/compiler'
4
4
  require 'cucumber/core/test/runner'
5
- require 'cucumber/core/test/mapper'
6
5
 
7
6
  module Cucumber
8
7
  module Core
9
8
 
10
- def execute(gherkin_documents, mapping_definition, report, filters = [])
9
+ def execute(gherkin_documents, report, filters = [])
11
10
  receiver = Test::Runner.new(report)
12
- filters << [Test::Mapper, [mapping_definition]]
13
11
  compile gherkin_documents, receiver, filters
14
12
  self
15
13
  end
@@ -33,8 +31,8 @@ module Cucumber
33
31
  end
34
32
 
35
33
  def compose(filters, last_receiver)
36
- filters.reverse.reduce(last_receiver) do |receiver, (filter_type, args)|
37
- filter_type.new(*args + [receiver])
34
+ filters.reverse.reduce(last_receiver) do |receiver, filter|
35
+ filter.with_receiver(receiver)
38
36
  end
39
37
  end
40
38
 
@@ -1,4 +1,3 @@
1
- require 'cucumber/initializer'
2
1
  require 'cucumber/core/ast/names'
3
2
  require 'cucumber/core/ast/location'
4
3
  require 'cucumber/core/ast/describes_itself'
@@ -11,7 +10,19 @@ module Cucumber
11
10
  include HasLocation
12
11
  include DescribesItself
13
12
 
14
- include Cucumber.initializer(:gherkin_statement, :language, :location, :comments, :keyword, :title, :description, :raw_steps)
13
+ def initialize(gherkin_statement, language, location, comments, keyword, title, description, raw_steps)
14
+ @gherkin_statement = gherkin_statement
15
+ @language = language
16
+ @location = location
17
+ @comments = comments
18
+ @keyword = keyword
19
+ @title = title
20
+ @description = description
21
+ @raw_steps = raw_steps
22
+ end
23
+
24
+ attr_reader :language, :title, :description, :raw_steps
25
+ private :language, :title, :description, :raw_steps
15
26
 
16
27
  attr_accessor :feature
17
28
  attr_accessor :comments, :keyword, :location
@@ -1,4 +1,3 @@
1
- require 'cucumber/initializer'
2
1
  require 'cucumber/core/ast/location'
3
2
 
4
3
  module Cucumber
@@ -6,7 +5,14 @@ module Cucumber
6
5
  module Ast
7
6
  class Comment
8
7
  include HasLocation
9
- include Cucumber.initializer :location, :value
8
+
9
+ attr_reader :location, :value
10
+ private :location, :value
11
+
12
+ def initialize(location, value)
13
+ @location = location
14
+ @value = value
15
+ end
10
16
 
11
17
  def to_s
12
18
  value
@@ -1,4 +1,3 @@
1
- require 'cucumber/initializer'
2
1
  require 'cucumber/core/ast/describes_itself'
3
2
  require 'cucumber/core/ast/location'
4
3
  require 'cucumber/core/ast/names'
@@ -12,11 +11,21 @@ module Cucumber
12
11
  include HasLocation
13
12
  include DescribesItself
14
13
 
15
- attr_reader :header, :keyword, :tags, :comments, :location, :gherkin_statement
14
+ def initialize(gherkin_statement, location, comments, tags, keyword, title, description, header, example_rows)
15
+ @gherkin_statement = gherkin_statement
16
+ @location = location
17
+ @comments = comments
18
+ @tags = tags
19
+ @keyword = keyword
20
+ @title = title
21
+ @description = description
22
+ @header = header
23
+ @example_rows = example_rows
24
+ end
16
25
 
17
- include Cucumber.initializer(
18
- :gherkin_statement, :location, :comments, :tags, :keyword, :title, :description, :header, :example_rows
19
- )
26
+ attr_reader :gherkin_statement, :location, :comments, :tags, :keyword,
27
+ :title, :description, :header, :example_rows
28
+ private :title, :description, :example_rows
20
29
 
21
30
  private
22
31
 
@@ -1,4 +1,3 @@
1
- require 'cucumber/initializer'
2
1
  require 'cucumber/core/ast/describes_itself'
3
2
  require 'cucumber/core/ast/names'
4
3
  require 'cucumber/core/ast/location'
@@ -12,12 +11,22 @@ module Cucumber
12
11
  include HasLocation
13
12
  include DescribesItself
14
13
 
15
- attr_reader :feature_elements, :language
16
- attr_reader :comments, :background, :tags, :keyword, :location, :title, :gherkin_statement
14
+ attr_reader :gherkin_statement, :language, :location, :background,
15
+ :comments, :tags, :keyword, :title, :description,
16
+ :feature_elements
17
+ private :description
17
18
 
18
- include Cucumber.initializer(:gherkin_statement, :language, :location, :background, :comments, :tags, :keyword, :title, :description, :feature_elements)
19
- def initialize(*)
20
- super
19
+ def initialize(gherkin_statement, language, location, background, comments, tags, keyword, title, description, feature_elements)
20
+ @gherkin_statement = gherkin_statement
21
+ @language = language
22
+ @location = location
23
+ @background = background
24
+ @comments = comments
25
+ @tags = tags
26
+ @keyword = keyword
27
+ @title = title
28
+ @description = description
29
+ @feature_elements = feature_elements
21
30
  end
22
31
 
23
32
  def children
@@ -1,4 +1,3 @@
1
- require 'cucumber/initializer'
2
1
  require 'cucumber/core/ast/describes_itself'
3
2
  require 'cucumber/core/ast/names'
4
3
  require 'cucumber/core/ast/empty_background'
@@ -12,10 +11,24 @@ module Cucumber
12
11
  include HasLocation
13
12
  include DescribesItself
14
13
 
15
- attr_reader :feature_tags
16
- attr_reader :comments, :tags, :keyword, :background, :title, :location, :gherkin_statement
14
+ attr_reader :gherkin_statement, :language, :location, :background,
15
+ :comments, :tags, :feature_tags, :keyword, :title,
16
+ :description, :raw_steps
17
+ private :raw_steps, :description
17
18
 
18
- include Cucumber.initializer(:gherkin_statement, :language, :location, :background, :comments, :tags, :feature_tags, :keyword, :title, :description, :raw_steps)
19
+ def initialize(gherkin_statement, language, location, background, comments, tags, feature_tags, keyword, title, description, raw_steps)
20
+ @gherkin_statement = gherkin_statement
21
+ @language = language
22
+ @location = location
23
+ @background = background
24
+ @comments = comments
25
+ @tags = tags
26
+ @feature_tags = feature_tags
27
+ @keyword = keyword
28
+ @title = title
29
+ @description = description
30
+ @raw_steps = raw_steps
31
+ end
19
32
 
20
33
  def children
21
34
  raw_steps
@@ -13,14 +13,26 @@ module Cucumber
13
13
 
14
14
  MissingExamples = Class.new(StandardError)
15
15
 
16
- attr_reader :feature_tags
17
-
18
- attr_reader :line
19
- private :line
20
-
21
- include Cucumber.initializer(:gherkin_statement, :language, :location, :background, :comments, :tags, :feature_tags, :keyword, :title, :description, :steps, :examples_tables)
22
-
23
- attr_reader :comments, :tags, :keyword, :background, :location, :gherkin_statement
16
+ attr_reader :gherkin_statement, :language, :background, :comments,
17
+ :tags, :feature_tags, :keyword, :title, :description,
18
+ :steps, :examples_tables, :line
19
+ private :language, :background, :comments, :feature_tags,
20
+ :line
21
+
22
+ def initialize(gherkin_statement, language, location, background, comments, tags, feature_tags, keyword, title, description, steps, examples_tables)
23
+ @gherkin_statement = gherkin_statement
24
+ @language = language
25
+ @location = location
26
+ @background = background
27
+ @comments = comments
28
+ @tags = tags
29
+ @feature_tags = feature_tags
30
+ @keyword = keyword
31
+ @title = title
32
+ @description = description
33
+ @steps = steps
34
+ @examples_tables = examples_tables
35
+ end
24
36
 
25
37
  private
26
38
 
@@ -1,13 +1,15 @@
1
- require 'cucumber/initializer'
2
1
  module Cucumber
3
2
  module Core
4
3
  module Ast
5
4
  class Tag
6
5
  include HasLocation
7
6
 
8
- include Cucumber.initializer(:location, :name)
9
-
10
7
  attr_reader :name
8
+
9
+ def initialize(location, name)
10
+ @location = location
11
+ @name = name
12
+ end
11
13
  end
12
14
  end
13
15
  end
@@ -1,4 +1,3 @@
1
- require 'cucumber/initializer'
2
1
  require 'cucumber/core/test/case'
3
2
  require 'cucumber/core/test/step'
4
3
 
@@ -7,7 +6,12 @@ module Cucumber
7
6
 
8
7
  # Compiles the AST into test cases
9
8
  class Compiler
10
- include Cucumber.initializer(:receiver)
9
+ attr_reader :receiver
10
+ private :receiver
11
+
12
+ def initialize(receiver)
13
+ @receiver = receiver
14
+ end
11
15
 
12
16
  def feature(feature)
13
17
  compiler = FeatureCompiler.new(TestCaseBuilder.new(receiver))
@@ -22,7 +26,12 @@ module Cucumber
22
26
 
23
27
  # @private
24
28
  class TestCaseBuilder
25
- include Cucumber.initializer(:receiver)
29
+ attr_reader :receiver
30
+ private :receiver
31
+
32
+ def initialize(receiver)
33
+ @receiver = receiver
34
+ end
26
35
 
27
36
  def on_background_step(source)
28
37
  background_test_steps << Test::Step.new(source)
@@ -53,7 +62,12 @@ module Cucumber
53
62
 
54
63
  # @private
55
64
  class FeatureCompiler
56
- include Cucumber.initializer(:receiver)
65
+ attr_reader :receiver
66
+ private :receiver
67
+
68
+ def initialize(receiver)
69
+ @receiver = receiver
70
+ end
57
71
 
58
72
  def feature(feature, &descend)
59
73
  @feature = feature
@@ -86,7 +100,13 @@ module Cucumber
86
100
 
87
101
  # @private
88
102
  class ScenarioOutlineCompiler
89
- include Cucumber.initializer(:source, :receiver)
103
+ attr_reader :source, :receiver
104
+ private :source, :receiver
105
+
106
+ def initialize(source, receiver)
107
+ @source = source
108
+ @receiver = receiver
109
+ end
90
110
 
91
111
  def outline_step(outline_step)
92
112
  outline_steps << outline_step
@@ -120,7 +140,13 @@ module Cucumber
120
140
 
121
141
  # @private
122
142
  class ScenarioCompiler
123
- include Cucumber.initializer(:source, :receiver)
143
+ attr_reader :source, :receiver
144
+ private :source, :receiver
145
+
146
+ def initialize(source, receiver)
147
+ @source = source
148
+ @receiver = receiver
149
+ end
124
150
 
125
151
  def step(step)
126
152
  receiver.on_step(source + [step])
@@ -130,7 +156,13 @@ module Cucumber
130
156
 
131
157
  # @private
132
158
  class BackgroundCompiler
133
- include Cucumber.initializer(:source, :receiver)
159
+ attr_reader :source, :receiver
160
+ private :source, :receiver
161
+
162
+ def initialize(source, receiver)
163
+ @source = source
164
+ @receiver = receiver
165
+ end
134
166
 
135
167
  def step(step)
136
168
  receiver.on_background_step(source + [step])