conformity 0.0.5 → 0.0.7

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: 01f3786cd9944fbc1a8275c48afcc2dc9128ea83
4
- data.tar.gz: f0d8722c3d724f21c3bb712e34057911a7bd6f3a
3
+ metadata.gz: 03f5bb53373a113a0035f5d41f94d396c70f6e58
4
+ data.tar.gz: 880e740b3ba9efd4db77ac939dd5ad72012eca69
5
5
  SHA512:
6
- metadata.gz: 0ec8f708b330e8cb8d75d8e856f9f1b766e97cb2780cf73458c639a577153a299e9a75f7b153098e92a86ee90dbdd58debee712e3ad55e143a31d7add4354a13
7
- data.tar.gz: 643358251d8989f885d6cd189d0ad5fda13402fd3f548420a4bfedb3c17ab2dd66dd24d1b30bf9452f2cf431e013e4379297c5aefc398891df9e886533232396
6
+ metadata.gz: b053d5f3f3eacc49e888927c696252b88dc9bf65ae1bde18d66290c40aa6d4ccba7d476dfb716dac3dc701ca0cd6da99a79b609704bed0be2454303d6729af8b
7
+ data.tar.gz: 208caa041d7abcbfcd5b3b52a6b839a3aae2defb56796fa30b904dd2ccecca5237ddb35b2ff91be8376c5ac508176166128270e8a001e1c9fe81225d11f453f9
@@ -1,16 +1,17 @@
1
1
  module Conformity
2
2
  class Actions
3
- attr_reader :session
3
+ attr_reader :session, :fields
4
4
 
5
5
  ACTIONS = [:visit, :find, :fill_in, :select, :check, :uncheck, :choose,
6
6
  :click_on, :wait]
7
7
 
8
- def initialize(session = Capybara.current_session)
8
+ def initialize(fields, session = Capybara.current_session)
9
+ @fields = fields
9
10
  @session = session
10
11
  end
11
12
 
12
13
  def field(name, options={})
13
- Field.value(name)
14
+ fields.value(name)
14
15
  end
15
16
 
16
17
  def method_missing(name, *args, &block)
@@ -3,29 +3,10 @@ module Conformity
3
3
  attr_reader :name, :options
4
4
  attr_accessor :type
5
5
 
6
- class << self
7
- def find(name)
8
- fields[name]
9
- end
10
-
11
- def value(name)
12
- find(name).value
13
- end
14
-
15
- def fields
16
- @fields ||= {}
17
- end
18
-
19
- def add_field(field)
20
- fields[field.name] = field
21
- end
22
- end
23
-
24
6
  def initialize(name, options = {})
25
7
  @name = name
26
8
  @options = options[:options]
27
9
  @required = options[:required] || false
28
- self.class.add_field(self)
29
10
  end
30
11
 
31
12
  def required?
@@ -0,0 +1,31 @@
1
+ module Conformity
2
+ class Fields
3
+ def fields
4
+ @fields ||= []
5
+ end
6
+
7
+ def add_field(field)
8
+ fields << field
9
+ end
10
+
11
+ def add_new_field(name, opts={})
12
+ add_field(Field.new(name, opts))
13
+ end
14
+
15
+ def field_names
16
+ fields.map { |field| field.name }
17
+ end
18
+
19
+ def set_values(values)
20
+ fields.each_with_index { |field, i| field.value = values[i] }
21
+ end
22
+
23
+ def value(name)
24
+ find(name).value
25
+ end
26
+
27
+ def find(name)
28
+ fields.select { |field| field.name == name }.first
29
+ end
30
+ end
31
+ end
@@ -2,41 +2,40 @@ module Conformity
2
2
  class Form
3
3
  extend Forwardable
4
4
 
5
- attr_reader :actions, :block, :success_conditions
5
+ attr_reader :host, :steps
6
6
 
7
- def_delegators :@success_conditions, :has_content?, :has_status_code?,
7
+ def_delegators :success_conditions, :has_content?, :has_status_code?,
8
8
  :success?
9
+ def_delegators :fields_container, :fields, :field_names
9
10
 
10
- def initialize(host = '', &block)
11
- set_host(host)
12
- @success_conditions = SuccessConditions.new(Capybara.current_session)
13
- @actions = Actions.new
14
- @block = block
15
- instance_eval(&block)
11
+ def initialize(host = '', &steps)
12
+ @host = host
13
+ @steps = steps
14
+ instance_eval(&steps)
16
15
  end
17
16
 
18
- def set_host(host)
19
- Capybara.app_host = host
17
+ def fields_container
18
+ @fields_container ||= Fields.new
20
19
  end
21
20
 
22
- def field(name, opts = {})
23
- fields << Field.new(name, opts)
24
- fields.last
21
+ def actions
22
+ @actions ||= Actions.new(fields_container)
25
23
  end
26
24
 
27
- def fields
28
- @fields ||= []
25
+ def success_conditions
26
+ @success_conditions ||= SuccessConditions.new
29
27
  end
30
28
 
31
- def field_names
32
- fields.map(&:name)
29
+ def field(name, opts = {})
30
+ fields_container.add_new_field(name, opts)
33
31
  end
34
32
 
35
33
  def fill
36
34
  Capybara.current_session.reset!
35
+ set_host(host)
37
36
 
38
37
  begin
39
- actions.instance_eval(&block)
38
+ actions.instance_eval(&steps)
40
39
  rescue => e
41
40
  raise FillError, "#{e.message}"
42
41
  end
@@ -44,8 +43,7 @@ module Conformity
44
43
  end
45
44
 
46
45
  def fill_with(*field_values)
47
- val_enum = field_values.to_enum
48
- fields.each { |field| field.value = val_enum.next }
46
+ fields_container.set_values(field_values)
49
47
  fill
50
48
  end
51
49
 
@@ -57,5 +55,10 @@ module Conformity
57
55
  # so Kernel#select isn't called
58
56
  def select(*args)
59
57
  end
58
+
59
+ private
60
+ def set_host(host)
61
+ Capybara.app_host = host
62
+ end
60
63
  end
61
64
  end
@@ -1,7 +1,7 @@
1
1
  module Conformity
2
2
  class SuccessConditions
3
3
 
4
- def initialize(session)
4
+ def initialize(session = Capybara.current_session)
5
5
  @session = session
6
6
  @conditions = []
7
7
  end
@@ -1,3 +1,3 @@
1
1
  module Conformity
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.7"
3
3
  end
data/lib/conformity.rb CHANGED
@@ -11,6 +11,7 @@ end
11
11
  require 'conformity/actions'
12
12
  require 'conformity/form'
13
13
  require 'conformity/field'
14
+ require 'conformity/fields'
14
15
  require 'conformity/success_conditions'
15
16
 
16
17
  module Conformity
data/spec/actions_spec.rb CHANGED
@@ -6,69 +6,54 @@ require 'conformity/actions'
6
6
  include Conformity
7
7
  describe Conformity::Actions do
8
8
  before :each do
9
- @field = double('field', value: 'quack')
9
+ @fields = double()
10
+ @session = double()
11
+ @actions = Actions.new(@fields, @session)
10
12
  end
11
13
 
12
14
  describe "#field" do
13
15
  it "get's the value of the field" do
14
- actions = Actions.new
15
-
16
- allow(Field).to receive(:value).with(:name) { "Jane Doe" }
17
-
18
- expect(actions.field(:name)).to match("Jane Doe")
16
+ allow(@fields).to receive(:value).with(:name) { "Jane Doe" }
17
+ expect(@actions.field(:name)).to match("Jane Doe")
19
18
  end
20
19
  end
21
20
 
22
21
  describe "#method_missing" do
23
22
  it "delegates action calls to session" do
24
- session = double
25
- actions = Actions.new(session)
26
-
27
- expect(session).to receive(:visit).with("/")
28
- actions.visit('/')
23
+ expect(@session).to receive(:visit).with("/")
24
+ @actions.visit('/')
29
25
  end
30
26
 
31
27
  it "ignores success conditions" do
32
- session = double
33
- actions = Actions.new(session)
34
-
35
- expect { actions.has_status_code?; actions.has_content? }.to_not raise_error
28
+ expect { @actions.has_status_code?; @actions.has_content? }.to_not raise_error
36
29
  end
37
30
  end
38
31
 
39
32
  describe "#select" do
40
33
  it "is called on session" do
41
- session = double
42
- actions = Actions.new(session)
43
-
44
- expect(session).to receive(:select)
45
- actions.select('Yes')
34
+ expect(@session).to receive(:select)
35
+ @actions.select('Yes')
46
36
  end
47
37
 
48
38
  it "is not called on Kernel" do
49
39
  skip "not sure how to test"
50
- session = double
51
- actions = Actions.new(session)
52
-
53
40
  expect(Kernel).to_not receive(:select)
54
- actions.select('Yes')
41
+ @actions.select('Yes')
55
42
  end
56
43
  end
57
44
 
58
45
  describe "logging" do
59
46
  it "calls session to save a screenshot" do
60
- session = double
61
47
  Conformity.configure do |c|
62
48
  c.log_screenshots = true
63
49
  c.screenshots_folder = "."
64
50
  end
65
51
 
66
52
  allow(Time).to receive(:now) { 0 }
67
- allow(session).to receive(:visit)
68
- expect(session).to receive(:save_screenshot).with("./0_visit.png")
53
+ allow(@session).to receive(:visit)
54
+ expect(@session).to receive(:save_screenshot).with("./0_visit.png")
69
55
 
70
- actions = Actions.new(session)
71
- actions.visit('/')
56
+ @actions.visit('/')
72
57
  end
73
58
  end
74
59
  end
data/spec/field_spec.rb CHANGED
@@ -50,23 +50,4 @@ describe Conformity::Field do
50
50
  expect(field.required?).to be_falsey
51
51
  end
52
52
  end
53
-
54
- describe ".find" do
55
- it "returns a field with the given name" do
56
- to_find = Field.new(:a)
57
- Field.new(:b)
58
- Field.new(:c)
59
-
60
- expect(Field.find(:a)).to be(to_find)
61
- end
62
- end
63
-
64
- describe ".value" do
65
- it "returns the value for a field with name" do
66
- field = Field.new(:field)
67
- field.value = "blue"
68
-
69
- expect(Field.value(:field)).to match("blue")
70
- end
71
- end
72
53
  end
@@ -0,0 +1,55 @@
1
+ require_relative 'spec_helper'
2
+ require 'conformity/field'
3
+
4
+ include Conformity
5
+ describe Conformity::Fields do
6
+ before :each do
7
+ @fields = Fields.new
8
+ end
9
+
10
+ describe "#add_field" do
11
+ it "adds a field to fields" do
12
+ field = double()
13
+ @fields.add_field(field)
14
+ expect(@fields.fields).to include(field)
15
+ end
16
+ end
17
+
18
+ describe "#add_new_field" do
19
+ it "adds a new field to fields" do
20
+ @fields.add_new_field(:title, options: ["Ms.", "Mr."])
21
+ allow(Field).to receive(:new) { double("Field", :name => :title) }
22
+ expect(@fields.fields.any? { |f| f.name == :title }).to be_truthy
23
+ end
24
+ end
25
+
26
+ describe "#field_names" do
27
+ it "returns the names of added fields" do
28
+ @fields.add_new_field(:name)
29
+ @fields.add_new_field(:title, options: ["Ms.", "Mr."])
30
+ @fields.add_new_field(:email)
31
+ expect(@fields.field_names).to match([:name, :title, :email])
32
+ end
33
+ end
34
+
35
+ describe "#value" do
36
+ it "returns the value for field name" do
37
+ field = double("Field", :name => :phone_number, value: '867-5309')
38
+ @fields.add_field(field)
39
+ expect(@fields.value(:phone_number)).to match('867-5309')
40
+ end
41
+ end
42
+
43
+ describe "#set_values" do
44
+ it "sets the value of fields" do
45
+ field_a = double()
46
+ field_b = double()
47
+
48
+ allow(@fields).to receive(:fields) { [field_a, field_b] }
49
+ expect(field_a).to receive(:value=).with('1')
50
+ expect(field_b).to receive(:value=).with('2')
51
+
52
+ @fields.set_values(['1', '2'])
53
+ end
54
+ end
55
+ end
data/spec/form_spec.rb CHANGED
@@ -30,33 +30,10 @@ describe Form do
30
30
  end
31
31
 
32
32
  describe '#field' do
33
- it 'should return a field' do
34
- expect(@form.field(:name)).to be_instance_of Field
35
- end
36
- end
37
-
38
- describe '#fields' do
39
- it 'should be empty with no fields' do
40
- expect(@form.fields).to be_empty
41
- end
42
-
43
- it 'should return fields when there are fields' do
44
- @form.field(:name)
45
- @form.field(:state, options: ["NY", "CA"])
46
-
47
- expect(@form.fields).to_not be_empty
48
- expect(@form.fields.all? { |field| field.class == Field }).to be_truthy
49
- end
50
- end
51
-
52
- describe '#field_names' do
53
- it 'lists the field names' do
54
- form = Form.new do
55
- fill_in 'name', with: field(:name)
56
- choose field(:state, options: ['NY', 'CA'])
57
- end
58
-
59
- expect(form.field_names).to match([:name, :state])
33
+ it "should delegate to fields_container" do
34
+ args = :name, { options: ['a', 'b'] }
35
+ expect(@form.fields_container).to receive(:add_new_field).with(*args)
36
+ @form.field(*args)
60
37
  end
61
38
  end
62
39
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: conformity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nikias Kalpaxis
@@ -68,11 +68,13 @@ files:
68
68
  - lib/conformity.rb
69
69
  - lib/conformity/actions.rb
70
70
  - lib/conformity/field.rb
71
+ - lib/conformity/fields.rb
71
72
  - lib/conformity/form.rb
72
73
  - lib/conformity/success_conditions.rb
73
74
  - lib/conformity/version.rb
74
75
  - spec/actions_spec.rb
75
76
  - spec/field_spec.rb
77
+ - spec/fields_spec.rb
76
78
  - spec/form_spec.rb
77
79
  - spec/spec_helper.rb
78
80
  - spec/success_conditions_spec.rb
@@ -103,6 +105,7 @@ summary: Automates form submissions by building upon Capybara.
103
105
  test_files:
104
106
  - spec/actions_spec.rb
105
107
  - spec/field_spec.rb
108
+ - spec/fields_spec.rb
106
109
  - spec/form_spec.rb
107
110
  - spec/spec_helper.rb
108
111
  - spec/success_conditions_spec.rb