conformity 0.0.3 → 0.0.4
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 +11 -4
- data/lib/conformity/action.rb +6 -3
- data/lib/conformity/field.rb +7 -2
- data/lib/conformity/version.rb +1 -1
- data/spec/field_spec.rb +26 -6
- data/spec/form_spec.rb +0 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d8642508831e87cddb514c49e41a861c72e0763
|
4
|
+
data.tar.gz: 49f1b297869149c45f33b30eeb9a10988269ab8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04448922009d3e0e41f6d1b49502ab18b34d1b492f8d5efa21b3220e12001e164990a41904970df2b8dfb9407a43357cac744e1332ef44c2a6f6baf0854287c5
|
7
|
+
data.tar.gz: f091d83d17f1206ca70f061b6b40eb88110bb2b27938e2375ff794af52f154f50a38a57b3b93efe1b428aafe43428d62ba37c1ce9213d88bac342f1a9221c9be
|
data/README.md
CHANGED
@@ -26,15 +26,22 @@ form = Form.new('http://www.google.com/') do
|
|
26
26
|
visit '/'
|
27
27
|
fill_in 'q', with: field(:query)
|
28
28
|
click_on 'Google Search'
|
29
|
+
|
30
|
+
# optional conditions to verify form submission success
|
31
|
+
has_status_code? 200
|
32
|
+
has_content? 'Search Tools'
|
29
33
|
end
|
30
34
|
|
31
35
|
form.field_names
|
32
36
|
# => [:query]
|
33
37
|
|
34
|
-
# returns Capybara::Session
|
35
|
-
form.fill_with('
|
36
|
-
form.fill_with('
|
37
|
-
form.fill_with('
|
38
|
+
# returns Capybara::Session, can call #html etc. on it
|
39
|
+
form.fill_with('news') # perform google search for 'news'
|
40
|
+
form.fill_with('what is the third planet from the sun')
|
41
|
+
form.fill_with('alternatives to gmail')
|
42
|
+
|
43
|
+
# check if the last form submission succeeded (if success conditions were set)
|
44
|
+
form.success?
|
38
45
|
```
|
39
46
|
|
40
47
|
## Contributing
|
data/lib/conformity/action.rb
CHANGED
@@ -20,9 +20,12 @@ module Conformity
|
|
20
20
|
|
21
21
|
def run
|
22
22
|
case name
|
23
|
-
when :fill_in
|
24
|
-
|
25
|
-
|
23
|
+
when :fill_in
|
24
|
+
return unless field.value
|
25
|
+
args.last[:with] = field.value
|
26
|
+
when :choose, :select
|
27
|
+
return unless field.value
|
28
|
+
args.first = field.value
|
26
29
|
end if field
|
27
30
|
|
28
31
|
result = send(name, *args, &block)
|
data/lib/conformity/field.rb
CHANGED
@@ -7,13 +7,18 @@ module Conformity
|
|
7
7
|
def initialize(name, options = {})
|
8
8
|
@name = name
|
9
9
|
@options = options[:options]
|
10
|
+
@required = options[:required] || false
|
11
|
+
end
|
12
|
+
|
13
|
+
def required?
|
14
|
+
@required
|
10
15
|
end
|
11
16
|
|
12
17
|
def value
|
13
18
|
if @value
|
14
19
|
@value
|
15
|
-
|
16
|
-
raise FieldError, "
|
20
|
+
elsif required?
|
21
|
+
raise FieldError, "Required field '#{name}' not set"
|
17
22
|
end
|
18
23
|
end
|
19
24
|
end
|
data/lib/conformity/version.rb
CHANGED
data/spec/field_spec.rb
CHANGED
@@ -4,17 +4,37 @@ require 'conformity/field'
|
|
4
4
|
include Conformity
|
5
5
|
describe Conformity::Field do
|
6
6
|
describe '#value' do
|
7
|
-
it "raises when there's no value" do
|
8
|
-
field = Field.new(:field)
|
9
|
-
|
10
|
-
expect { field.value }.to raise_error(Conformity::FieldError)
|
11
|
-
end
|
12
|
-
|
13
7
|
it "returns a value when there's a value" do
|
14
8
|
field = Field.new('field')
|
15
9
|
field.value = :value
|
16
10
|
|
17
11
|
expect(field.value).to equal(:value)
|
18
12
|
end
|
13
|
+
|
14
|
+
it "raises when there's no value and a field is required" do
|
15
|
+
field = Field.new(:field, required: true)
|
16
|
+
|
17
|
+
expect { field.value }.to raise_error(Conformity::FieldError)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "does not raise when there's no value and a field isn't required" do
|
21
|
+
implicit = Field.new(:field)
|
22
|
+
explicit = Field.new(:field, required: false)
|
23
|
+
|
24
|
+
expect { implicit.value }.to_not raise_error
|
25
|
+
expect { explicit.value }.to_not raise_error
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#required?" do
|
30
|
+
it "returns true if a field is required" do
|
31
|
+
field = Field.new(:field, required: true)
|
32
|
+
expect(field.required?).to be_truthy
|
33
|
+
end
|
34
|
+
|
35
|
+
it "returns false if a field is not required" do
|
36
|
+
field = Field.new(:field, required: false)
|
37
|
+
expect(field.required?).to be_falsey
|
38
|
+
end
|
19
39
|
end
|
20
40
|
end
|
data/spec/form_spec.rb
CHANGED