cucumber_factory 2.2.0 → 2.3.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: 95567d71e09afa59f6db5bb2722ce78eb234b473987025ca3f66b6e181cdac1e
4
- data.tar.gz: 7b1e046852657282cb2d5b65b714d12bb65c848196c0d6c70c13f3ce231fc684
3
+ metadata.gz: 864d657afd1eb2d45bba31a210ed4025aed3756c5224d5c2a2bfb8d9b9baa469
4
+ data.tar.gz: fc74f572c8518d5cb366e92a4799f6b74b176cc516c67cd6750432380404be49
5
5
  SHA512:
6
- metadata.gz: '083f2675e4b6592ab9ee117b5080fefdeaa06f27abba833f3145b176834f37baf3e40f4ef74e90b9d91558f1034b50c7c6250d2675caeda98d52b8a794d27142'
7
- data.tar.gz: 392e4121dc98584c1928f2e028964780f079a4a0f74d437fb6595dc6d2b9ecbbb090e9eb97f0361f9fa1059c633fb8a9de8f357d986ad0a3bd5e193e79c20bae
6
+ metadata.gz: 75750f57520b8a9e535d8d26094d53fbff9678a41b3ccff12a01f0610f79cc876ee2b031a95be37e831da33d80fa7b8072ae6ef4c377be233dc87f4d2edc4994
7
+ data.tar.gz: a409eaa3516d73efaf6da8d413bd426b48cd4b2aee19621982936fab6f0d79c830b8aae07b19d064b253f69445f4c26ab97700e08d14f0022ec9a54befbcd120
data/.gitignore CHANGED
@@ -6,3 +6,4 @@ pkg
6
6
  .rvmrc
7
7
  log/*.log
8
8
  spec/support/database.yml
9
+ uploads/
@@ -15,6 +15,16 @@ This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html
15
15
 
16
16
  -
17
17
 
18
+ ## 2.3.0 - 2020-09-24
19
+
20
+ ### Compatible changes
21
+
22
+ - Added a step to add file objects to a model:
23
+ ```cucumber
24
+ Given there is a user with the avatar file:"path/to/avatar.jpg"
25
+ ```
26
+ Both single and double quotes are supported.
27
+
18
28
  ## 2.2.0 - 2020-09-23
19
29
 
20
30
  ### Compatible changes
@@ -14,6 +14,7 @@ gem 'gemika'
14
14
 
15
15
  # Test dependencies
16
16
  gem 'factory_bot', '< 5'
17
+ gem 'carrierwave', '~> 1.0'
17
18
 
18
19
  # Gem under test
19
20
  gem 'cucumber_factory', :path => '.'
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cucumber_factory (2.2.0)
4
+ cucumber_factory (2.3.0)
5
5
  activerecord
6
6
  activesupport
7
7
  cucumber
@@ -24,6 +24,10 @@ GEM
24
24
  tzinfo (~> 1.1)
25
25
  arel (6.0.4)
26
26
  builder (3.2.4)
27
+ carrierwave (1.2.3)
28
+ activemodel (>= 4.0.0)
29
+ activesupport (>= 4.0.0)
30
+ mime-types (>= 1.16)
27
31
  concurrent-ruby (1.1.6)
28
32
  cucumber (1.3.20)
29
33
  builder (>= 2.1.2)
@@ -42,6 +46,9 @@ GEM
42
46
  multi_json (~> 1.3)
43
47
  i18n (0.9.5)
44
48
  concurrent-ruby (~> 1.0)
49
+ mime-types (3.2.2)
50
+ mime-types-data (~> 3.2015)
51
+ mime-types-data (3.2018.0812)
45
52
  minitest (5.12.0)
46
53
  multi_json (1.14.1)
47
54
  multi_test (0.1.2)
@@ -70,6 +77,7 @@ PLATFORMS
70
77
  DEPENDENCIES
71
78
  activerecord (~> 4.2.0)
72
79
  activesupport (~> 4.2.0)
80
+ carrierwave (~> 1.0)
73
81
  cucumber (~> 1.3.20)
74
82
  cucumber_factory!
75
83
  database_cleaner (~> 1.0.0)
@@ -14,6 +14,7 @@ gem 'gemika'
14
14
 
15
15
  # Test dependencies
16
16
  gem 'factory_bot', '< 5' # 5.0 requires Ruby >= 2.3
17
+ gem 'carrierwave', '~> 1.0' # 2.0 requires Rails >= 5 and Ruby >= 2.2
17
18
 
18
19
  # Gem under test
19
20
  gem 'cucumber_factory', :path => '.'
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cucumber_factory (2.2.0)
4
+ cucumber_factory (2.3.0)
5
5
  activerecord
6
6
  activesupport
7
7
  cucumber
@@ -24,6 +24,10 @@ GEM
24
24
  tzinfo (~> 1.1)
25
25
  arel (6.0.4)
26
26
  builder (3.2.3)
27
+ carrierwave (1.2.3)
28
+ activemodel (>= 4.0.0)
29
+ activesupport (>= 4.0.0)
30
+ mime-types (>= 1.16)
27
31
  concurrent-ruby (1.0.5)
28
32
  cucumber (2.4.0)
29
33
  builder (>= 2.1.2)
@@ -46,6 +50,9 @@ GEM
46
50
  gherkin (4.1.3)
47
51
  i18n (0.9.5)
48
52
  concurrent-ruby (~> 1.0)
53
+ mime-types (3.2.2)
54
+ mime-types-data (~> 3.2015)
55
+ mime-types-data (3.2018.0812)
49
56
  minitest (5.11.3)
50
57
  multi_json (1.13.1)
51
58
  multi_test (0.1.2)
@@ -74,6 +81,7 @@ PLATFORMS
74
81
  DEPENDENCIES
75
82
  activerecord (~> 4.2.0)
76
83
  activesupport (~> 4.2.0)
84
+ carrierwave (~> 1.0)
77
85
  cucumber (~> 2.4.0)
78
86
  cucumber_factory!
79
87
  database_cleaner
@@ -14,6 +14,7 @@ gem 'gemika'
14
14
 
15
15
  # Test dependencies
16
16
  gem 'factory_bot'
17
+ gem 'carrierwave'
17
18
 
18
19
  # Gem under test
19
20
  gem 'cucumber_factory', :path => '.'
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cucumber_factory (2.2.0)
4
+ cucumber_factory (2.3.0)
5
5
  activerecord
6
6
  activesupport
7
7
  cucumber
@@ -24,6 +24,10 @@ GEM
24
24
  arel (7.1.4)
25
25
  backports (3.11.1)
26
26
  builder (3.2.3)
27
+ carrierwave (1.2.3)
28
+ activemodel (>= 4.0.0)
29
+ activesupport (>= 4.0.0)
30
+ mime-types (>= 1.16)
27
31
  concurrent-ruby (1.0.5)
28
32
  cucumber (3.0.2)
29
33
  builder (>= 2.1.2)
@@ -51,6 +55,9 @@ GEM
51
55
  gherkin (4.1.3)
52
56
  i18n (0.9.5)
53
57
  concurrent-ruby (~> 1.0)
58
+ mime-types (3.2.2)
59
+ mime-types-data (~> 3.2015)
60
+ mime-types-data (3.2018.0812)
54
61
  minitest (5.11.3)
55
62
  multi_json (1.13.1)
56
63
  multi_test (0.1.2)
@@ -79,6 +86,7 @@ PLATFORMS
79
86
  DEPENDENCIES
80
87
  activerecord (~> 5.0.0)
81
88
  activesupport (~> 5.0.0)
89
+ carrierwave
82
90
  cucumber (~> 3.0.0)
83
91
  cucumber_factory!
84
92
  database_cleaner
@@ -14,6 +14,7 @@ gem 'gemika'
14
14
 
15
15
  # Test dependencies
16
16
  gem 'factory_bot'
17
+ gem 'carrierwave'
17
18
 
18
19
  # Gem under test
19
20
  gem 'cucumber_factory', :path => '.'
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cucumber_factory (2.2.0)
4
+ cucumber_factory (2.3.0)
5
5
  activerecord
6
6
  activesupport
7
7
  cucumber
@@ -24,6 +24,10 @@ GEM
24
24
  arel (8.0.0)
25
25
  backports (3.11.1)
26
26
  builder (3.2.3)
27
+ carrierwave (1.2.3)
28
+ activemodel (>= 4.0.0)
29
+ activesupport (>= 4.0.0)
30
+ mime-types (>= 1.16)
27
31
  concurrent-ruby (1.0.5)
28
32
  cucumber (3.1.0)
29
33
  builder (>= 2.1.2)
@@ -51,6 +55,9 @@ GEM
51
55
  gherkin (5.0.0)
52
56
  i18n (0.9.5)
53
57
  concurrent-ruby (~> 1.0)
58
+ mime-types (3.2.2)
59
+ mime-types-data (~> 3.2015)
60
+ mime-types-data (3.2018.0812)
54
61
  minitest (5.11.3)
55
62
  multi_json (1.13.1)
56
63
  multi_test (0.1.2)
@@ -79,6 +86,7 @@ PLATFORMS
79
86
  DEPENDENCIES
80
87
  activerecord (~> 5.1.0)
81
88
  activesupport (~> 5.1.0)
89
+ carrierwave
82
90
  cucumber (~> 3.1.0)
83
91
  cucumber_factory!
84
92
  database_cleaner
data/README.md CHANGED
@@ -151,7 +151,16 @@ Given there is a movie with the tags ["comedy", "drama" and "action"]
151
151
  ```
152
152
 
153
153
 
154
+ Setting file attributes
155
+ -----------------------
154
156
 
157
+ You can set an attribute to a file object with the following syntax:
158
+
159
+ ```cucumber
160
+ Given there is a movie with the image file:'path/to/image.jpg'
161
+ ```
162
+
163
+ All paths are relative to the project root, absolute paths are not supported. Please note that file attributes must follow the syntax `file:"PATH"`, both single and double quotes are allowed.
155
164
 
156
165
  Using named factories and traits
157
166
  --------------------------------
@@ -16,10 +16,11 @@ module CucumberFactory
16
16
  VALUE_INTEGER = /\d+/
17
17
  VALUE_DECIMAL = /[\d\.]+/
18
18
  VALUE_STRING = /"[^"]*"|'[^']*'/
19
+ VALUE_FILE = /file:#{VALUE_STRING}/
19
20
  VALUE_ARRAY = /\[[^\]]*\]/
20
21
  VALUE_LAST_RECORD = /\babove\b/
21
22
 
22
- VALUE_SCALAR = /#{VALUE_STRING}|#{VALUE_DECIMAL}|#{VALUE_INTEGER}/
23
+ VALUE_SCALAR = /#{VALUE_STRING}|#{VALUE_DECIMAL}|#{VALUE_INTEGER}|#{VALUE_FILE}/
23
24
 
24
25
  CLEAR_NAMED_RECORDS_STEP_DESCRIPTOR = {
25
26
  :kind => :Before,
@@ -160,16 +161,16 @@ module CucumberFactory
160
161
  # DocString e.g. "first name: Jane\nlast name: Jenny\n"
161
162
  if raw_multiline_attributes.is_a?(String)
162
163
  raw_multiline_attributes.split("\n").each do |fragment|
163
- raw_attribute, value = fragment.split(': ')
164
+ raw_attribute, value = fragment.split(': ', 2)
164
165
  attribute = attribute_name_from_prose(raw_attribute)
165
- value = "\"#{value}\"" unless matches_fully?(value, VALUE_ARRAY)
166
+ value = "\"#{value}\"" unless matches_fully?(value, /#{VALUE_ARRAY}|#{VALUE_FILE}/)
166
167
  attributes[attribute] = attribute_value(world, model_class, transient_attributes, attribute, value)
167
168
  end
168
169
  # DataTable e.g. in raw [["first name", "Jane"], ["last name", "Jenny"]]
169
170
  else
170
171
  raw_multiline_attributes.raw.each do |raw_attribute, value|
171
172
  attribute = attribute_name_from_prose(raw_attribute)
172
- value = "\"#{value}\"" unless matches_fully?(value, VALUE_ARRAY)
173
+ value = "\"#{value}\"" unless matches_fully?(value, /#{VALUE_ARRAY}|#{VALUE_FILE}/)
173
174
  attributes[attribute] = attribute_value(world, model_class, transient_attributes, attribute, value)
174
175
  end
175
176
  end
@@ -236,6 +237,9 @@ module CucumberFactory
236
237
  value = value.to_i
237
238
  elsif matches_fully?(value, VALUE_DECIMAL)
238
239
  value = BigDecimal(value)
240
+ elsif matches_fully?(value, VALUE_FILE)
241
+ path = File.path("./#{file_value_to_path(value)}")
242
+ value = File.new(path)
239
243
  else
240
244
  raise Error, "Cannot set attribute #{model_class}##{attribute} to #{value}."
241
245
  end
@@ -243,11 +247,20 @@ module CucumberFactory
243
247
  end
244
248
 
245
249
  def unquote(string)
250
+ # This method removes quotes or brackets from the start and end from a string
251
+ # Examples: 'single' => single, "double" => double, [1, 2, 3] => 1, 2, 3
246
252
  string[1, string.length - 2]
247
253
  end
248
254
 
255
+ def file_value_to_path(string)
256
+ # file paths are marked with a special keyword and enclosed with quotes.
257
+ # Example: file:"/path/image.png"
258
+ # This will extract the path (/path/image.png) from the text fragment above
259
+ unquote string.sub(/\Afile:/, '')
260
+ end
261
+
249
262
  def full_regexp(partial_regexp)
250
- Regexp.new("\\A" + partial_regexp.source + "\\z", partial_regexp.options)
263
+ Regexp.new('\\A(?:' + partial_regexp.source + ')\\z', partial_regexp.options)
251
264
  end
252
265
 
253
266
  def matches_fully?(string, partial_regexp)
@@ -267,7 +280,7 @@ module CucumberFactory
267
280
  end
268
281
 
269
282
  def attribute_name_from_prose(prose)
270
- prose.downcase.gsub(" ", "_").to_sym
283
+ prose.downcase.gsub(' ', '_').to_sym
271
284
  end
272
285
 
273
286
  def remember_record_names(world, record, attributes)
@@ -1,3 +1,3 @@
1
1
  module CucumberFactory
2
- VERSION = '2.2.0'
2
+ VERSION = '2.3.0'
3
3
  end
@@ -0,0 +1 @@
1
+ This is a test file.
@@ -0,0 +1 @@
1
+ This is the second test file.
@@ -0,0 +1 @@
1
+ spec/assets/file.txt
@@ -388,6 +388,50 @@ title: Before Sunrise
388
388
  }.to raise_error(CucumberFactory::Factory::Error, 'Cannot set last Movie#premiere_site for polymorphic associations')
389
389
  end
390
390
 
391
+ it 'supports carrierwave uploaders' do
392
+ invoke_cucumber_step('there is a payment with the attachment file:"spec/assets/file.txt"')
393
+ payment = Payment.last
394
+ expect(payment.attachment.file.read).to eq "This is a test file.\n"
395
+ end
396
+
397
+ it 'supports single quote for carrierwave uploaders' do
398
+ invoke_cucumber_step("there is a payment with the attachment file:'spec/assets/file.txt'")
399
+ payment = Payment.last
400
+ expect(payment.attachment.file.read).to eq "This is a test file.\n"
401
+ end
402
+
403
+ it 'is able to read symlinked files' do
404
+ invoke_cucumber_step("there is a payment with the attachment file:'spec/assets/symlink.txt'")
405
+ payment = Payment.last
406
+ expect(payment.attachment.file.read).to eq "This is a test file.\n"
407
+ end
408
+
409
+ it 'supports table syntax for carrierwave uploaders' do
410
+ invoke_cucumber_step('there is a payment with these attributes:', nil, <<-DATA_TABLE)
411
+ | attachment | file:"spec/assets/file.txt" |
412
+ DATA_TABLE
413
+ payment = Payment.last
414
+ expect(payment.attachment.file.read).to eq "This is a test file.\n"
415
+ end
416
+
417
+ it 'supports doc string syntax for carrierwave uploaders' do
418
+ invoke_cucumber_step('there is a payment with these attributes:', <<-DOC_STRING)
419
+ attachment: file:"spec/assets/file.txt"
420
+ DOC_STRING
421
+ payment = Payment.last
422
+ payment.save!
423
+ expect(payment.attachment.file.read).to eq "This is a test file.\n"
424
+ end
425
+
426
+ it 'allows updating a carrierwave attribute' do
427
+ invoke_cucumber_step('there is a payment with the attachment file:"spec/assets/file.txt"')
428
+ payment = Payment.last
429
+ expect(payment.attachment.file.read).to eq "This is a test file.\n"
430
+ invoke_cucumber_step('the payment above has the attachment file:"spec/assets/file2.txt"')
431
+ payment.reload
432
+ expect(payment.attachment.file.read).to eq "This is the second test file.\n"
433
+ end
434
+
391
435
  it 'works with nested factories (BUGFIX)' do
392
436
  invoke_cucumber_step('there is a subgenre movie')
393
437
  end
@@ -447,6 +491,13 @@ title: Before Sunrise
447
491
  obj.attributes[:total].to_s.should == "45.6"
448
492
  end
449
493
 
494
+ it "should allow to set file attributes with the file:'path' syntax" do
495
+ invoke_cucumber_step('there is a plain Ruby class with the file file:"spec/assets/file.txt"')
496
+ obj = PlainRubyClass.last
497
+ obj.attributes[:file].should be_a(File)
498
+ obj.attributes[:file].read.should == "This is a test file.\n"
499
+ end
500
+
450
501
  it "should allow set an array of strings with square brackets" do
451
502
  invoke_cucumber_step('there is a plain Ruby class with the tags ["foo", "bar"] and the list ["bam", "baz"]')
452
503
  obj = PlainRubyClass.last
@@ -3,9 +3,12 @@ $: << File.join(File.dirname(__FILE__), "/../../lib" )
3
3
  require 'cucumber_factory'
4
4
  require 'gemika'
5
5
  require 'factory_bot'
6
+ require 'carrierwave'
7
+ require 'carrierwave/orm/activerecord'
6
8
 
7
9
  ActiveRecord::Base.default_timezone = :local
8
10
 
11
+ Dir["#{File.dirname(__FILE__)}/support/uploaders/*.rb"].sort.each {|f| require f}
9
12
  Dir["#{File.dirname(__FILE__)}/support/models/*.rb"].sort.each {|f| require f}
10
13
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each {|f| require f}
11
14
  Dir["#{File.dirname(__FILE__)}/shared_examples/**/*.rb"].sort.each {|f| require f}
@@ -32,6 +32,7 @@ Gemika::Database.new.rewrite_schema! do
32
32
  create_table :payments do |t|
33
33
  t.text :comment
34
34
  t.integer :amount
35
+ t.string :attachment
35
36
  end
36
37
 
37
38
  create_table :actors do |t|
@@ -1,8 +1,13 @@
1
- class Payment < ActiveRecord::Base
2
-
3
- if ActiveRecord::VERSION::MAJOR <= 3
4
- # Only the comment is accessible, amount isn't
5
- attr_accessible :comment
6
- end
7
-
8
- end
1
+ class Payment < ActiveRecord::Base
2
+ class AttachmentUploader < CarrierWave::Uploader::Base
3
+ storage :file
4
+ end
5
+
6
+ mount_uploader :attachment, AttachmentUploader
7
+
8
+ if ActiveRecord::VERSION::MAJOR <= 3
9
+ # Only the comment is accessible, amount isn't
10
+ attr_accessible :comment
11
+ end
12
+
13
+ end
@@ -0,0 +1,3 @@
1
+ class AttachmentUploader < CarrierWave::Uploader::Base
2
+ storage :file
3
+ end
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: 2.2.0
4
+ version: 2.3.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: 2020-09-23 00:00:00.000000000 Z
11
+ date: 2020-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cucumber
@@ -99,6 +99,9 @@ files:
99
99
  - lib/cucumber_factory/switcher.rb
100
100
  - lib/cucumber_factory/update_strategy.rb
101
101
  - lib/cucumber_factory/version.rb
102
+ - spec/assets/file.txt
103
+ - spec/assets/file2.txt
104
+ - spec/assets/symlink.txt
102
105
  - spec/cucumber_factory/factory/build_strategy_spec.rb
103
106
  - spec/cucumber_factory/steps_spec.rb
104
107
  - spec/spec_helper.rb
@@ -116,6 +119,7 @@ files:
116
119
  - spec/support/models/plain_ruby_class.rb
117
120
  - spec/support/models/user.rb
118
121
  - spec/support/models/uuid_user.rb
122
+ - spec/support/uploaders/attachment_uploader.rb
119
123
  homepage: http://github.com/makandra/cucumber_factory
120
124
  licenses:
121
125
  - MIT