cucumber_factory 1.14.2 → 1.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fdeea41c773feb6d2c05b8166797af8a6793393937c525e68a43973d4d26f5eb
4
- data.tar.gz: 39dd9632417d2181dc873a262a93305bc75ead63e0ac244b1851865c477ee99e
3
+ metadata.gz: c9be7d49c33814f02f79d18b4a92eb3f5af05de9bd8b8b0a38305e2113763e0c
4
+ data.tar.gz: a446cbe7440b4fb9f0841133dd655d1fd332e2eace463297d484fa40d5849ffd
5
5
  SHA512:
6
- metadata.gz: b8c7851c81677ddbce263a03b5e7cdca73d57611198c084168f7fda3c5f24ebd489fdead26b02a3086385919fc979735932ef1062b4e196ebd305a64b43dbc7b
7
- data.tar.gz: 548ac3a75c7c7c1db66e43f4ebae7c140de13215bc9a5f0bf6795ebcd059be28fba1bd820d5fe078162afbd61fbdb21d6621b7b5186ec507f45ce01371216f43
6
+ metadata.gz: 2bb70ead6e5bcb857d6c887ae4b5ec5a1f0b95f93d550c1e90a45c97c2a88f16733f4abf47fa5ded2242400c2e97e40d2a6c70835439b2b273ed290831af236e
7
+ data.tar.gz: c5dc17e7f963b9a7c5a0e6d1e128bc5024a5e547737e4f1148e60ee47b3dbf48d7a7db5422e5481ddaae0558092cd7faaa957ea370de233bfc5bff7f94904087
@@ -4,32 +4,31 @@ rvm:
4
4
  - 2.5.3
5
5
 
6
6
  gemfile:
7
- - gemfiles/Gemfile.cucumber-1.3
8
- - gemfiles/Gemfile.cucumber-2.4
9
- - gemfiles/Gemfile.cucumber-3.0
10
- - gemfiles/Gemfile.cucumber-3.1
7
+ - Gemfile.cucumber-1.3
8
+ - Gemfile.cucumber-2.4
9
+ - Gemfile.cucumber-3.0
10
+ - Gemfile.cucumber-3.1
11
11
 
12
12
  matrix:
13
13
  exclude:
14
- - gemfile: gemfiles/Gemfile.cucumber-3.1
14
+ - gemfile: Gemfile.cucumber-3.1
15
15
  rvm: 1.8.7
16
- - gemfile: gemfiles/Gemfile.cucumber-3.1
16
+ - gemfile: Gemfile.cucumber-3.1
17
17
  rvm: 2.1.10 # cucumber 3 wants ruby >= 2.2
18
- - gemfile: gemfiles/Gemfile.cucumber-3.0
18
+ - gemfile: Gemfile.cucumber-3.0
19
19
  rvm: 1.8.7
20
- - gemfile: gemfiles/Gemfile.cucumber-3.0
20
+ - gemfile: Gemfile.cucumber-3.0
21
21
  rvm: 2.1.10 # cucumber 3 wants ruby >= 2.2
22
- - gemfile: gemfiles/Gemfile.cucumber-2.4
22
+ - gemfile: Gemfile.cucumber-2.4
23
23
  rvm: 1.8.7
24
- - gemfile: gemfiles/Gemfile.cucumber-1.3
24
+ - gemfile: Gemfile.cucumber-1.3
25
25
  rvm: 2.5.3 # doesn't work with old RSpec
26
- - gemfile: gemfiles/Gemfile.cucumber-1.3
26
+ - gemfile: Gemfile.cucumber-1.3
27
27
  rvm: 2.1.10 # doesn't work with old RSpec
28
28
 
29
29
  install:
30
30
  # Replace default Travis CI bundler script with a version that doesn't
31
31
  # explode when lockfile doesn't match recently bumped version
32
- - gem update --system
33
32
  - bundle install --no-deployment --jobs=3 --retry=3 --path=${BUNDLE_PATH:-vendor/bundle}
34
33
 
35
34
  before_script:
@@ -0,0 +1,55 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
+
7
+
8
+ ## 1.15.0 - 2019-02-08
9
+
10
+ ### Breaking changes
11
+
12
+ - Moved gem's code from `Cucumber` module into `CucumberFactory` module.
13
+ - Instead of calling `Cucumber::Factory.add_steps(self)`, `require 'cucumber_factory/add_steps'` instead.
14
+
15
+
16
+ ## 1.14.2 - 2018-10-31
17
+
18
+ ### Compatible changes
19
+
20
+ - Replace deprecated `Fixnum` with `Integer`
21
+
22
+
23
+ ## 1.14.1 - 2018-10-26
24
+
25
+ ### Compatible changes
26
+
27
+ - Allow to refer to previously set foreign keys
28
+
29
+
30
+ ## 1.14.0 - 2018-10-26
31
+
32
+ ### Compatible changes
33
+
34
+ - Allow to set numbers without quotes
35
+ - Support array fields out of the box
36
+ - Allow to set has_many associations with square bracket notation
37
+
38
+
39
+ ## 1.13.0 - 2018-04-26
40
+
41
+ ### Compatible changes
42
+
43
+ - Support multi line attribute assignment
44
+
45
+
46
+ ## 1.12.0 - 2018-04-26
47
+
48
+ ### Compatible changes
49
+
50
+ - Support for Cucumber 3.0 and 3.1
51
+
52
+
53
+ ## Previous releases
54
+
55
+ - See [GitHub](https://github.com/makandra/cucumber_factory/commits/master)
data/Gemfile CHANGED
@@ -1 +1 @@
1
- ./gemfiles/Gemfile.cucumber-2.4
1
+ ./Gemfile.cucumber-2.4
@@ -14,4 +14,4 @@ gem 'database_cleaner', '~>1.0.0'
14
14
  gem 'gemika'
15
15
 
16
16
  # Gem under test
17
- gem 'cucumber_factory', :path => '..'
17
+ gem 'cucumber_factory', :path => '.'
@@ -1,7 +1,7 @@
1
1
  PATH
2
- remote: ..
2
+ remote: .
3
3
  specs:
4
- cucumber_factory (1.14.2)
4
+ cucumber_factory (1.15.0)
5
5
  activerecord
6
6
  activesupport
7
7
  cucumber
@@ -13,4 +13,4 @@ gem 'database_cleaner'
13
13
  gem 'gemika'
14
14
 
15
15
  # Gem under test
16
- gem 'cucumber_factory', :path => '..'
16
+ gem 'cucumber_factory', :path => '.'
@@ -1,7 +1,7 @@
1
1
  PATH
2
- remote: ..
2
+ remote: .
3
3
  specs:
4
- cucumber_factory (1.14.2)
4
+ cucumber_factory (1.15.0)
5
5
  activerecord
6
6
  activesupport
7
7
  cucumber
@@ -13,4 +13,4 @@ gem 'database_cleaner'
13
13
  gem 'gemika'
14
14
 
15
15
  # Gem under test
16
- gem 'cucumber_factory', :path => '..'
16
+ gem 'cucumber_factory', :path => '.'
@@ -1,7 +1,7 @@
1
1
  PATH
2
- remote: ..
2
+ remote: .
3
3
  specs:
4
- cucumber_factory (1.14.2)
4
+ cucumber_factory (1.15.0)
5
5
  activerecord
6
6
  activesupport
7
7
  cucumber
@@ -13,4 +13,4 @@ gem 'database_cleaner'
13
13
  gem 'gemika'
14
14
 
15
15
  # Gem under test
16
- gem 'cucumber_factory', :path => '..'
16
+ gem 'cucumber_factory', :path => '.'
@@ -1,7 +1,7 @@
1
1
  PATH
2
- remote: ..
2
+ remote: .
3
3
  specs:
4
- cucumber_factory (1.14.2)
4
+ cucumber_factory (1.15.0)
5
5
  activerecord
6
6
  activesupport
7
7
  cucumber
@@ -1 +1 @@
1
- ./gemfiles/Gemfile.cucumber-2.4.lock
1
+ ./Gemfile.cucumber-2.4.lock
data/README.md CHANGED
@@ -180,7 +180,7 @@ In your `Gemfile` say:
180
180
 
181
181
  Now create a file `features/step_definitions/factory_steps.rb`, which just says
182
182
 
183
- Cucumber::Factory.add_steps(self)
183
+ require 'cucumber_factory/add_steps'
184
184
 
185
185
  Now run `bundle install` and restart your server.
186
186
 
@@ -12,5 +12,19 @@ end
12
12
  require 'cucumber_priority'
13
13
 
14
14
  # Gem
15
- require 'cucumber/factory'
15
+ require 'cucumber_factory/build_strategy'
16
+ require 'cucumber_factory/factory'
16
17
  require 'cucumber_factory/switcher'
18
+
19
+ module Cucumber
20
+ module Factory
21
+ module_function
22
+
23
+ def add_steps(main)
24
+ warn "Using `Cucumber::Factory.add_steps(self)` is deprecated. Use `require 'cucumber_factory/add_steps'` instead."
25
+
26
+ add_steps_filepath = File.join(File.dirname(__FILE__), 'cucumber_factory/add_steps.rb')
27
+ main.instance_eval(File.read(add_steps_filepath))
28
+ end
29
+ end
30
+ end
@@ -0,0 +1 @@
1
+ CucumberFactory::Factory.add_steps(self)
@@ -0,0 +1,108 @@
1
+ module CucumberFactory
2
+
3
+ # wraps machinist / factory_bot / ruby object logic
4
+
5
+ class BuildStrategy
6
+
7
+ class << self
8
+
9
+ def from_prose(model_prose, variant_prose)
10
+ # don't use \w which depends on the system locale
11
+ underscored_model_name = model_prose.gsub(/[^A-Za-z0-9_\/]+/, "_")
12
+ if variant_prose.present?
13
+ variants = /\((.*?)\)/.match(variant_prose)[1].split(/\s*,\s*/)
14
+ variants = variants.collect { |variant| variant.downcase.gsub(" ", "_") }
15
+ else
16
+ variants = []
17
+ end
18
+
19
+ if factory_bot_strategy = factory_bot_strategy(underscored_model_name, variants)
20
+ factory_bot_strategy
21
+ else
22
+ model_class = underscored_model_name.camelize.constantize
23
+ machinist_strategy(model_class, variants) ||
24
+ active_record_strategy(model_class) ||
25
+ ruby_object_strategy(model_class)
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ def factory_bot_strategy(factory_name, variants)
32
+ factory_class = ::FactoryBot if defined?(FactoryBot)
33
+ factory_class ||= ::FactoryGirl if defined?(FactoryGirl)
34
+ return unless factory_class
35
+
36
+ variants = variants.map(&:to_sym)
37
+ factory_name = factory_name.to_s.underscore.gsub('/', '_').to_sym
38
+
39
+ factory = factory_class.factories[factory_name]
40
+
41
+ if factory.nil? && variants.present? && factory = factory_class.factories[variants[0]]
42
+ factory_name, *variants = variants
43
+ end
44
+
45
+ if factory
46
+ new(factory.build_class) do |attributes|
47
+ # Cannot have additional scalar args after a varargs
48
+ # argument in Ruby 1.8 and 1.9
49
+ args = []
50
+ args += variants
51
+ args << attributes
52
+ factory_class.create(factory_name, *args)
53
+ end
54
+ end
55
+
56
+ end
57
+
58
+ def machinist_strategy(model_class, variants)
59
+ if model_class.respond_to?(:make)
60
+
61
+ new(model_class) do |attributes|
62
+ if variants.present?
63
+ variants.size == 1 or raise 'Machinist only supports a single variant per blueprint'
64
+ model_class.make(variants.first.to_sym, attributes)
65
+ else
66
+ model_class.make(attributes)
67
+ end
68
+ end
69
+
70
+ end
71
+ end
72
+
73
+ def active_record_strategy(model_class)
74
+ if model_class.respond_to?(:create!)
75
+
76
+ new(model_class) do |attributes|
77
+ model = model_class.new
78
+ CucumberFactory::Switcher.assign_attributes(model, attributes)
79
+ model.save!
80
+ model
81
+ end
82
+
83
+ end
84
+ end
85
+
86
+ def ruby_object_strategy(model_class)
87
+ new(model_class) do |attributes|
88
+ model_class.new(attributes)
89
+ end
90
+ end
91
+
92
+ end
93
+
94
+
95
+ attr_reader :model_class
96
+
97
+ def initialize(model_class, &block)
98
+ @model_class = model_class
99
+ @create_proc = block
100
+ end
101
+
102
+ def create_record(attributes)
103
+ @create_proc.call(attributes)
104
+ end
105
+
106
+ end
107
+
108
+ end
@@ -1,7 +1,5 @@
1
- require 'cucumber/factory/build_strategy'
2
-
3
- module Cucumber
4
- class Factory
1
+ module CucumberFactory
2
+ module Factory
5
3
  class Error < StandardError; end
6
4
 
7
5
  ATTRIBUTES_PATTERN = '( with the .+?)?( (?:which|who|that) is .+?)?'
@@ -22,7 +20,7 @@ module Cucumber
22
20
 
23
21
  CLEAR_NAMED_RECORDS_STEP_DESCRIPTOR = {
24
22
  :kind => :Before,
25
- :block => proc { Cucumber::Factory.send(:reset_named_records, self) }
23
+ :block => proc { CucumberFactory::Factory.send(:reset_named_records, self) }
26
24
  }
27
25
 
28
26
  # We cannot use vararg blocks in the descriptors in Ruby 1.8, as explained by
@@ -32,26 +30,26 @@ module Cucumber
32
30
  NAMED_CREATION_STEP_DESCRIPTOR = {
33
31
  :kind => :Given,
34
32
  :pattern => /^#{NAMED_RECORD_PATTERN}#{ATTRIBUTES_PATTERN}?$/,
35
- :block => lambda { |a1, a2, a3, a4, a5| Cucumber::Factory.send(:parse_named_creation, self, a1, a2, a3, a4, a5) }
33
+ :block => lambda { |a1, a2, a3, a4, a5| CucumberFactory::Factory.send(:parse_named_creation, self, a1, a2, a3, a4, a5) }
36
34
  }
37
35
 
38
36
  CREATION_STEP_DESCRIPTOR = {
39
37
  :kind => :Given,
40
38
  :pattern => /^#{RECORD_PATTERN}#{ATTRIBUTES_PATTERN}$/,
41
- :block => lambda { |a1, a2, a3, a4| Cucumber::Factory.send(:parse_creation, self, a1, a2, a3, a4) }
39
+ :block => lambda { |a1, a2, a3, a4| CucumberFactory::Factory.send(:parse_creation, self, a1, a2, a3, a4) }
42
40
  }
43
41
 
44
42
  NAMED_CREATION_STEP_DESCRIPTOR_WITH_TEXT_ATTRIBUTES = {
45
43
  :kind => :Given,
46
44
  :pattern => /^"#{NAMED_RECORD_PATTERN}#{ATTRIBUTES_PATTERN}#{TEXT_ATTRIBUTES_PATTERN}?$/,
47
- :block => lambda { |a1, a2, a3, a4, a5, a6| Cucumber::Factory.send(:parse_named_creation, self, a1, a2, a3, a4, a5, a6) },
45
+ :block => lambda { |a1, a2, a3, a4, a5, a6| CucumberFactory::Factory.send(:parse_named_creation, self, a1, a2, a3, a4, a5, a6) },
48
46
  :priority => true
49
47
  }
50
48
 
51
49
  CREATION_STEP_DESCRIPTOR_WITH_TEXT_ATTRIBUTES = {
52
50
  :kind => :Given,
53
51
  :pattern => /^#{RECORD_PATTERN}#{ATTRIBUTES_PATTERN}#{TEXT_ATTRIBUTES_PATTERN}$/,
54
- :block => lambda { |a1, a2, a3, a4, a5| Cucumber::Factory.send(:parse_creation, self, a1, a2, a3, a4, a5) },
52
+ :block => lambda { |a1, a2, a3, a4, a5| CucumberFactory::Factory.send(:parse_creation, self, a1, a2, a3, a4, a5) },
55
53
  :priority => true
56
54
  }
57
55
 
@@ -94,12 +92,12 @@ module Cucumber
94
92
  def set_named_record(world, name, record)
95
93
  named_records(world)[name] = record
96
94
  end
97
-
95
+
98
96
  def parse_named_creation(world, name, raw_model, raw_variant, raw_attributes, raw_boolean_attributes, raw_multiline_attributes = nil)
99
97
  record = parse_creation(world, raw_model, raw_variant, raw_attributes, raw_boolean_attributes, raw_multiline_attributes)
100
98
  set_named_record(world, name, record)
101
99
  end
102
-
100
+
103
101
  def parse_creation(world, raw_model, raw_variant, raw_attributes, raw_boolean_attributes, raw_multiline_attributes = nil)
104
102
  build_strategy = BuildStrategy.from_prose(raw_model, raw_variant)
105
103
  model_class = build_strategy.model_class
@@ -1,3 +1,3 @@
1
1
  module CucumberFactory
2
- VERSION = '1.14.2'
2
+ VERSION = '1.15.0'
3
3
  end
@@ -1,8 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Cucumber::Factory::BuildStrategy do
3
+ describe CucumberFactory::BuildStrategy do
4
4
 
5
- subject { Cucumber::Factory::BuildStrategy }
5
+ subject { CucumberFactory::BuildStrategy }
6
6
 
7
7
  # most of the behaviour is integration tested in steps_spec.rb
8
8
 
@@ -17,7 +17,8 @@ def prepare_cucumber_example
17
17
  @main.extend(Cucumber::RbSupport::RbDsl)
18
18
  end
19
19
 
20
- Cucumber::Factory.add_steps(@main)
20
+ add_steps_filepath = File.expand_path(File.join(File.dirname(__FILE__), '../../lib/cucumber_factory/add_steps.rb'))
21
+ @main.instance_eval(File.read(add_steps_filepath))
21
22
  end
22
23
 
23
24
  def invoke_cucumber_step(step, doc_string = nil, data_table = nil)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cucumber_factory
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.14.2
4
+ version: 1.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henning Koch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-31 00:00:00.000000000 Z
11
+ date: 2019-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cucumber
@@ -77,23 +77,25 @@ files:
77
77
  - ".rspec"
78
78
  - ".ruby-version"
79
79
  - ".travis.yml"
80
+ - CHANGELOG.md
80
81
  - Gemfile
82
+ - Gemfile.cucumber-1.3
83
+ - Gemfile.cucumber-1.3.lock
84
+ - Gemfile.cucumber-2.4
85
+ - Gemfile.cucumber-2.4.lock
86
+ - Gemfile.cucumber-3.0
87
+ - Gemfile.cucumber-3.0.lock
88
+ - Gemfile.cucumber-3.1
89
+ - Gemfile.cucumber-3.1.lock
81
90
  - Gemfile.lock
82
91
  - LICENSE
83
92
  - README.md
84
93
  - Rakefile
85
94
  - cucumber_factory.gemspec
86
- - gemfiles/Gemfile.cucumber-1.3
87
- - gemfiles/Gemfile.cucumber-1.3.lock
88
- - gemfiles/Gemfile.cucumber-2.4
89
- - gemfiles/Gemfile.cucumber-2.4.lock
90
- - gemfiles/Gemfile.cucumber-3.0
91
- - gemfiles/Gemfile.cucumber-3.0.lock
92
- - gemfiles/Gemfile.cucumber-3.1
93
- - gemfiles/Gemfile.cucumber-3.1.lock
94
- - lib/cucumber/factory.rb
95
- - lib/cucumber/factory/build_strategy.rb
96
95
  - lib/cucumber_factory.rb
96
+ - lib/cucumber_factory/add_steps.rb
97
+ - lib/cucumber_factory/build_strategy.rb
98
+ - lib/cucumber_factory/factory.rb
97
99
  - lib/cucumber_factory/switcher.rb
98
100
  - lib/cucumber_factory/version.rb
99
101
  - spec/cucumber_factory/factory/build_strategy_spec.rb
@@ -1,110 +0,0 @@
1
- module Cucumber
2
- class Factory
3
-
4
- # wraps machinist / factory_bot / ruby object logic
5
-
6
- class BuildStrategy
7
-
8
- class << self
9
-
10
- def from_prose(model_prose, variant_prose)
11
- # don't use \w which depends on the system locale
12
- underscored_model_name = model_prose.gsub(/[^A-Za-z0-9_\/]+/, "_")
13
- if variant_prose.present?
14
- variants = /\((.*?)\)/.match(variant_prose)[1].split(/\s*,\s*/)
15
- variants = variants.collect { |variant| variant.downcase.gsub(" ", "_") }
16
- else
17
- variants = []
18
- end
19
-
20
- if factory_bot_strategy = factory_bot_strategy(underscored_model_name, variants)
21
- factory_bot_strategy
22
- else
23
- model_class = underscored_model_name.camelize.constantize
24
- machinist_strategy(model_class, variants) ||
25
- active_record_strategy(model_class) ||
26
- ruby_object_strategy(model_class)
27
- end
28
- end
29
-
30
- private
31
-
32
- def factory_bot_strategy(factory_name, variants)
33
- factory_class = ::FactoryBot if defined?(FactoryBot)
34
- factory_class ||= ::FactoryGirl if defined?(FactoryGirl)
35
- return unless factory_class
36
-
37
- variants = variants.map(&:to_sym)
38
- factory_name = factory_name.to_s.underscore.gsub('/', '_').to_sym
39
-
40
- factory = factory_class.factories[factory_name]
41
-
42
- if factory.nil? && variants.present? && factory = factory_class.factories[variants[0]]
43
- factory_name, *variants = variants
44
- end
45
-
46
- if factory
47
- new(factory.build_class) do |attributes|
48
- # Cannot have additional scalar args after a varargs
49
- # argument in Ruby 1.8 and 1.9
50
- args = []
51
- args += variants
52
- args << attributes
53
- factory_class.create(factory_name, *args)
54
- end
55
- end
56
-
57
- end
58
-
59
- def machinist_strategy(model_class, variants)
60
- if model_class.respond_to?(:make)
61
-
62
- new(model_class) do |attributes|
63
- if variants.present?
64
- variants.size == 1 or raise 'Machinist only supports a single variant per blueprint'
65
- model_class.make(variants.first.to_sym, attributes)
66
- else
67
- model_class.make(attributes)
68
- end
69
- end
70
-
71
- end
72
- end
73
-
74
- def active_record_strategy(model_class)
75
- if model_class.respond_to?(:create!)
76
-
77
- new(model_class) do |attributes|
78
- model = model_class.new
79
- CucumberFactory::Switcher.assign_attributes(model, attributes)
80
- model.save!
81
- model
82
- end
83
-
84
- end
85
- end
86
-
87
- def ruby_object_strategy(model_class)
88
- new(model_class) do |attributes|
89
- model_class.new(attributes)
90
- end
91
- end
92
-
93
- end
94
-
95
-
96
- attr_reader :model_class
97
-
98
- def initialize(model_class, &block)
99
- @model_class = model_class
100
- @create_proc = block
101
- end
102
-
103
- def create_record(attributes)
104
- @create_proc.call(attributes)
105
- end
106
-
107
- end
108
-
109
- end
110
- end