conformity 0.0.1
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 +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +46 -0
- data/Rakefile +1 -0
- data/conformity.gemspec +25 -0
- data/lib/conformity/action.rb +34 -0
- data/lib/conformity/field.rb +20 -0
- data/lib/conformity/form.rb +65 -0
- data/lib/conformity/version.rb +3 -0
- data/lib/conformity.rb +29 -0
- data/spec/action_spec.rb +39 -0
- data/spec/field_spec.rb +20 -0
- data/spec/form_spec.rb +87 -0
- data/spec/spec_helper.rb +3 -0
- metadata +105 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 67792e30b38df5c2c9f4b1e501f2715fffcef248
|
4
|
+
data.tar.gz: adf7d031b5582ca28890ee7b333f126120597b9f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4cd7f9e5883d107d734b50cdefad9f46ef514f05fcbf4902c2a1fac5a95661baa10d9d840c0c9c6be7667309b579d421be5e182c60323e5ee3630ef2eab53732
|
7
|
+
data.tar.gz: 64bbcbd7124e7fc5cf6bb28ce39b8b0c43868cd14743aba1dca48231248666ec80f3ece519fc807fe950d98ec067cf5cd28a69be2e515c5ffa6a9eb0d179de81
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Nikias Kalpaxis
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# Conformity
|
2
|
+
|
3
|
+
Created mainly for use with the [contact-congress](https://github.com/unitedstates/contact-congress) project.
|
4
|
+
Uses capybara with the addition of a Form class and a #field method that lets you fill out a form with different inputs each time.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'conformity'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install conformity
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
include Conformity
|
24
|
+
|
25
|
+
form = Form.new('http://www.google.com/') do
|
26
|
+
visit '/'
|
27
|
+
fill_in 'q', with: field(:query)
|
28
|
+
click_on 'Google Search'
|
29
|
+
end
|
30
|
+
|
31
|
+
form.field_names
|
32
|
+
# => [:query]
|
33
|
+
|
34
|
+
# returns Capybara::Session on success and raises FillError on failure
|
35
|
+
form.fill_with('ruby')
|
36
|
+
form.fill_with('rails')
|
37
|
+
form.fill_with('news')
|
38
|
+
```
|
39
|
+
|
40
|
+
## Contributing
|
41
|
+
|
42
|
+
1. Fork it ( http://github.com/<my-github-username>/conformity/fork )
|
43
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
44
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
45
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
46
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/conformity.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'conformity/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "conformity"
|
8
|
+
spec.version = Conformity::VERSION
|
9
|
+
spec.authors = ["Nikias Kalpaxis"]
|
10
|
+
spec.email = ["kalpaxisn@gmail.com"]
|
11
|
+
spec.summary = %q{Automates form submissions by building upon Capybara.}
|
12
|
+
spec.description = %q{}
|
13
|
+
spec.homepage = "https://github.com/nhjk/conformity"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency "capybara", "~> 2.3"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Conformity
|
2
|
+
class Action
|
3
|
+
include Capybara::DSL
|
4
|
+
|
5
|
+
attr_reader :name, :args, :block
|
6
|
+
|
7
|
+
def initialize(name, args = [], block = nil)
|
8
|
+
@name = name
|
9
|
+
@args = args
|
10
|
+
@block = block
|
11
|
+
end
|
12
|
+
|
13
|
+
def field
|
14
|
+
@field ||= case name
|
15
|
+
when :fill_in then args.last[:with]
|
16
|
+
when :choose then args.first
|
17
|
+
when :select then args.first
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def run
|
22
|
+
case name
|
23
|
+
when :fill_in then args.last[:with] = field.value
|
24
|
+
when :choose then args.first = field.value
|
25
|
+
when :select then args.first = field.value
|
26
|
+
end if field
|
27
|
+
|
28
|
+
result = send(name, *args, &block)
|
29
|
+
if !result && result['status'] == 'fail'
|
30
|
+
raise ActionError, "Capybara status: #{result}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Conformity
|
2
|
+
class Field
|
3
|
+
attr_reader :name
|
4
|
+
attr_writer :value
|
5
|
+
attr_accessor :type
|
6
|
+
|
7
|
+
def initialize(name, options = {})
|
8
|
+
@name = name.to_sym
|
9
|
+
@options = options[:options]
|
10
|
+
end
|
11
|
+
|
12
|
+
def value
|
13
|
+
if @value
|
14
|
+
@value
|
15
|
+
else
|
16
|
+
raise FieldError, "Field '#{name}' not set"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Conformity
|
2
|
+
class Form
|
3
|
+
METHODS = [:visit, :find, :fill_in, :select, :check, :uncheck, :choose,
|
4
|
+
:click_on, :wait]
|
5
|
+
|
6
|
+
def initialize(host = '', &block)
|
7
|
+
set_host(host)
|
8
|
+
instance_eval(&block) if block
|
9
|
+
end
|
10
|
+
|
11
|
+
def set_host(host)
|
12
|
+
Capybara.app_host = host
|
13
|
+
end
|
14
|
+
|
15
|
+
def field(name, opts = {})
|
16
|
+
fields << Field.new(name, opts)
|
17
|
+
fields.last
|
18
|
+
end
|
19
|
+
|
20
|
+
def fields
|
21
|
+
@fields ||= []
|
22
|
+
end
|
23
|
+
|
24
|
+
def field_names
|
25
|
+
fields.map(&:name)
|
26
|
+
end
|
27
|
+
|
28
|
+
def fill
|
29
|
+
Capybara.current_session.reset!
|
30
|
+
|
31
|
+
begin
|
32
|
+
actions.each(&:run)
|
33
|
+
rescue => e
|
34
|
+
raise FillError, "#{e.message}"
|
35
|
+
end
|
36
|
+
Capybara.page
|
37
|
+
end
|
38
|
+
|
39
|
+
def fill_with(*field_values)
|
40
|
+
val_enum = field_values.to_enum
|
41
|
+
fields.each { |field| field.value = val_enum.next }
|
42
|
+
fill
|
43
|
+
end
|
44
|
+
|
45
|
+
def method_missing(name, *args, &block)
|
46
|
+
if METHODS.include?(name)
|
47
|
+
action = Action.new(name, args, block)
|
48
|
+
|
49
|
+
case action.name
|
50
|
+
when :fill_in then action.field.type = :text
|
51
|
+
when :choose then action.field.type = :radio
|
52
|
+
when :select then action.field.type = :select
|
53
|
+
end
|
54
|
+
|
55
|
+
actions << action
|
56
|
+
else
|
57
|
+
super
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def actions
|
62
|
+
@actions ||= []
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/lib/conformity.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'conformity/version'
|
2
|
+
require 'capybara'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'capybara/poltergeist'
|
6
|
+
poltergeist = true
|
7
|
+
rescue Gem::LoadError
|
8
|
+
poltergeist = false
|
9
|
+
end
|
10
|
+
|
11
|
+
require 'conformity/action'
|
12
|
+
require 'conformity/form'
|
13
|
+
require 'conformity/field'
|
14
|
+
|
15
|
+
module Conformity
|
16
|
+
class ConformityError < StandardError; end
|
17
|
+
class ActionError < ConformityError; end
|
18
|
+
class FieldError < ConformityError; end
|
19
|
+
class FillError < ConformityError; end
|
20
|
+
end
|
21
|
+
|
22
|
+
Capybara.configure do |config|
|
23
|
+
config.run_server = false
|
24
|
+
if poltergeist
|
25
|
+
config.default_driver = :poltergeist
|
26
|
+
else
|
27
|
+
config.default_driver = :selenium
|
28
|
+
end
|
29
|
+
end
|
data/spec/action_spec.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
require 'conformity/action'
|
3
|
+
|
4
|
+
|
5
|
+
describe Conformity::Action do
|
6
|
+
before :each do
|
7
|
+
@field = double('field', value: 'quack')
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#field' do
|
11
|
+
it 'locates the field duck type for fill_in' do
|
12
|
+
action = Action.new(:fill_in, ['#name', with: @field])
|
13
|
+
|
14
|
+
expect(action.field).to respond_to(:value)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'locates the field duck type for choose' do
|
18
|
+
action = Action.new(:choose, [@field])
|
19
|
+
|
20
|
+
expect(action.field).to respond_to(:value)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'locates the field duck type for select' do
|
24
|
+
action = Action.new(:select, [@field])
|
25
|
+
|
26
|
+
expect(action.field).to respond_to(:value)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#run' do
|
31
|
+
it 'delegates to Capybara::DSL' do
|
32
|
+
skip
|
33
|
+
action = Action.new(:click_on, ['#submit'])
|
34
|
+
|
35
|
+
expect(Capybara::DSL).to receive(:check).with('#submit')
|
36
|
+
action.run
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/spec/field_spec.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
require 'conformity/field'
|
3
|
+
|
4
|
+
include Conformity
|
5
|
+
describe Conformity::Field do
|
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
|
+
it "returns a value when there's a value" do
|
14
|
+
field = Field.new('field')
|
15
|
+
field.value = :value
|
16
|
+
|
17
|
+
expect(field.value).to equal(:value)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/spec/form_spec.rb
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
require 'conformity/form'
|
3
|
+
|
4
|
+
|
5
|
+
describe Conformity::Form do
|
6
|
+
before :each do
|
7
|
+
@form = Form.new
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#field' do
|
11
|
+
it 'should return a field' do
|
12
|
+
expect(@form.field(:name)).to be_instance_of Field
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#fields' do
|
17
|
+
it 'should be empty with no fields' do
|
18
|
+
expect(@form.fields).to be_empty
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should return fields when there are fields' do
|
22
|
+
@form.field(:name)
|
23
|
+
@form.field(:state, options: ["NY", "CA"])
|
24
|
+
|
25
|
+
expect(@form.fields).to_not be_empty
|
26
|
+
expect(@form.fields.all? { |field| field.class == Field }).to be_truthy
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#field_names' do
|
31
|
+
it 'lists the field names' do
|
32
|
+
form = Form.new do
|
33
|
+
fill_in 'name', with: field(:name)
|
34
|
+
choose field(:state, options: ['NY', 'CA'])
|
35
|
+
end
|
36
|
+
|
37
|
+
expect(form.field_names).to match([:name, :state])
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '#fill' do
|
42
|
+
it 'runs the actions' do
|
43
|
+
skip "didn't write test yet!"
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'raises FillError on failure' do
|
47
|
+
form = Form.new do
|
48
|
+
fill_in 'name', with: field(:name)
|
49
|
+
click_on 'submit'
|
50
|
+
end
|
51
|
+
|
52
|
+
expect { form.fill_with('Jane Doe') }.to raise_error(FillError)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe '#method_missing' do
|
57
|
+
it 'does not execute actions immediately' do
|
58
|
+
@form.fill_in "#some_id", with: @form.field(:name)
|
59
|
+
expect(Capybara::DSL).to_not receive(:fill_in)
|
60
|
+
end
|
61
|
+
|
62
|
+
describe 'field types' do
|
63
|
+
it 'sets the field type for fill_in' do
|
64
|
+
field = double
|
65
|
+
expect(field).to receive(:type=).with(:text)
|
66
|
+
|
67
|
+
@form.fill_in :name, with: field
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'sets the field type for choose' do
|
71
|
+
field = double
|
72
|
+
expect(field).to receive(:type=).with(:radio)
|
73
|
+
|
74
|
+
@form.choose field
|
75
|
+
end
|
76
|
+
|
77
|
+
# this tests fails and I don't know why! (rspec's fault not mine.. I think)
|
78
|
+
it 'sets the field type for select' do
|
79
|
+
skip "RSpec's fault"
|
80
|
+
field = double
|
81
|
+
expect(field).to receive(:type=).with(:select)
|
82
|
+
|
83
|
+
@form.select field
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: conformity
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nikias Kalpaxis
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: capybara
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.5'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: ''
|
56
|
+
email:
|
57
|
+
- kalpaxisn@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- conformity.gemspec
|
68
|
+
- lib/conformity.rb
|
69
|
+
- lib/conformity/action.rb
|
70
|
+
- lib/conformity/field.rb
|
71
|
+
- lib/conformity/form.rb
|
72
|
+
- lib/conformity/version.rb
|
73
|
+
- spec/action_spec.rb
|
74
|
+
- spec/field_spec.rb
|
75
|
+
- spec/form_spec.rb
|
76
|
+
- spec/spec_helper.rb
|
77
|
+
homepage: https://github.com/nhjk/conformity
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
metadata: {}
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 2.2.2
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: Automates form submissions by building upon Capybara.
|
101
|
+
test_files:
|
102
|
+
- spec/action_spec.rb
|
103
|
+
- spec/field_spec.rb
|
104
|
+
- spec/form_spec.rb
|
105
|
+
- spec/spec_helper.rb
|