cucumber_factory 1.12.0 → 1.13.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- cucumber_factory (1.11.9)
4
+ cucumber_factory (1.13.0)
5
5
  activerecord
6
6
  activesupport
7
7
  cucumber
@@ -36,7 +36,7 @@ GEM
36
36
  cucumber-core (1.5.0)
37
37
  gherkin (~> 4.0)
38
38
  cucumber-wire (0.0.1)
39
- cucumber_priority (0.3.0)
39
+ cucumber_priority (0.3.1)
40
40
  cucumber
41
41
  database_cleaner (1.6.2)
42
42
  diff-lcs (1.3)
data/README.md CHANGED
@@ -39,6 +39,21 @@ Given there is a movie which is awesome, popular and successful but not science
39
39
  And there is a director with the income "500000" but with the account balance "-30000"
40
40
  ```
41
41
 
42
+ If you have many attribute assignments you can use doc string or data table:
43
+
44
+ ```cucumber
45
+ Given there is a movie with these attributes:
46
+ """
47
+ name: Sunshine
48
+ comedy: false
49
+ """
50
+ ```
51
+
52
+ ```cucumber
53
+ Given there is a movie with these attributes:
54
+ | name | Sunshine |
55
+ | comedy | false |
56
+ ```
42
57
 
43
58
  Setting associations
44
59
  --------------------
@@ -70,6 +85,22 @@ And there is a movie with the prequel "Before Sunrise"
70
85
 
71
86
  Note that in the example above, "Before Sunrise" is only a name you can use to refer to the record. The name is not actually used for the movie title, or any other attribute value.
72
87
 
88
+ It is not possible to define associations in doc string or data table, but you can combine them in one
89
+ step:
90
+
91
+ ```cucumber
92
+ Given there is a movie with the prequel above and these attributes:
93
+ """
94
+ name: Sunshine
95
+ comedy: false
96
+ """
97
+ ```
98
+
99
+ ```cucumber
100
+ Given there is a movie with the prequel above and these attributes:
101
+ | name | Sunshine |
102
+ | comedy | false |
103
+ ```
73
104
 
74
105
  Support for popular factory gems
75
106
  --------------------------------
@@ -134,12 +165,13 @@ There are tests in `spec`. We only accept PRs with tests. To run tests:
134
165
  - Create a local MySQL database `cucumber_factory_test`
135
166
  - Copy `spec/support/database.sample.yml` to `spec/support/database.yml` and enter your local credentials for the test databases
136
167
  - Install development dependencies using `bundle install`
137
- - Run tests using `bundle exec rspec`
168
+ - Run tests with the default symlinked Gemfile using `bundle exec rspec` or explicit with `BUNDLE_GEMFILE=gemfiles/Gemfile.cucumber-x.x bundle exec rspec spec`
138
169
 
139
170
  We recommend to test large changes against multiple versions of Ruby and multiple dependency sets. Supported combinations are configured in `.travis.yml`. We provide some rake tasks to help with this:
140
171
 
141
- - Install development dependencies using `bundle matrix:install`
142
- - Run tests using `bundle matrix:spec`
172
+ For each ruby version do (you need to change it manually):
173
+ - Install development dependencies using `rake matrix:install`
174
+ - Run tests using `rake matrix:spec`
143
175
 
144
176
  Note that we have configured Travis CI to automatically run tests in all supported Ruby versions and dependency sets after each push. We will only merge pull requests after a green Travis build.
145
177
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- cucumber_factory (1.11.9)
4
+ cucumber_factory (1.13.0)
5
5
  activerecord
6
6
  activesupport
7
7
  cucumber
@@ -20,7 +20,7 @@ GEM
20
20
  gherkin (~> 2.12)
21
21
  multi_json (>= 1.7.5, < 2.0)
22
22
  multi_test (>= 0.1.2)
23
- cucumber_priority (0.3.0)
23
+ cucumber_priority (0.3.1)
24
24
  cucumber
25
25
  database_cleaner (1.0.1)
26
26
  diff-lcs (1.2.5)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- cucumber_factory (1.11.9)
4
+ cucumber_factory (1.13.0)
5
5
  activerecord
6
6
  activesupport
7
7
  cucumber
@@ -36,7 +36,7 @@ GEM
36
36
  cucumber-core (1.5.0)
37
37
  gherkin (~> 4.0)
38
38
  cucumber-wire (0.0.1)
39
- cucumber_priority (0.3.0)
39
+ cucumber_priority (0.3.1)
40
40
  cucumber
41
41
  database_cleaner (1.6.2)
42
42
  diff-lcs (1.3)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- cucumber_factory (1.11.9)
4
+ cucumber_factory (1.13.0)
5
5
  activerecord
6
6
  activesupport
7
7
  cucumber
@@ -41,7 +41,7 @@ GEM
41
41
  cucumber-expressions (4.0.4)
42
42
  cucumber-tag_expressions (1.1.1)
43
43
  cucumber-wire (0.0.1)
44
- cucumber_priority (0.3.0)
44
+ cucumber_priority (0.3.1)
45
45
  cucumber
46
46
  database_cleaner (1.6.2)
47
47
  diff-lcs (1.3)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- cucumber_factory (1.11.9)
4
+ cucumber_factory (1.13.0)
5
5
  activerecord
6
6
  activesupport
7
7
  cucumber
@@ -41,7 +41,7 @@ GEM
41
41
  cucumber-expressions (5.0.13)
42
42
  cucumber-tag_expressions (1.1.1)
43
43
  cucumber-wire (0.0.1)
44
- cucumber_priority (0.3.0)
44
+ cucumber_priority (0.3.1)
45
45
  cucumber
46
46
  database_cleaner (1.6.2)
47
47
  diff-lcs (1.3)
@@ -4,6 +4,10 @@ module Cucumber
4
4
  class Factory
5
5
 
6
6
  ATTRIBUTES_PATTERN = '( with the .+?)?( (?:which|who|that) is .+?)?'
7
+ TEXT_ATTRIBUTES_PATTERN = ' (?:with|and) these attributes:'
8
+
9
+ RECORD_PATTERN = 'there is an? (.+?)( \(.+?\))?'
10
+ NAMED_RECORD_PATTERN = '"([^\"]*)" is an? (.+?)( \(.+?\))?'
7
11
 
8
12
  NAMED_RECORDS_VARIABLE = :'@named_cucumber_factory_records'
9
13
 
@@ -12,25 +16,43 @@ module Cucumber
12
16
  :block => proc { Cucumber::Factory.send(:reset_named_records, self) }
13
17
  }
14
18
 
19
+ # We cannot use vararg blocks in the descriptors in Ruby 1.8, as explained by
20
+ # Aslak: http://www.ruby-forum.com/topic/182927. We use different descriptors and cucumber priority to work around
21
+ # it.
22
+
15
23
  NAMED_CREATION_STEP_DESCRIPTOR = {
16
24
  :kind => :Given,
17
- :pattern => /^"([^\"]*)" is an? (.+?)( \(.+?\))?#{ATTRIBUTES_PATTERN}?$/,
18
- # we cannot use vararg blocks here in Ruby 1.8, as explained by Aslak: http://www.ruby-forum.com/topic/182927
25
+ :pattern => /^#{NAMED_RECORD_PATTERN}#{ATTRIBUTES_PATTERN}?$/,
19
26
  :block => lambda { |a1, a2, a3, a4, a5| Cucumber::Factory.send(:parse_named_creation, self, a1, a2, a3, a4, a5) }
20
27
  }
21
28
 
22
29
  CREATION_STEP_DESCRIPTOR = {
23
30
  :kind => :Given,
24
- :pattern => /^there is an? (.+?)( \(.+?\))?#{ATTRIBUTES_PATTERN}$/,
25
- # we cannot use vararg blocks here in Ruby 1.8, as explained by Aslak: http://www.ruby-forum.com/topic/182927
31
+ :pattern => /^#{RECORD_PATTERN}#{ATTRIBUTES_PATTERN}$/,
26
32
  :block => lambda { |a1, a2, a3, a4| Cucumber::Factory.send(:parse_creation, self, a1, a2, a3, a4) }
27
33
  }
28
34
 
35
+ NAMED_CREATION_STEP_DESCRIPTOR_WITH_TEXT_ATTRIBUTES = {
36
+ :kind => :Given,
37
+ :pattern => /^"#{NAMED_RECORD_PATTERN}#{ATTRIBUTES_PATTERN}#{TEXT_ATTRIBUTES_PATTERN}?$/,
38
+ :block => lambda { |a1, a2, a3, a4, a5, a6| Cucumber::Factory.send(:parse_named_creation, self, a1, a2, a3, a4, a5, a6) },
39
+ :priority => true
40
+ }
41
+
42
+ CREATION_STEP_DESCRIPTOR_WITH_TEXT_ATTRIBUTES = {
43
+ :kind => :Given,
44
+ :pattern => /^#{RECORD_PATTERN}#{ATTRIBUTES_PATTERN}#{TEXT_ATTRIBUTES_PATTERN}$/,
45
+ :block => lambda { |a1, a2, a3, a4, a5| Cucumber::Factory.send(:parse_creation, self, a1, a2, a3, a4, a5) },
46
+ :priority => true
47
+ }
48
+
29
49
  class << self
30
50
 
31
51
  def add_steps(main)
32
52
  add_step(main, CREATION_STEP_DESCRIPTOR)
33
53
  add_step(main, NAMED_CREATION_STEP_DESCRIPTOR)
54
+ add_step(main, CREATION_STEP_DESCRIPTOR_WITH_TEXT_ATTRIBUTES)
55
+ add_step(main, NAMED_CREATION_STEP_DESCRIPTOR_WITH_TEXT_ATTRIBUTES)
34
56
  add_step(main, CLEAR_NAMED_RECORDS_STEP_DESCRIPTOR)
35
57
  end
36
58
 
@@ -40,7 +62,7 @@ module Cucumber
40
62
  main.instance_eval {
41
63
  kind = descriptor[:kind]
42
64
  object = send(kind, *[descriptor[:pattern]].compact, &descriptor[:block])
43
- object.overridable if kind != :Before
65
+ object.overridable(:priority => descriptor[:priority] ? 1 : 0) if kind != :Before
44
66
  object
45
67
  }
46
68
  end
@@ -64,12 +86,12 @@ module Cucumber
64
86
  named_records(world)[name] = record
65
87
  end
66
88
 
67
- def parse_named_creation(world, name, raw_model, raw_variant, raw_attributes, raw_boolean_attributes)
68
- record = parse_creation(world, raw_model, raw_variant, raw_attributes, raw_boolean_attributes)
89
+ def parse_named_creation(world, name, raw_model, raw_variant, raw_attributes, raw_boolean_attributes, raw_multiline_attributes = nil)
90
+ record = parse_creation(world, raw_model, raw_variant, raw_attributes, raw_boolean_attributes, raw_multiline_attributes)
69
91
  set_named_record(world, name, record)
70
92
  end
71
93
 
72
- def parse_creation(world, raw_model, raw_variant, raw_attributes, raw_boolean_attributes)
94
+ def parse_creation(world, raw_model, raw_variant, raw_attributes, raw_boolean_attributes, raw_multiline_attributes = nil)
73
95
  build_strategy = BuildStrategy.from_prose(raw_model, raw_variant)
74
96
  model_class = build_strategy.model_class
75
97
  attributes = {}
@@ -88,6 +110,22 @@ module Cucumber
88
110
  attributes[attribute] = flag
89
111
  end
90
112
  end
113
+ if raw_multiline_attributes.present?
114
+ # DocString e.g. "first name: Jane\nlast name: Jenny\n"
115
+ if raw_multiline_attributes.is_a?(String)
116
+ raw_multiline_attributes.split("\n").each do |fragment|
117
+ raw_attribute, value = fragment.split(': ')
118
+ attribute = attribute_name_from_prose(raw_attribute)
119
+ attributes[attribute] = value
120
+ end
121
+ # DataTable e.g. in raw [["first name", "Jane"], ["last name", "Jenny"]]
122
+ else
123
+ raw_multiline_attributes.raw.each do |raw_attribute, value|
124
+ attribute = attribute_name_from_prose(raw_attribute)
125
+ attributes[attribute] = value
126
+ end
127
+ end
128
+ end
91
129
  record = build_strategy.create_record(attributes)
92
130
  remember_record_names(world, record, attributes)
93
131
  record
@@ -1,3 +1,3 @@
1
1
  module CucumberFactory
2
- VERSION = '1.12.0'
2
+ VERSION = '1.13.0'
3
3
  end
@@ -294,4 +294,54 @@ describe 'steps provided by cucumber_factory' do
294
294
  invoke_cucumber_step('there is a plain ruby class with the butt "pear-shaped"')
295
295
  end
296
296
 
297
+ it "should allow to set attributes via doc string" do
298
+ user = User.new
299
+ User.stub(:new => user)
300
+
301
+ invoke_cucumber_step('there is a user with these attributes:', <<-DOC_STRING)
302
+ name: Jane
303
+ locked: true
304
+ DOC_STRING
305
+
306
+ user.name.should == "Jane"
307
+ user.locked.should == true
308
+ end
309
+
310
+ it "should allow to set attributes via additional doc string" do
311
+ user = User.new
312
+ User.stub(:new => user)
313
+
314
+ invoke_cucumber_step('there is a user with the email "test@invalid.com" and these attributes:', <<-DOC_STRING)
315
+ name: Jane
316
+ DOC_STRING
317
+
318
+ user.name.should == "Jane"
319
+ user.email.should == "test@invalid.com"
320
+ end
321
+
322
+ it "should allow to set attributes via data table" do
323
+ user = User.new
324
+ User.stub(:new => user)
325
+
326
+ invoke_cucumber_step('there is a user with these attributes:', nil, <<-DATA_TABLE)
327
+ | name | Jane |
328
+ | locked | true |
329
+ DATA_TABLE
330
+
331
+ user.name.should == "Jane"
332
+ user.locked.should == true
333
+ end
334
+
335
+ it "should allow to set attributes via additional data table" do
336
+ user = User.new
337
+ User.stub(:new => user)
338
+
339
+ invoke_cucumber_step('there is a user with the email "test@invalid.com" and these attributes:', nil, <<-DATA_TABLE)
340
+ | name | Jane |
341
+ DATA_TABLE
342
+
343
+ user.name.should == "Jane"
344
+ user.email.should == "test@invalid.com"
345
+ end
346
+
297
347
  end
@@ -20,13 +20,30 @@ def prepare_cucumber_example
20
20
  Cucumber::Factory.add_steps(@main)
21
21
  end
22
22
 
23
- def invoke_cucumber_step(step)
24
- multiline_argument = begin
25
- Cucumber::MultilineArgument::None.new # Cucumber 2+
26
- rescue NameError
27
- nil # Cucumber 1
23
+ def invoke_cucumber_step(step, doc_string = nil, data_table = nil)
24
+ if Cucumber::VERSION >= '2'
25
+ multiline_argument = Cucumber::MultilineArgument::None.new
26
+
27
+ if doc_string.present?
28
+ multiline_argument = Cucumber::MultilineArgument::DocString.new(doc_string)
29
+ end
30
+
31
+ if data_table.present?
32
+ multiline_argument = Cucumber::MultilineArgument::DataTable.from(data_table)
33
+ end
34
+ else
35
+ multiline_argument = nil
36
+
37
+ if doc_string.present?
38
+ multiline_argument = Cucumber::Ast::DocString.new(doc_string, '')
39
+ end
40
+
41
+ if data_table.present?
42
+ multiline_argument = Cucumber::Ast::Table.parse(data_table, nil, nil)
43
+ end
28
44
  end
29
- first_step_match(step).invoke(multiline_argument) # nil means no multiline args
45
+
46
+ first_step_match(step).invoke(multiline_argument)
30
47
  end
31
48
 
32
49
  def support_code
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cucumber_factory
3
3
  version: !ruby/object:Gem::Version
4
- hash: 39
4
+ hash: 35
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 12
8
+ - 13
9
9
  - 0
10
- version: 1.12.0
10
+ version: 1.13.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Henning Koch
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2018-02-28 00:00:00 Z
18
+ date: 2018-04-26 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: cucumber