chop 0.20.1 → 0.21.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 +4 -4
- data/README.md +3 -3
- data/lib/chop.rb +1 -0
- data/lib/chop/definition_list.rb +19 -0
- data/lib/chop/dfn_dl.rb +14 -0
- data/lib/chop/diff.rb +7 -16
- data/lib/chop/dsl.rb +3 -3
- data/lib/chop/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b908d6fd6ee8ad3a672d047bc4b8e6b32c2abd6
|
4
|
+
data.tar.gz: bc1c246a81f4dda4ef37fbfb14fe2b204566fb26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6635faa8663d31c306ddf41b3c18dbeb5d3fe70836f3bc284be5d1916b8d98598e4567727b06d04e2206da71cd311ecb122f35f6ac0de0c84351a958378ed450
|
7
|
+
data.tar.gz: 22fd0b20cad3052e9f224e523dfdb81b19bbeb03ba49dd02757fe6451b922f96339d09808ed5667ece53bac5fec49696122d924c000b8a1421359eefd348504e
|
data/README.md
CHANGED
@@ -61,7 +61,7 @@ Overide Capybara finders:
|
|
61
61
|
* `#allow_not_found`: diffing against a missing element will diff against `[[]]` instead of raising an exception.
|
62
62
|
|
63
63
|
High-level declarative transformations:
|
64
|
-
* `#image`: Replaces the specified cell with the
|
64
|
+
* `#image`: Replaces the specified cell with the filename of the first image within it, stripped of path and cachebusters.
|
65
65
|
|
66
66
|
All these methods are implemented in terms of the following low-level methods, useful for when you need more control over the transformation:
|
67
67
|
* `#header`: add or transform the table header, depending on block arity.
|
@@ -149,11 +149,11 @@ end
|
|
149
149
|
|
150
150
|
### Don't like monkeypatching?
|
151
151
|
|
152
|
-
Load `chop` before `cucumber` in your Gemfile, and call the two methods directly on the `Chop` module, passing the cucumber table in as the
|
152
|
+
Load `chop` before `cucumber` in your Gemfile, and call the two methods directly on the `Chop` module, passing the cucumber table in as the last argument.
|
153
153
|
|
154
154
|
```ruby
|
155
155
|
Chop.create! Users, table
|
156
|
-
Chop.diff! table,
|
156
|
+
Chop.diff! "table", table
|
157
157
|
Chop.fill_in! table
|
158
158
|
```
|
159
159
|
|
data/lib/chop.rb
CHANGED
data/lib/chop/definition_list.rb
CHANGED
@@ -18,6 +18,25 @@ module Chop
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
21
|
+
|
22
|
+
def field key
|
23
|
+
transformation do |rows|
|
24
|
+
rows.map do |row|
|
25
|
+
if row.first.text.parameterize.underscore == key.to_s
|
26
|
+
row[1] = yield(row[1])
|
27
|
+
end
|
28
|
+
row
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def image *cols
|
34
|
+
block = ->(cell){ cell_to_image_filename(cell) }
|
35
|
+
cols.each do |col|
|
36
|
+
method = col.is_a?(Symbol) ? :field : :column
|
37
|
+
send method, col, &block
|
38
|
+
end
|
39
|
+
end
|
21
40
|
end
|
22
41
|
|
23
42
|
Dl = DefinitionList
|
data/lib/chop/dfn_dl.rb
ADDED
data/lib/chop/diff.rb
CHANGED
@@ -9,23 +9,18 @@ module Chop
|
|
9
9
|
new(selector, table, session, block).diff!
|
10
10
|
end
|
11
11
|
|
12
|
+
def cell_to_image_filename cell
|
13
|
+
cell.all("img").map do |img|
|
14
|
+
File.basename(img[:src] || "").split("?")[0].sub(/-[0-9a-f]{64}/, '')
|
15
|
+
end.first
|
16
|
+
end
|
17
|
+
|
12
18
|
class_attribute :default_selector, :rows_finder, :cells_finder, :text_finder
|
13
19
|
|
14
20
|
self.rows_finder = -> { raise "Missing rows finder!" }
|
15
21
|
self.cells_finder = -> { raise "Missing cells finder!" }
|
16
22
|
self.text_finder = ->(cell) { cell.text }
|
17
23
|
|
18
|
-
def self.text_or_image_alt_finder
|
19
|
-
->(cell) do
|
20
|
-
text = cell.text
|
21
|
-
if text.blank? && image = cell.first("img")
|
22
|
-
image["alt"]
|
23
|
-
else
|
24
|
-
text
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
24
|
attr_accessor :header_transformations, :transformations
|
30
25
|
|
31
26
|
def initialize selector = nil, table = nil, session = Capybara.current_session, block = nil, &other_block
|
@@ -94,11 +89,7 @@ module Chop
|
|
94
89
|
def image *keys
|
95
90
|
keys.each do |key|
|
96
91
|
field(key) do |cell|
|
97
|
-
|
98
|
-
image["alt"]
|
99
|
-
else
|
100
|
-
cell
|
101
|
-
end
|
92
|
+
cell_to_image_filename(cell)
|
102
93
|
end
|
103
94
|
end
|
104
95
|
end
|
data/lib/chop/dsl.rb
CHANGED
@@ -4,8 +4,8 @@ module Chop
|
|
4
4
|
Create.create! klass, table, &block
|
5
5
|
end
|
6
6
|
|
7
|
-
def diff! selector, table, session: Capybara.current_session, &block
|
8
|
-
class_name = session.find(selector).tag_name.
|
7
|
+
def diff! selector, table, session: Capybara.current_session, as: nil, &block
|
8
|
+
class_name = as ? as.to_s.camelize : session.find(selector).tag_name.camelize
|
9
9
|
klass = const_get("Chop::#{class_name}")
|
10
10
|
klass.diff! selector, table, session: session, &block
|
11
11
|
end
|
@@ -24,7 +24,7 @@ if defined?(Cucumber::MultilineArgument::DataTable)
|
|
24
24
|
|
25
25
|
def diff! other_table="table", options={}, &block
|
26
26
|
if other_table.is_a?(String) && !other_table.include?("|")
|
27
|
-
Chop.diff! other_table, self, &block
|
27
|
+
Chop.diff! other_table, self, options, &block
|
28
28
|
else
|
29
29
|
super
|
30
30
|
end
|
data/lib/chop/version.rb
CHANGED
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.
|
4
|
+
version: 0.21.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: 2018-
|
11
|
+
date: 2018-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -129,6 +129,7 @@ files:
|
|
129
129
|
- lib/chop/config.rb
|
130
130
|
- lib/chop/create.rb
|
131
131
|
- lib/chop/definition_list.rb
|
132
|
+
- lib/chop/dfn_dl.rb
|
132
133
|
- lib/chop/diff.rb
|
133
134
|
- lib/chop/dsl.rb
|
134
135
|
- lib/chop/form.rb
|