chop 0.23.8 → 0.26.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 983026fa3d934d4b7adafeac19546fec6c8550b1
4
- data.tar.gz: c70bf8196d0aa7d0066ce24c09638903eec71621
2
+ SHA256:
3
+ metadata.gz: bee1ec352644193eeff10aabf667030259daaef55aaf4e0e7adcbfe3af6f53f1
4
+ data.tar.gz: a07d1ce3c87efb2be5a59c5ad7be173ee8b92f0f869b2764d9dabb92e0840eac
5
5
  SHA512:
6
- metadata.gz: a9d3ab204fbd53c21339d3bb9cd2c6b84dcebb945b710f1d9f8d1058cdf6c8c04edde96e7f1b5ac6ab48f46ad852432db336e8bd022d6ea55e617665e286f1ba
7
- data.tar.gz: b87490c821e61315974a5d96d1c083ed55e574f54f2fcf45c33b559ea4d3685b5a5b1ea863e02d8bd0f120b1820369ee2544a2f723171a76591b43956a5e8f92
6
+ metadata.gz: 1b74cb6aafd7b59f8c705220afd644e2295a5355d4f98cd05aff588455dcc9a818406650f4de5f9063802df172cb817c3b7d4994d45e6cc26b9050cae88207e4
7
+ data.tar.gz: 3b2752804004fc1676c10881f67a9178fdcb42e2d19fd0e8efcf8dbf73686b55cb652026633c9732452347211f8b15f5d7349e5fd0cfe8084eb3e2b7bb738b33
@@ -1,3 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.3
3
+ - 2.4
4
+ - 2.5
5
+ - 2.6
6
+ - 2.7
data/README.md CHANGED
@@ -18,7 +18,7 @@ end
18
18
  Chop monkeypatches Cucumber tables with three new methods:
19
19
 
20
20
  * `#create!`: Creates entities. Built-in support for ActiveRecord (default) and FactoryGirl, at present.
21
- * `#diff!`: Enhances existing method to also accept a CSS selector. Currently supports diffing `<table>`, `<dl>`, `<ul>`, and even `<form>`!.
21
+ * `#diff!`: Enhances existing method to also accept a capybara element, or a CSS selector pointing to one. Currently supports diffing `<table>`, `<dl>`, `<ul>`, and even `<form>`!.
22
22
  * `#fill_in!`: Fills in a form on the current page.
23
23
 
24
24
  All these methods accept blocks for customization.
@@ -33,8 +33,8 @@ Transform the attributes hash derived from the table before passing to `ActiveRe
33
33
 
34
34
  High-level declarative transformations:
35
35
 
36
- * `#file`: Replaces a file path with a file handle. Looks in `features/support/fixtures` by default.
37
- * `#files`: Replaces a space-delimited list of file paths with an array of file handles. Looks in `features/support/fixtures` by default.
36
+ * `#file`: Replaces a file path with a file handle. Looks in `features/support/fixtures` by default. Set `upload: true` to wrap file in `Rack::Test::UploadedFile`.
37
+ * `#files`: Replaces a space-delimited list of file paths with an array of file handles. Looks in `features/support/fixtures` by default. Set `upload: true` to wrap file in `Rack::Test::UploadedFile`.
38
38
  * `#has_one/#belongs_to`: Replaces an entity name with that entity. Uses `.find_by_name` by default.
39
39
  * `#has_many`: Replaces a comma-delimited list of entity names with an array of those entities. Uses `.find_by_name` by default.
40
40
  * `#underscore_keys`: Converts all hash keys to underscored versions.
@@ -117,12 +117,20 @@ module Chop
117
117
  def file *keys
118
118
  options = extract_options!(keys)
119
119
  path = options.fetch(:path, "features/support/fixtures")
120
+ upload = options.fetch(:upload, false)
120
121
 
121
122
  handle_renames! keys
122
123
 
123
124
  keys.each do |key|
124
125
  field key do |file|
125
- File.open(File.join(path, file)) if file.present?
126
+ if file.present?
127
+ file_path = File.join(path, file)
128
+ if upload
129
+ Rack::Test::UploadedFile.new(file_path)
130
+ else
131
+ File.open(file_path)
132
+ end
133
+ end
126
134
  end
127
135
  end
128
136
  end
@@ -130,6 +138,7 @@ module Chop
130
138
  def files *keys
131
139
  options = extract_options!(keys)
132
140
  path = options.fetch(:path, "features/support/fixtures")
141
+ upload = options.fetch(:upload, false)
133
142
  delimiter = options.fetch(:delimiter, " ")
134
143
 
135
144
  handle_renames! keys
@@ -137,13 +146,19 @@ module Chop
137
146
  keys.each do |key|
138
147
  field key do |paths|
139
148
  paths.split(delimiter).map do |file|
140
- File.open(File.join(path, file))
149
+ file_path = File.join(path, file)
150
+ if upload
151
+ Rack::Test::UploadedFile.new(file_path)
152
+ else
153
+ File.open(file_path)
154
+ end
141
155
  end
142
156
  end
143
157
  end
144
158
  end
145
159
 
146
160
  def has_many key, klass=nil, delimiter: ", ", name_field: :name
161
+ klass ||= key.to_s.classify.constantize
147
162
  field key do |names|
148
163
  names.split(delimiter).map do |name|
149
164
  klass.find_by!(name_field => name)
@@ -152,6 +167,7 @@ module Chop
152
167
  end
153
168
 
154
169
  def has_one key, klass=nil, name_field: :name
170
+ klass ||= key.to_s.classify.constantize
155
171
  field key do |name|
156
172
  klass.find_by!(name_field => name) if name.present?
157
173
  end
@@ -157,7 +157,11 @@ module Chop
157
157
 
158
158
  def root
159
159
  @root ||= begin
160
- session.find(selector)
160
+ if selector.is_a?(Capybara::Node::Element)
161
+ selector
162
+ else
163
+ session.find(selector)
164
+ end
161
165
  rescue Capybara::ElementNotFound
162
166
  raise unless @allow_not_found
163
167
  Node("")
@@ -7,7 +7,13 @@ module Chop
7
7
  end
8
8
 
9
9
  def diff! selector, table, session: Capybara.current_session, as: nil, &block
10
- class_name = as ? as.to_s.camelize : session.find(selector).tag_name.camelize
10
+ class_name = if as
11
+ as.to_s
12
+ elsif selector.respond_to?(:tag_name)
13
+ selector.tag_name
14
+ else
15
+ session.find(selector).tag_name
16
+ end.camelize
11
17
  klass = const_get("Chop::#{class_name}")
12
18
  klass.diff! selector, table, session: session, &block
13
19
  end
@@ -25,7 +31,7 @@ if defined?(Cucumber::MultilineArgument::DataTable)
25
31
  end
26
32
 
27
33
  def diff! other_table="table", options={}, &block
28
- if other_table.is_a?(String) && !other_table.include?("|")
34
+ if other_table.respond_to?(:tag_name) || (other_table.is_a?(String) && !other_table.include?("|"))
29
35
  Chop.diff! other_table, self, options, &block
30
36
  else
31
37
  super
@@ -8,7 +8,18 @@ module Chop
8
8
  end
9
9
 
10
10
  def self.diff! selector, table, session: Capybara.current_session, &block
11
- all_fields = session.find("form").all("input, textarea, select")
11
+ root = begin
12
+ if selector.is_a?(Capybara::Node::Element)
13
+ selector
14
+ else
15
+ session.find(selector)
16
+ end
17
+ rescue Capybara::ElementNotFound
18
+ raise unless @allow_not_found
19
+ Node("")
20
+ end
21
+
22
+ all_fields = root.all("input, textarea, select")
12
23
  relevant_fields = all_fields.inject([]) do |fields, field|
13
24
  next fields if field[:name].blank?
14
25
  next fields if field[:type] == "submit"
@@ -102,6 +113,10 @@ module Chop
102
113
  end
103
114
  end
104
115
 
116
+ def get_value
117
+ checkboxes.select(&:checked?).map(&:value).join(", ")
118
+ end
119
+
105
120
  private
106
121
 
107
122
  def checkboxes
@@ -1,3 +1,3 @@
1
1
  module Chop
2
- VERSION = "0.23.8"
2
+ VERSION = "0.26.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.23.8
4
+ version: 0.26.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Micah Geisel
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-04-04 00:00:00.000000000 Z
11
+ date: 2021-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -141,8 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
141
  - !ruby/object:Gem::Version
142
142
  version: '0'
143
143
  requirements: []
144
- rubyforge_project:
145
- rubygems_version: 2.6.14
144
+ rubygems_version: 3.0.3
146
145
  signing_key:
147
146
  specification_version: 4
148
147
  summary: Slice and dice your cucumber tables with ease!