chop 0.17.0 → 0.18.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: 59d92389e8d22766ebf98088ebd74d94e8688985
4
- data.tar.gz: c9faf716a53e8723cbf06557536a40874acf63b1
3
+ metadata.gz: 9437969c21a2222e26cbd07267a976fa19c58fac
4
+ data.tar.gz: 84762ef6d1eca1f80a823e10e9c62e20cfeea707
5
5
  SHA512:
6
- metadata.gz: 96cd9da2dad570c6ea2cd5dc499241defd524dd46112cb45b64ce34049f032734a80362e08ebc3a5b50b08ddaa5951f26bd1f8583b976b9787190045bcff45ef
7
- data.tar.gz: 478895292a06647dfa5ee2df7dbef98986bef6c68febe0447d31fe8d79bde787a1a0b1526674182ee2cc40ffe795efa34a0e945aaeac243a3c3d33e0deba5348
6
+ metadata.gz: 5c37f4af27957e08a63433b72917e2258e0d8e64190d97e8ec30796eb804a5ca022e92ad56597dc746b603fb8e9aacb22d2155ca0e88ab7538429a5f5402e897
7
+ data.tar.gz: 011669ab54baa0009368cf7db428d1a08122e99f72a909939bbcd0bb753760192307e4aff07a9b5877a9da889b3aff6a943fcb2670fc53eb74455043ddf63707
data/Gemfile CHANGED
@@ -4,3 +4,6 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  gem "byebug"
7
+ gem "poltergeist"
8
+ gem "phantomjs-binaries"
9
+
@@ -3,8 +3,12 @@ require "chop/diff"
3
3
  module Chop
4
4
  class DefinitionList < Diff
5
5
  self.default_selector = "dl"
6
- self.rows_finder = ->(root) { root.all("dfn") }
7
- self.cells_finder = ->(row) { row.all("dt,dd") }
6
+ self.rows_finder = ->(root) do
7
+ root.all("dt,dd").slice_before do |node|
8
+ node.tag_name == "dt"
9
+ end
10
+ end
11
+ self.cells_finder = ->(row) { row }
8
12
 
9
13
  def column index, &block
10
14
  transformation do |rows|
@@ -7,6 +7,13 @@ module Chop
7
7
  new(table, session, path).fill_in!
8
8
  end
9
9
 
10
+ def self.diff! selector, table, session: Capybara.current_session, &block
11
+ actual = session.find("form").all("input, textarea, select").map do |field|
12
+ [field.label, field.value]
13
+ end
14
+ table.diff! actual, surplus_row: false
15
+ end
16
+
10
17
  def fill_in!
11
18
  table.rows_hash.each do |label, value|
12
19
  Field.for(session, label, value, path).fill_in!
@@ -110,13 +117,48 @@ module Chop
110
117
  end
111
118
  end
112
119
 
113
- class File < Field
120
+ class SingleFile < Field
114
121
  def matches?
115
- field[:type] == "file"
122
+ field[:type] == "file" && !field[:multiple]
116
123
  end
117
124
 
118
125
  def fill_in!
119
- field.set ::File.join(path, value)
126
+ assert_single_file!
127
+ field.set file_path
128
+ end
129
+
130
+ private
131
+
132
+ def file_path
133
+ ::File.join(path, value).tap do |path|
134
+ ::File.open(path){} # raise Errno::ENOENT if file doesn't exist
135
+ end
136
+ end
137
+
138
+ def assert_single_file!
139
+ if value.include?(" ")
140
+ raise TypeError.new("Cannot attach multiple files to file field '#{label}' without the multiple attribute present")
141
+ end
142
+ end
143
+ end
144
+
145
+ class MultipleFile < Field
146
+ def matches?
147
+ field[:type] == "file" && field[:multiple]
148
+ end
149
+
150
+ def fill_in!
151
+ field.set file_paths
152
+ end
153
+
154
+ private
155
+
156
+ def file_paths
157
+ value.split(" ").map do |filename|
158
+ ::File.join(path, filename).tap do |path|
159
+ ::File.open(path){} # raise Errno::ENOENT if file doesn't exist
160
+ end
161
+ end
120
162
  end
121
163
  end
122
164
 
@@ -1,3 +1,3 @@
1
1
  module Chop
2
- VERSION = "0.17.0"
2
+ VERSION = "0.18.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.17.0
4
+ version: 0.18.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: 2017-03-26 00:00:00.000000000 Z
11
+ date: 2017-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord