conformity 0.0.2 → 0.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 011dcfc1a2e284d37c12b61ed27df6e0c76a25ef
4
- data.tar.gz: 26b680569448f9dd54a27343a1fb5c19018e60b9
3
+ metadata.gz: 06a1ee41845235c2c6a610c633900b0965f29da3
4
+ data.tar.gz: bb8a8354bc42db8784e585f41a0cddb6b0efa87a
5
5
  SHA512:
6
- metadata.gz: 85cc2036f76c48e0e97bc065bee20c972bb82f6e8fae30244e8cde9d64e5ba8499a95a5440eef27b79fcaa89f22e905688bd5346a023fbdc6a0f8a480e4626ac
7
- data.tar.gz: 6a916d04c39029fce898126e76fe1b8d22d658c20d36c26bcc0f0b7232fa22cb4415ffb6949d292a370fb7261b10ce6e7fef29e6605f75ed77e43c65afec03e6
6
+ metadata.gz: fc1499b750d08250a1814a584d25042e54edab27dffde93b3d8f438daa6d916376614e77faefd54ef2a92f456a5cca19ba5cfb95d5dbbf18f6c0bef25bc9384d
7
+ data.tar.gz: e5075bccf2989f0852bae4fdaa12461b4bb82c005db9b0e6fb1bca8dc3836c6a04dd9207ac52743c11dd0bf6364b5e3db38d9d3baf39217c73176c14c8b7fd84
@@ -5,7 +5,7 @@ module Conformity
5
5
  attr_accessor :type
6
6
 
7
7
  def initialize(name, options = {})
8
- @name = name.to_sym
8
+ @name = name
9
9
  @options = options[:options]
10
10
  end
11
11
 
@@ -1,10 +1,16 @@
1
1
  module Conformity
2
2
  class Form
3
+ extend Forwardable
4
+
3
5
  METHODS = [:visit, :find, :fill_in, :select, :check, :uncheck, :choose,
4
6
  :click_on, :wait]
5
7
 
8
+ def_delegators :@success_conditions, :has_content?, :has_status_code?,
9
+ :success?
10
+
6
11
  def initialize(host = '', &block)
7
12
  set_host(host)
13
+ @success_conditions = SuccessConditions.new(Capybara.current_session)
8
14
  instance_eval(&block) if block
9
15
  end
10
16
 
@@ -0,0 +1,32 @@
1
+ module Conformity
2
+ class SuccessConditions
3
+
4
+ def initialize(session)
5
+ @session = session
6
+ @conditions = []
7
+ end
8
+
9
+ def has_content?(content)
10
+ add_condition do
11
+ session.has_content?(content)
12
+ end
13
+ end
14
+
15
+ def has_status_code?(status_code)
16
+ add_condition do
17
+ session.status_code == status_code
18
+ end
19
+ end
20
+
21
+ def success?
22
+ conditions.all? { |condition| condition.call() }
23
+ end
24
+
25
+ private
26
+ attr_reader :session, :conditions
27
+
28
+ def add_condition(&block)
29
+ conditions << block
30
+ end
31
+ end
32
+ end
@@ -1,3 +1,3 @@
1
1
  module Conformity
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/conformity.rb CHANGED
@@ -11,6 +11,7 @@ end
11
11
  require 'conformity/action'
12
12
  require 'conformity/form'
13
13
  require 'conformity/field'
14
+ require 'conformity/success_conditions'
14
15
 
15
16
  module Conformity
16
17
  class ConformityError < StandardError; end
@@ -0,0 +1,48 @@
1
+ require_relative 'spec_helper'
2
+ require 'conformity/success_conditions'
3
+
4
+
5
+ describe SuccessConditions do
6
+ before :each do
7
+ @session = double()
8
+ @sc = SuccessConditions.new(@session)
9
+ end
10
+
11
+ describe '#has_content' do
12
+ it 'delegates to the session' do
13
+ @sc.has_content? 'Content'
14
+ expect(@session).to receive(:has_content?).with('Content')
15
+ @sc.success?
16
+ end
17
+ end
18
+
19
+ describe '#has_status_code' do
20
+ it 'delegates to the session' do
21
+ @sc.has_status_code? 200
22
+ expect(@session).to receive(:status_code)
23
+ @sc.success?
24
+ end
25
+ end
26
+
27
+ describe '#success?' do
28
+ it 'returns true for passing conditions' do
29
+ @sc.has_content? 'Content'
30
+ @sc.has_status_code? 200
31
+
32
+ allow(@session).to receive(:has_content?) { true }
33
+ allow(@session).to receive(:status_code) { 200 }
34
+
35
+ expect(@sc.success?).to be_truthy
36
+ end
37
+
38
+ it 'returns false for failing conditions' do
39
+ @sc.has_content? 'Content'
40
+ @sc.has_status_code? 200
41
+
42
+ allow(@session).to receive(:has_content?) { false }
43
+ allow(@session).to receive(:status_code) { 404 }
44
+
45
+ expect(@sc.success?).to be_falsy
46
+ end
47
+ end
48
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: conformity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nikias Kalpaxis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-06 00:00:00.000000000 Z
11
+ date: 2014-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capybara
@@ -69,11 +69,13 @@ files:
69
69
  - lib/conformity/action.rb
70
70
  - lib/conformity/field.rb
71
71
  - lib/conformity/form.rb
72
+ - lib/conformity/success_conditions.rb
72
73
  - lib/conformity/version.rb
73
74
  - spec/action_spec.rb
74
75
  - spec/field_spec.rb
75
76
  - spec/form_spec.rb
76
77
  - spec/spec_helper.rb
78
+ - spec/success_conditions_spec.rb
77
79
  homepage: https://github.com/nhjk/conformity
78
80
  licenses:
79
81
  - MIT
@@ -103,3 +105,4 @@ test_files:
103
105
  - spec/field_spec.rb
104
106
  - spec/form_spec.rb
105
107
  - spec/spec_helper.rb
108
+ - spec/success_conditions_spec.rb