elabs_matchers 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -1
- data/Gemfile.lock +37 -26
- data/README.md +57 -47
- data/development.txt +26 -0
- data/doc/ElabsMatchers/Helpers/Fixtures.html +33 -23
- data/doc/ElabsMatchers/Helpers/NormalizeKeys.html +222 -0
- data/doc/ElabsMatchers/Helpers/ReloadRecord.html +302 -0
- data/doc/ElabsMatchers/Helpers/SelectYearAndMonth.html +251 -0
- data/doc/ElabsMatchers/Helpers.html +29 -22
- data/doc/ElabsMatchers/Matchers/Allow/AllowMatcher.html +707 -0
- data/doc/ElabsMatchers/Matchers/Allow.html +229 -0
- data/doc/ElabsMatchers/Matchers/ContainHash/ContainHashMatcher.html +506 -0
- data/doc/ElabsMatchers/Matchers/ContainHash.html +222 -0
- data/doc/ElabsMatchers/Matchers/HaveAttribute/HaveAttributeMatcher.html +656 -0
- data/doc/ElabsMatchers/Matchers/HaveAttribute.html +239 -0
- data/doc/ElabsMatchers/Matchers/HaveFields/HaveFieldsMatcher.html +572 -0
- data/doc/ElabsMatchers/Matchers/HaveFields.html +220 -0
- data/doc/ElabsMatchers/Matchers/HaveFlash/HaveFlashMatcher.html +654 -0
- data/doc/ElabsMatchers/Matchers/HaveFlash.html +306 -0
- data/doc/ElabsMatchers/Matchers/HaveFormErrorsOn/HaveFormErrorsOnMatcher.html +678 -0
- data/doc/ElabsMatchers/Matchers/HaveFormErrorsOn.html +236 -0
- data/doc/ElabsMatchers/Matchers/HaveHeader/HaveHeaderMatcher.html +568 -0
- data/doc/ElabsMatchers/Matchers/HaveHeader.html +219 -0
- data/doc/ElabsMatchers/Matchers/HaveImage/HaveImageMatcher.html +592 -0
- data/doc/ElabsMatchers/Matchers/HaveImage.html +219 -0
- data/doc/ElabsMatchers/Matchers/HaveTableRow/HaveTableRowMatcher.html +654 -0
- data/doc/ElabsMatchers/Matchers/HaveTableRow.html +236 -0
- data/doc/ElabsMatchers/Matchers/OnlyInclude/OnlyIncludeMatcher.html +494 -0
- data/doc/ElabsMatchers/Matchers/OnlyInclude.html +221 -0
- data/doc/ElabsMatchers/Matchers/Persist/PersistMatcher.html +586 -0
- data/doc/ElabsMatchers/Matchers/Persist.html +235 -0
- data/doc/ElabsMatchers/Matchers.html +29 -22
- data/doc/ElabsMatchers.html +1144 -21
- data/doc/_index.html +161 -79
- data/doc/class_list.html +12 -6
- data/doc/css/full_list.css +4 -2
- data/doc/css/style.css +50 -44
- data/doc/file.README.html +71 -73
- data/doc/file_list.html +12 -6
- data/doc/frames.html +20 -5
- data/doc/index.html +71 -73
- data/doc/js/app.js +52 -43
- data/doc/js/full_list.js +9 -9
- data/doc/js/jquery.js +4 -16
- data/doc/method_list.html +603 -77
- data/doc/top-level-namespace.html +24 -103
- data/elabs_matchers.gemspec +4 -3
- data/history.txt +15 -0
- data/lib/elabs_matchers/extensions/module.rb +24 -0
- data/lib/elabs_matchers/helpers/fixtures.rb +2 -2
- data/lib/elabs_matchers/helpers/{common.rb → normalize_keys.rb} +3 -4
- data/lib/elabs_matchers/helpers/{orm.rb → reload_record.rb} +9 -6
- data/lib/elabs_matchers/helpers/{capybara.rb → select_year_and_month.rb} +5 -3
- data/lib/elabs_matchers/matchers/allow.rb +130 -0
- data/lib/elabs_matchers/matchers/contain_hash.rb +58 -0
- data/lib/elabs_matchers/matchers/have_attribute.rb +62 -0
- data/lib/elabs_matchers/matchers/have_fields.rb +45 -0
- data/lib/elabs_matchers/matchers/have_flash.rb +65 -0
- data/lib/elabs_matchers/matchers/have_form_errors_on.rb +79 -0
- data/lib/elabs_matchers/matchers/have_header.rb +53 -0
- data/lib/elabs_matchers/matchers/have_image.rb +69 -0
- data/lib/elabs_matchers/matchers/have_table_row.rb +113 -0
- data/lib/elabs_matchers/matchers/only_include.rb +41 -0
- data/lib/elabs_matchers/matchers/persist.rb +42 -0
- data/lib/elabs_matchers/version.rb +1 -1
- data/lib/elabs_matchers.rb +90 -10
- data/spec/elabs_matchers/helpers/fixtures_spec.rb +1 -1
- data/spec/elabs_matchers/helpers/{common_spec.rb → normalize_keys_spec.rb} +2 -2
- data/spec/elabs_matchers/helpers/{orm_spec.rb → reload_record_spec.rb} +3 -2
- data/spec/elabs_matchers/helpers/select_year_and_month_spec.rb +32 -0
- data/spec/elabs_matchers/matchers/{rspec/allow_spec.rb → allow_spec.rb} +5 -4
- data/spec/elabs_matchers/matchers/contain_hash_spec.rb +86 -0
- data/spec/elabs_matchers/matchers/have_attribute_spec.rb +65 -0
- data/spec/elabs_matchers/matchers/have_fields_spec.rb +46 -0
- data/spec/elabs_matchers/matchers/have_flash_spec.rb +97 -0
- data/spec/elabs_matchers/matchers/have_form_errors_on_spec.rb +93 -0
- data/spec/elabs_matchers/matchers/have_header_spec.rb +54 -0
- data/spec/elabs_matchers/matchers/have_image_spec.rb +49 -0
- data/spec/elabs_matchers/matchers/have_table_row_spec.rb +119 -0
- data/spec/elabs_matchers/matchers/only_include_spec.rb +32 -0
- data/spec/elabs_matchers/matchers/persist_spec.rb +21 -0
- data/{lib/elabs_matchers/orm → spec/fixtures}/post.rb +0 -0
- data/spec/spec_helper.rb +19 -8
- data/todo.txt +6 -0
- metadata +104 -48
- data/lib/elabs_matchers/cucumber/common.rb +0 -57
- data/lib/elabs_matchers/helpers/session.rb +0 -81
- data/lib/elabs_matchers/matchers/capybara/common.rb +0 -245
- data/lib/elabs_matchers/matchers/rspec/allow.rb +0 -112
- data/lib/elabs_matchers/matchers/rspec/common.rb +0 -59
- data/lib/elabs_matchers/matchers/rspec/orm.rb +0 -29
- data/spec/elabs_matchers/cucumber/common_spec.rb +0 -49
- data/spec/elabs_matchers/helpers/capybara_spec.rb +0 -32
- data/spec/elabs_matchers/helpers/session_spec.rb +0 -35
- data/spec/elabs_matchers/matchers/capybara/common_spec.rb +0 -202
- data/spec/elabs_matchers/matchers/rspec/common_spec.rb +0 -74
- data/spec/elabs_matchers/matchers/rspec/orm_spec.rb +0 -16
@@ -0,0 +1,41 @@
|
|
1
|
+
module ElabsMatchers
|
2
|
+
module Matchers
|
3
|
+
module OnlyInclude
|
4
|
+
rspec
|
5
|
+
|
6
|
+
class OnlyIncludeMatcher < Struct.new(:elements)
|
7
|
+
attr_reader :actual
|
8
|
+
|
9
|
+
def matches?(actual)
|
10
|
+
@actual = actual
|
11
|
+
elements.uniq.length == elements.length and
|
12
|
+
actual.length == elements.length and
|
13
|
+
elements.all? { |element| actual.include?(element) }
|
14
|
+
end
|
15
|
+
|
16
|
+
def failure_message_for_should
|
17
|
+
"Expected #{actual.inspect} to only include #{elements.inspect}."
|
18
|
+
end
|
19
|
+
|
20
|
+
def failure_message_for_should_not
|
21
|
+
"Expected #{actual.inspect} to not only include #{elements.inspect}, but it did."
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
##
|
26
|
+
#
|
27
|
+
# Asserts if the array contains exactly the supplied elements.
|
28
|
+
# The order of the element do not have to match.
|
29
|
+
#
|
30
|
+
# @param [*Array] elements Comma seperated list of arguments
|
31
|
+
#
|
32
|
+
# Example:
|
33
|
+
# ["foo", "bar"].should only_include("bar", "foo")
|
34
|
+
# ["foo", "bar"].should_not only_include("foo")
|
35
|
+
|
36
|
+
def only_include(*elements)
|
37
|
+
OnlyIncludeMatcher.new(elements)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module ElabsMatchers
|
2
|
+
module Matchers
|
3
|
+
module Persist
|
4
|
+
rspec :type => :model
|
5
|
+
|
6
|
+
class PersistMatcher < Struct.new(:attribute, :value)
|
7
|
+
attr_reader :record
|
8
|
+
|
9
|
+
def matches?(record)
|
10
|
+
record.send(:"#{attribute}=", value)
|
11
|
+
record.save!
|
12
|
+
record = record.class.find(record.id)
|
13
|
+
@final_value = record.send(attribute)
|
14
|
+
|
15
|
+
@final_value == value
|
16
|
+
end
|
17
|
+
|
18
|
+
def failure_message_for_should
|
19
|
+
"Expected #{attribute} to be persisted and retain its value of #{value.inspect} but the value was #{@final_value.inspect}."
|
20
|
+
end
|
21
|
+
|
22
|
+
def failure_message_for_should_not
|
23
|
+
"Expected #{attribute} not to be persisted and retain its value of #{value.inspect} but it did."
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
##
|
28
|
+
#
|
29
|
+
# Asserts if an assigned value persistes in the database.
|
30
|
+
#
|
31
|
+
# @param [Symbol] attribute The name of the attibute to check if it persisted or not
|
32
|
+
# @param [Object] value The value to persist to the attribute
|
33
|
+
#
|
34
|
+
# Example:
|
35
|
+
# post.should persist(:title, "Blog post")
|
36
|
+
|
37
|
+
def persist(attribute, value)
|
38
|
+
PersistMatcher.new(attribute, value)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/elabs_matchers.rb
CHANGED
@@ -1,19 +1,99 @@
|
|
1
|
+
require "rspec"
|
2
|
+
|
1
3
|
module ElabsMatchers
|
2
4
|
require "active_support/core_ext/hash/indifferent_access"
|
5
|
+
require "active_support/core_ext/object/blank"
|
6
|
+
require "active_support/core_ext/array/conversions"
|
3
7
|
require "active_support/inflector"
|
8
|
+
require "rspec"
|
4
9
|
|
5
|
-
|
6
|
-
|
7
|
-
|
10
|
+
require "elabs_matchers/extensions/module"
|
11
|
+
require "elabs_matchers/helpers/fixtures"
|
12
|
+
require "elabs_matchers/helpers/normalize_keys"
|
13
|
+
require "elabs_matchers/helpers/reload_record"
|
14
|
+
require "elabs_matchers/helpers/select_year_and_month"
|
15
|
+
|
16
|
+
require "elabs_matchers/matchers/allow"
|
17
|
+
require "elabs_matchers/matchers/contain_hash"
|
18
|
+
require "elabs_matchers/matchers/have_attribute"
|
19
|
+
require "elabs_matchers/matchers/have_fields"
|
20
|
+
require "elabs_matchers/matchers/have_flash"
|
21
|
+
require "elabs_matchers/matchers/have_form_errors_on"
|
22
|
+
require "elabs_matchers/matchers/have_header"
|
23
|
+
require "elabs_matchers/matchers/have_image"
|
24
|
+
require "elabs_matchers/matchers/have_table_row"
|
25
|
+
require "elabs_matchers/matchers/only_include"
|
26
|
+
require "elabs_matchers/matchers/persist"
|
27
|
+
|
28
|
+
class << self
|
29
|
+
attr_accessor :header_selector, :header_selector_type
|
30
|
+
attr_accessor :attribute_selector, :attribute_selector_type
|
31
|
+
attr_accessor :flash_notice_selector, :flash_notice_selector_type, :flash_alert_selector, :flash_alert_selector_type
|
32
|
+
attr_accessor :form_errors_on_selector
|
33
|
+
attr_accessor :image_selector, :image_selector_type
|
34
|
+
attr_accessor :table_row_selector
|
8
35
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
36
|
+
##
|
37
|
+
#
|
38
|
+
# Configure ElabsMatchers to suit your needs. The spec/spec_helper.rb
|
39
|
+
# file is a good place to put your configurations in.
|
40
|
+
#
|
41
|
+
# ElabsMatchers.configure do |config|
|
42
|
+
# config.header_selector = "//h1"
|
43
|
+
# config.header_selector_type = :xpath
|
44
|
+
# config.image_selector = lambda { |src| "img[src='#{src}']" }
|
45
|
+
# end
|
46
|
+
#
|
47
|
+
# === Configurable options
|
48
|
+
#
|
49
|
+
# [header_selctor = String] The selector to use when finding header tags (Default: "h1,h2")
|
50
|
+
# [header_selector_type = Symbol] The type of selector to use, :css or :xpath (Default: :css)
|
51
|
+
#
|
52
|
+
# [image_selctor = lamda] The selector to use when finding images (Default: see matcher)
|
53
|
+
# [image_selector_type = Symbol] The type of selector to use, :css or :xpath (Default: :css)
|
54
|
+
#
|
55
|
+
# [attribute_selector = lambda] A lambda that takes label and value as arguments and return a selector (Default: see matcher)
|
56
|
+
# [attribute_selector_type = Symbol] The type of selector to use, :css or :xpath (Default: :xpath)
|
57
|
+
#
|
58
|
+
# [flash_notice_selector = String] The selector to use when finding the flash notice (Default: "#flash.notice, #flash .notice, .flash.notice")
|
59
|
+
# [flash_notice_selector_type = Symbol] The type of selector to use, :css or :xpath (Default: :css)
|
60
|
+
# [flash_alert_selector = String] The selector to use when finding the flash alert (Default: "#flash.alert, #flash .alert, .flash.alert")
|
61
|
+
# [flash_alert_selector_type = Symbol] The type of selector to use, :css or :xpath (Default: :css)
|
62
|
+
#
|
63
|
+
# [form_errors_on_selector = String] A xpath expression to be used when finding associated error notices (Default: see matcher)
|
64
|
+
#
|
65
|
+
# [table_row_selector = lambda] A lambda that takes table row return a selector (Default: see matcher)
|
14
66
|
|
15
|
-
|
16
|
-
|
67
|
+
def configure
|
68
|
+
yield self
|
69
|
+
end
|
70
|
+
|
71
|
+
##
|
72
|
+
#
|
73
|
+
# Reset Elabs matchers to use the default configuration.
|
74
|
+
|
75
|
+
def use_default_configuration!
|
76
|
+
configure do |config|
|
77
|
+
config.header_selector = "h1,h2"
|
78
|
+
config.header_selector_type = :css
|
79
|
+
|
80
|
+
config.image_selector = nil
|
81
|
+
config.image_selector_type = :css
|
82
|
+
|
83
|
+
config.attribute_selector = nil
|
84
|
+
config.attribute_selector_type = :xpath
|
85
|
+
|
86
|
+
config.flash_notice_selector = "#flash.notice, #flash .notice, .flash.notice"
|
87
|
+
config.flash_notice_selector_type = :css
|
88
|
+
config.flash_alert_selector = "#flash.alert, #flash .alert, .flash.alert"
|
89
|
+
config.flash_alert_selector_type = :css
|
90
|
+
|
91
|
+
config.form_errors_on_selector = nil
|
92
|
+
|
93
|
+
config.table_row_selector = nil
|
94
|
+
end
|
17
95
|
end
|
18
96
|
end
|
19
97
|
end
|
98
|
+
|
99
|
+
ElabsMatchers.use_default_configuration!
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
|
-
describe ElabsMatchers::Helpers::
|
3
|
+
describe ElabsMatchers::Helpers::NormalizeKeys do
|
4
4
|
describe "normalize_keys" do
|
5
5
|
it "turns the keys into symbols" do
|
6
6
|
normalize_keys("First name" => "Adam").keys.first.should == "first_name"
|
@@ -1,6 +1,7 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
|
+
require "fixtures/post.rb"
|
2
3
|
|
3
|
-
describe ElabsMatchers::Helpers::
|
4
|
+
describe ElabsMatchers::Helpers::ReloadRecord do
|
4
5
|
let(:post) { ElabsMatchers::Orm::Post.create(:title => "New") }
|
5
6
|
|
6
7
|
describe "#save_and_reload" do
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe ElabsMatchers::Helpers::SelectYearAndMonth do
|
4
|
+
let(:page) { Capybara::Session.new(:rack_test, proc { |env| [200, {}, [html]]}) }
|
5
|
+
let(:html) do
|
6
|
+
%Q{
|
7
|
+
<label for="post_date_1i">Date</label>
|
8
|
+
<select id="post_date_1i" name="post[date(1i)]">
|
9
|
+
<option value="2009" selected="selected">2009</option>
|
10
|
+
<option value="2010">2010</option>
|
11
|
+
</select>
|
12
|
+
<select id="post_date_2i" name="post[date(2i)]">
|
13
|
+
<option value="1" selected="selected">January</option>
|
14
|
+
<option value="2">February</option>
|
15
|
+
</select>
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
before do
|
20
|
+
page.extend(ElabsMatchers::Helpers::SelectYearAndMonth)
|
21
|
+
page.visit "/"
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#select_year_and_month" do
|
25
|
+
it "selects the year and momth selects" do
|
26
|
+
page.select_year_and_month("2010", "February", :from => "Date")
|
27
|
+
|
28
|
+
page.find("#post_date_1i").find("option[selected]").text.should == "2010"
|
29
|
+
page.find("#post_date_2i").find("option[selected]").text.should == "February"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -1,6 +1,7 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
|
+
require "fixtures/post"
|
2
3
|
|
3
|
-
describe ElabsMatchers::Matchers::
|
4
|
+
describe ElabsMatchers::Matchers::Allow do
|
4
5
|
let(:post) { ElabsMatchers::Orm::Post.create }
|
5
6
|
subject { post }
|
6
7
|
|
@@ -33,7 +34,7 @@ describe ElabsMatchers::Matchers::Rspec::Allow do
|
|
33
34
|
|
34
35
|
it { expect { should allow("Elabs", "").as(:title) }.to fail_assertion }
|
35
36
|
it { expect { should_not allow("", "Elabs").as(:title) }.to fail_assertion }
|
36
|
-
it {
|
37
|
+
it { should allow("", "Elabs").as(:signature) }
|
37
38
|
end
|
38
39
|
|
39
40
|
context "with several attributes" do
|
@@ -77,4 +78,4 @@ describe ElabsMatchers::Matchers::Rspec::Allow do
|
|
77
78
|
it { expect { should_not allow(9, "9", "9e3", 0.1).as(:price) }.to fail_assertion }
|
78
79
|
end
|
79
80
|
end
|
80
|
-
end
|
81
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe ElabsMatchers::Matchers::ContainHash do
|
4
|
+
describe "#contain_hash" do
|
5
|
+
context "with a simple hash" do
|
6
|
+
subject { { "foo" => "bar", "baz" => "quox" } }
|
7
|
+
|
8
|
+
it "returns true with the given value" do
|
9
|
+
should contain_hash({ "foo" => "bar" })
|
10
|
+
should contain_hash({ "baz" => "quox" })
|
11
|
+
|
12
|
+
expect { should contain_hash({ "foo" => "baz" }) }.to fail_assertion
|
13
|
+
expect { should contain_hash({ "bar" => "bar" }) }.to fail_assertion
|
14
|
+
end
|
15
|
+
|
16
|
+
it "returns false if key or value don't match" do
|
17
|
+
should_not contain_hash({ "foo" => "quox" })
|
18
|
+
should_not contain_hash({ "baz" => "bar" })
|
19
|
+
|
20
|
+
expect { should_not contain_hash({ "foo" => "bar" }) }.to fail_assertion
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "with a simple array" do
|
25
|
+
subject { %w[foo quox] }
|
26
|
+
|
27
|
+
it "returns true with the given value" do
|
28
|
+
should contain_hash(["foo"])
|
29
|
+
should contain_hash(["quox"])
|
30
|
+
should contain_hash(%w[foo quox])
|
31
|
+
|
32
|
+
expect { should contain_hash(["bar"]) }.to fail_assertion
|
33
|
+
end
|
34
|
+
|
35
|
+
it "returns false if the array doesn't contain the given value" do
|
36
|
+
should_not contain_hash(["blah"])
|
37
|
+
expect { should_not contain_hash(["foo"]) }.to fail_assertion
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "with a nested hash" do
|
42
|
+
subject { { "foo" => { "foo1" => "bar1", "foo2" => "bar2" }} }
|
43
|
+
|
44
|
+
it "returns true with the given value" do
|
45
|
+
should contain_hash({ "foo" => { "foo1" => "bar1" }})
|
46
|
+
should contain_hash({ "foo" => { "foo2" => "bar2" }})
|
47
|
+
|
48
|
+
expect { should contain_hash({ "foo" => { "foo1" => "bar2" }}) }.to fail_assertion
|
49
|
+
expect { should contain_hash({ "bar" => { "foo1" => "bar1" }}) }.to fail_assertion
|
50
|
+
expect { should contain_hash({ "foo" => { "foo2" => "bar1" }}) }.to fail_assertion
|
51
|
+
end
|
52
|
+
|
53
|
+
it "returns false if key or value don't match" do
|
54
|
+
should_not contain_hash({ "foo" => { "foo1" => "bar2" }})
|
55
|
+
should_not contain_hash({ "foo" => { "foo2" => "bar1" }})
|
56
|
+
should_not contain_hash({ "foo" => { "monkey" => "baz" }})
|
57
|
+
should_not contain_hash({ "foo" => "monkey" })
|
58
|
+
|
59
|
+
expect { should_not contain_hash({ "foo" => { "foo1" => "bar1" }}) }.to fail_assertion
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context "with a nested array" do
|
64
|
+
subject { { "foo" => ["quox", { "bar" => "baz" }]} }
|
65
|
+
|
66
|
+
it "returns true with the given value" do
|
67
|
+
should contain_hash({ "foo" => [{ "bar" => "baz" }]})
|
68
|
+
should contain_hash({ "foo" => ["quox"]})
|
69
|
+
|
70
|
+
expect { should contain_hash({ "foo" => [{ "bar" => "quox" }] }) }.to fail_assertion
|
71
|
+
expect { should contain_hash({ "foo" => [{ "foo" => "baz" }] }) }.to fail_assertion
|
72
|
+
expect { should contain_hash({ "bar" => [{ "bar" => "baz" }] }) }.to fail_assertion
|
73
|
+
expect { should contain_hash({ "foo" => ["bar"] }) }.to fail_assertion
|
74
|
+
end
|
75
|
+
|
76
|
+
it "returns false if array doesn't contain the given sequence" do
|
77
|
+
should_not contain_hash({ "foo" => [{ "bar" => "quox" }]})
|
78
|
+
should_not contain_hash({ "foo" => ["bar"]})
|
79
|
+
should_not contain_hash({ "foo" => "monkey"})
|
80
|
+
|
81
|
+
expect { should_not contain_hash({ "foo" => [{ "bar" => "baz" }] }) }.to fail_assertion
|
82
|
+
expect { should_not contain_hash({ "foo" => ["quox"] }) }.to fail_assertion
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe ElabsMatchers::Matchers::HaveAttribute, :type => :feature do
|
4
|
+
describe "#have_attribute" do
|
5
|
+
subject { Capybara.string(html) }
|
6
|
+
|
7
|
+
shared_examples "a have attribute matcher" do
|
8
|
+
it "returns true when the label exists with the supplied value" do
|
9
|
+
should have_attribute("Title", "First")
|
10
|
+
should have_attribute("Title", "First")
|
11
|
+
|
12
|
+
expect { should have_attribute("Title", "Last") }.to fail_assertion
|
13
|
+
expect { should have_attribute("Name", "First") }.to fail_assertion
|
14
|
+
end
|
15
|
+
|
16
|
+
it "returns false when the label exists with but the value is wrong" do
|
17
|
+
should_not have_attribute("Title", "Wrong")
|
18
|
+
expect { should_not have_attribute("Title", "First") }.to fail_assertion
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns false when the label does not exist even if the value does" do
|
22
|
+
should_not have_attribute("Wrong", "First")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "using default configuration" do
|
27
|
+
it_behaves_like "a have attribute matcher" do
|
28
|
+
let(:html) do
|
29
|
+
%Q{<div class="show_for post" id="post_1">
|
30
|
+
<p class="wrapper post_status"><strong class="label">Title</strong><br />First</p>
|
31
|
+
<p class="wrapper post_status"><strong class="label">Author</strong><br />Adam</p>
|
32
|
+
</div>}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "configured with a css selector" do
|
38
|
+
before do
|
39
|
+
ElabsMatchers.attribute_selector_type = :css
|
40
|
+
ElabsMatchers.attribute_selector = lambda do |label, value|
|
41
|
+
"a[title='#{label}'] img[alt='#{value}']"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
it_behaves_like "a have attribute matcher" do
|
46
|
+
let(:html) { %Q{<div><a title="Title"><img alt="First" src="/f.png"></a><a title="Author"><img alt="Adam" src="/a.png"></a></div>} }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context "configured with xpath selector" do
|
51
|
+
before do
|
52
|
+
ElabsMatchers.attribute_selector_type = :xpath
|
53
|
+
ElabsMatchers.attribute_selector = lambda do |label, value|
|
54
|
+
XPath.generate do |x|
|
55
|
+
x.descendant(:a)[x.attr(:title).contains(label)][x.contains(value)]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
it_behaves_like "a have attribute matcher" do
|
61
|
+
let(:html) { %Q{<div><a title="Title">First</a><a title="Author">Adam</a></div>} }
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe ElabsMatchers::Matchers::HaveFields, :type => :feature do
|
4
|
+
describe "#have_fields" do
|
5
|
+
let(:html) do
|
6
|
+
Capybara.string(%Q{
|
7
|
+
<form>
|
8
|
+
<label for="author">Author</label>
|
9
|
+
<input type="text" name="author" id="author" value="Adam" />
|
10
|
+
<label for="year">Year</label>
|
11
|
+
<input type="text" name="year" id="year" value="2011" />
|
12
|
+
</form>
|
13
|
+
})
|
14
|
+
end
|
15
|
+
subject { html }
|
16
|
+
|
17
|
+
it "returns true with several fields if both labels and values are correct" do
|
18
|
+
should have_fields("Author" => "Adam", "Year" => "2011")
|
19
|
+
|
20
|
+
expect { should have_fields("Author" => "Adam", "Year" => "2012") }.to fail_assertion
|
21
|
+
expect { should have_fields("Author" => "Adam", "Week" => "2011") }.to fail_assertion
|
22
|
+
end
|
23
|
+
|
24
|
+
it "returns true with one field if both labels and values are correct" do
|
25
|
+
should have_fields("Year" => "2011")
|
26
|
+
expect { should have_fields("Week" => "2011") }.to fail_assertion
|
27
|
+
end
|
28
|
+
|
29
|
+
it "returns false if the label is correct but the value is not" do
|
30
|
+
should_not have_fields("Author" => "David")
|
31
|
+
expect { should_not have_fields("Author" => "Adam") }.to fail_assertion
|
32
|
+
end
|
33
|
+
|
34
|
+
it "returns false if the label is correct but the value is not" do
|
35
|
+
should_not have_fields("Wrong" => "Adam")
|
36
|
+
end
|
37
|
+
|
38
|
+
it "returns false if the one of the pairs is incorrect" do
|
39
|
+
should_not have_fields("Author" => "Goliath", "Year" => "2012")
|
40
|
+
|
41
|
+
expect { should_not have_fields("Author" => "Adam", "Year" => "2012") }.to fail_assertion
|
42
|
+
expect { should_not have_fields("Author" => "Adam", "Year" => "2011") }.to fail_assertion
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|