chop 0.20.1 → 0.21.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
2
  SHA1:
3
- metadata.gz: ee08121005f0c0e0dc0c87490bd7e3dc5437aa25
4
- data.tar.gz: 88f4109163927c7f3ded4aed309e2129ef8fbd35
3
+ metadata.gz: 3b908d6fd6ee8ad3a672d047bc4b8e6b32c2abd6
4
+ data.tar.gz: bc1c246a81f4dda4ef37fbfb14fe2b204566fb26
5
5
  SHA512:
6
- metadata.gz: 5c090fba6c2c4f5c5033690955dbffb5cc391c7ba1ab0c1f1af10089178ed40d9da7b5af6e8fbb54d2edc3f518b96fa080d0180bff4834e5bd0cd216f5812b50
7
- data.tar.gz: 2139c72e05d46285b0c1279951c62831f1fae90395a9d0a1d68d08c05699cd7e597b67ecb021a896a9cd5f6a62933a17af73d68bafc6b63a32e2f3c878a20ce1
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 alt text of the first image within it.
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 first argument.
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, "table"
156
+ Chop.diff! "table", table
157
157
  Chop.fill_in! table
158
158
  ```
159
159
 
@@ -2,6 +2,7 @@ require "chop/version"
2
2
  require "chop/create"
3
3
  require "chop/table"
4
4
  require "chop/definition_list"
5
+ require "chop/dfn_dl"
5
6
  require "chop/unordered_list"
6
7
  require "chop/form"
7
8
  require "chop/dsl"
@@ -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
@@ -0,0 +1,14 @@
1
+ require "chop/definition_list"
2
+
3
+ module Chop
4
+ class DfnDl < DefinitionList
5
+ self.rows_finder = ->(root) do
6
+ root.all("dfn")
7
+ end
8
+
9
+ self.cells_finder = ->(row) do
10
+ row.all("dt,dd")
11
+ end
12
+ end
13
+ end
14
+
@@ -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
- if image = cell.first("img")
98
- image["alt"]
99
- else
100
- cell
101
- end
92
+ cell_to_image_filename(cell)
102
93
  end
103
94
  end
104
95
  end
@@ -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.capitalize
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
@@ -1,3 +1,3 @@
1
1
  module Chop
2
- VERSION = "0.20.1"
2
+ VERSION = "0.21.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.20.1
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-03-12 00:00:00.000000000 Z
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