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,97 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe ElabsMatchers::Matchers::HaveFlash, :type => :feature do
|
4
|
+
subject { Capybara.string(html + "<h1>Elabs</h1>") }
|
5
|
+
|
6
|
+
describe "#have_flash_notice" do
|
7
|
+
shared_examples "a have flash notice matcher" do
|
8
|
+
it "returns true if given the content of the flash notice" do
|
9
|
+
should have_flash_notice("Success")
|
10
|
+
expect { should have_flash_notice("Elabs") }.to fail_assertion
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns false if given content outside the flash notice" do
|
14
|
+
should_not have_flash_notice("Elabs")
|
15
|
+
expect { should_not have_flash_notice("Success") }.to fail_assertion
|
16
|
+
end
|
17
|
+
|
18
|
+
it "returns false if the content doesn't exist on the page" do
|
19
|
+
should_not have_flash_notice("Failure")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "with default configuration" do
|
24
|
+
it_behaves_like "a have flash notice matcher" do
|
25
|
+
let(:html) { %Q{<div id="flash" class="notice">Success</div>} }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "configured with xpath selector" do
|
30
|
+
before do
|
31
|
+
ElabsMatchers.flash_notice_selector_type = :xpath
|
32
|
+
ElabsMatchers.flash_notice_selector = XPath.descendant(:div)[XPath.attr(:class).contains("flash-notice")].to_s
|
33
|
+
end
|
34
|
+
|
35
|
+
it_behaves_like "a have flash notice matcher" do
|
36
|
+
let(:html) { %Q{<div class="flash-notice">Success</div>} }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "configured with xpath selector" do
|
41
|
+
before do
|
42
|
+
ElabsMatchers.flash_notice_selector_type = :css
|
43
|
+
ElabsMatchers.flash_notice_selector = ".flash-notice"
|
44
|
+
end
|
45
|
+
|
46
|
+
it_behaves_like "a have flash notice matcher" do
|
47
|
+
let(:html) { %Q{<div class="flash-notice">Success</div>} }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "#have_flash_alert" do
|
53
|
+
shared_examples "a have flash alert matcher" do
|
54
|
+
it "returns true if given the content of the flash alert" do
|
55
|
+
should have_flash_alert("Failure")
|
56
|
+
expect { should have_flash_alert("Elabs") }.to fail_assertion
|
57
|
+
end
|
58
|
+
|
59
|
+
it "returns false if given content outside the flash alert" do
|
60
|
+
should_not have_flash_alert("Elabs")
|
61
|
+
expect { should_not have_flash_alert("Failure") }.to fail_assertion
|
62
|
+
end
|
63
|
+
|
64
|
+
it "returns false if the content doesn't exist on the page" do
|
65
|
+
should_not have_flash_alert("Success")
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context "with default configuration" do
|
70
|
+
it_behaves_like "a have flash alert matcher" do
|
71
|
+
let(:html) { %Q{<div id="flash" class="alert">Failure</div>} }
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context "configured with xpath selector" do
|
76
|
+
before do
|
77
|
+
ElabsMatchers.flash_alert_selector_type = :xpath
|
78
|
+
ElabsMatchers.flash_alert_selector = XPath.descendant(:div)[XPath.attr(:class).contains("flash-alert")].to_s
|
79
|
+
end
|
80
|
+
|
81
|
+
it_behaves_like "a have flash alert matcher" do
|
82
|
+
let(:html) { %Q{<div class="flash-alert">Failure</div>} }
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
context "configured with xpath selector" do
|
87
|
+
before do
|
88
|
+
ElabsMatchers.flash_alert_selector_type = :css
|
89
|
+
ElabsMatchers.flash_alert_selector = ".flash-alert"
|
90
|
+
end
|
91
|
+
|
92
|
+
it_behaves_like "a have flash alert matcher" do
|
93
|
+
let(:html) { %Q{<div class="flash-alert">Failure</div>} }
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe ElabsMatchers::Matchers::HaveFormErrorsOn, :type => :feature do
|
4
|
+
subject do
|
5
|
+
Capybara.string("<form>" + html + "</form>")
|
6
|
+
end
|
7
|
+
|
8
|
+
shared_examples "a form error matcher" do
|
9
|
+
it "returns true if the label and the error message is correct" do
|
10
|
+
should have_form_errors_on("Name", "can't be blank")
|
11
|
+
|
12
|
+
expect { should have_form_errors_on("Name", "must be royal") }.to fail_assertion
|
13
|
+
expect { should have_form_errors_on("Message", "can't be blank") }.to fail_assertion
|
14
|
+
end
|
15
|
+
|
16
|
+
it "returns false if the label is correct by the error message is wrong" do
|
17
|
+
should_not have_form_errors_on("Name", "Not good enough")
|
18
|
+
expect { should_not have_form_errors_on("Name", "can't be blank") }.to fail_assertion
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns false if the label is wrong by the error message is correct" do
|
22
|
+
should_not have_form_errors_on("Author", "can't be blank")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#have_form_errors_on" do
|
27
|
+
context "with error as sibling to input" do
|
28
|
+
it_behaves_like "a form error matcher" do
|
29
|
+
let(:html) { %Q{
|
30
|
+
<span class="error">can't be blank</span>
|
31
|
+
<label for="name">Name</label>
|
32
|
+
<input type="text" name="name" id="name" value="" /> }
|
33
|
+
}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "with input nested in label" do
|
38
|
+
it_behaves_like "a form error matcher" do
|
39
|
+
let(:html) { %Q{
|
40
|
+
<label for="name">
|
41
|
+
<input type="text" name="name" id="name" value="" />
|
42
|
+
Name
|
43
|
+
</label>
|
44
|
+
<span class="error">can't be blank</span>}
|
45
|
+
}
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context "with error span outside input container" do
|
51
|
+
it_behaves_like "a form error matcher" do
|
52
|
+
let(:html) { %Q{
|
53
|
+
<div class="input string required field_with_errors">
|
54
|
+
<fieldset>
|
55
|
+
<label for="name">Name</label>
|
56
|
+
<input id="name" name="name" type="text" value="">
|
57
|
+
</fieldset>
|
58
|
+
<span class="error">can't be blank</span>
|
59
|
+
</div> }
|
60
|
+
}
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context "with twitter bootstrap markup normal inputs" do
|
65
|
+
it_behaves_like "a form error matcher" do
|
66
|
+
let(:html) { %Q{
|
67
|
+
<div class="control-group error">
|
68
|
+
<label for="name">Name</label>
|
69
|
+
<div class="controls">
|
70
|
+
<input id="name" name="name" type="text" value="">
|
71
|
+
<p>can't be blank</p>
|
72
|
+
</div>
|
73
|
+
</div>}
|
74
|
+
}
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context "with custom configured xpath selector" do
|
79
|
+
before do
|
80
|
+
ElabsMatchers.form_errors_on_selector = %Q{..//..//li[contains(@class,'error')]}
|
81
|
+
end
|
82
|
+
|
83
|
+
it_behaves_like "a form error matcher" do
|
84
|
+
let(:html) { %Q{
|
85
|
+
<ul>
|
86
|
+
<li><label for="name">Name</label></li>
|
87
|
+
<li><input type="text" name="name" id="name" value="" /></li>
|
88
|
+
<li class="error">can't be blank</li>
|
89
|
+
</ul>}
|
90
|
+
}
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe ElabsMatchers::Matchers::HaveHeader, :type => :feature do
|
4
|
+
describe "#have_header" do
|
5
|
+
let(:html) { Capybara.string(%Q{<div><h1>Elabs</h1><h2>Bespoke</h2><h3>Development</h3></div>}) }
|
6
|
+
subject { html }
|
7
|
+
|
8
|
+
it "returns true if given the content of a h1 tag" do
|
9
|
+
should have_header("Elabs")
|
10
|
+
expect { should have_header("Development") }.to fail_assertion
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns true if given the content of a h2 tag" do
|
14
|
+
should have_header("Bespoke")
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns false if given the content of a h3 tag" do
|
18
|
+
should_not have_header("Development")
|
19
|
+
|
20
|
+
expect { should_not have_header("Elabs") }.to fail_assertion
|
21
|
+
expect { should_not have_header("Bespoke") }.to fail_assertion
|
22
|
+
end
|
23
|
+
|
24
|
+
it "returns false if the content doesn't exist on the page" do
|
25
|
+
should_not have_header("Bugs")
|
26
|
+
end
|
27
|
+
|
28
|
+
shared_examples "a configured have header matcher" do
|
29
|
+
it "returns true if given the content of a h3" do
|
30
|
+
should have_header("Development")
|
31
|
+
expect { should_not have_header("Development") }.to fail_assertion
|
32
|
+
end
|
33
|
+
|
34
|
+
it "returns false if given the content of a h2" do
|
35
|
+
should_not have_header("Bespoke")
|
36
|
+
expect { should have_header("Bespoke") }.to fail_assertion
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "configured with a css selector" do
|
41
|
+
before { ElabsMatchers.header_selector = "h1,h3" }
|
42
|
+
it_behaves_like "a configured have header matcher"
|
43
|
+
end
|
44
|
+
|
45
|
+
context "configured with xpath selector" do
|
46
|
+
before do
|
47
|
+
ElabsMatchers.header_selector_type = :xpath
|
48
|
+
ElabsMatchers.header_selector = XPath.descendant(:h1, :h3).to_s
|
49
|
+
end
|
50
|
+
|
51
|
+
it_behaves_like "a configured have header matcher"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe ElabsMatchers::Matchers::HaveImage, :type => :feature do
|
4
|
+
describe "#have_image" do
|
5
|
+
subject { Capybara.string("<div>" + html + "</div>") }
|
6
|
+
|
7
|
+
shared_examples "a have image matcher" do
|
8
|
+
it "returns true if the image exists on the page" do
|
9
|
+
should have_image("Logo")
|
10
|
+
expect { should have_image("Avatar") }.to fail_assertion
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns false if the image doesn't exist on the page" do
|
14
|
+
should_not have_image("Avatar")
|
15
|
+
expect { should_not have_image("Logo") }.to fail_assertion
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "with default configuration" do
|
20
|
+
it_behaves_like "a have image matcher" do
|
21
|
+
let(:html) { %Q{<img src="logo.png" alt="Logo" />} }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "configured with css selector" do
|
26
|
+
before do
|
27
|
+
ElabsMatchers.image_selector_type = :css
|
28
|
+
ElabsMatchers.image_selector = lambda { |src| "img[class='#{src}']" }
|
29
|
+
end
|
30
|
+
|
31
|
+
it_behaves_like "a have image matcher" do
|
32
|
+
let(:html) { %Q{<img src="logo.png" class="Logo" />} }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "configured with xpath selector" do
|
37
|
+
before do
|
38
|
+
ElabsMatchers.image_selector_type = :xpath
|
39
|
+
ElabsMatchers.image_selector = lambda do |src|
|
40
|
+
"//img[@class='#{src}']"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
it_behaves_like "a have image matcher" do
|
45
|
+
let(:html) { %Q{<img src="logo.png" class="Logo" />} }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe ElabsMatchers::Matchers::HaveTableRow, :type => :feature do
|
4
|
+
describe "#have_table_row" do
|
5
|
+
let(:header) { %Q{
|
6
|
+
<caption>Posts</caption>
|
7
|
+
<thead>
|
8
|
+
<tr><th>Title</th><th>Author</th></tr>
|
9
|
+
</thead>} }
|
10
|
+
subject { Capybara.string("<table>" + header + "<tbody>" + html + "</tbody></table>") }
|
11
|
+
|
12
|
+
shared_examples "a table row matcher" do
|
13
|
+
it "returns true when the one of the pairs in the row exists" do
|
14
|
+
should have_table_row("Posts", "Title" => "First")
|
15
|
+
expect { should have_table_row("Posts", "Foo" => "First") }.to fail_assertion
|
16
|
+
end
|
17
|
+
|
18
|
+
it "returns true when the all of the pairs in the row exists" do
|
19
|
+
should have_table_row("Posts", "Title" => "First", "Author" => "Adam")
|
20
|
+
expect { should have_table_row("Posts", "Title" => "First", "Author" => "Second") }.to fail_assertion
|
21
|
+
end
|
22
|
+
|
23
|
+
it "returns false when the header is wrong and the value is correct" do
|
24
|
+
should_not have_table_row("Posts", "Label" => "First")
|
25
|
+
expect { should_not have_table_row("Posts", "Title" => "First") }.to fail_assertion
|
26
|
+
end
|
27
|
+
|
28
|
+
it "returns false when the header is correct and the value is wrong" do
|
29
|
+
should_not have_table_row("Posts", "Title" => "Forth")
|
30
|
+
expect { should have_table_row("Posts", "Author" => "First") }.to fail_assertion
|
31
|
+
end
|
32
|
+
|
33
|
+
it "returns false when on of the pairs is wrong" do
|
34
|
+
should_not have_table_row("Posts", "Title" => "First", "Author" => "David")
|
35
|
+
expect { should have_table_row("Posts", "Title" => "First", "Author" => "David") }.to fail_assertion
|
36
|
+
end
|
37
|
+
|
38
|
+
it "returns false when given the value of another column" do
|
39
|
+
should_not have_table_row("Posts", "Title" => "Adam")
|
40
|
+
expect { should have_table_row("Posts", "Title" => "Adam") }.to fail_assertion
|
41
|
+
end
|
42
|
+
|
43
|
+
it "returns true when asking for existing blank value" do
|
44
|
+
should have_table_row("Posts", "Author" => "")
|
45
|
+
expect { should have_table_row("Posts", "Third" => "not empty") }.to fail_assertion
|
46
|
+
end
|
47
|
+
|
48
|
+
it "returns false when asking for non-existing blank value" do
|
49
|
+
should_not have_table_row("Posts", "Title" => "")
|
50
|
+
expect { should have_table_row("Posts", "Title" => "") }.to fail_assertion
|
51
|
+
end
|
52
|
+
|
53
|
+
it "returns false if there is no matching table" do
|
54
|
+
should_not have_table_row("Other", "Title" => "First")
|
55
|
+
expect { should_not have_table_row("Posts", "Title" => "First") }.to fail_assertion
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context "with text node values" do
|
60
|
+
it_behaves_like "a table row matcher" do
|
61
|
+
let(:html) { %Q{
|
62
|
+
<tr><td>First</td><td>Adam</td></tr>
|
63
|
+
<tr><td>Second</td><td>David</td></tr>
|
64
|
+
<tr><td>Third</td><td></td></tr>}
|
65
|
+
}
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context "with input field values" do
|
70
|
+
it_behaves_like "a table row matcher" do
|
71
|
+
let(:html) { %Q{
|
72
|
+
<tr>
|
73
|
+
<td><input type="text" value="First" /></td>
|
74
|
+
<td><input type="text" value="Adam" /></td>
|
75
|
+
</tr>
|
76
|
+
<tr>
|
77
|
+
<td><input type="text" value="Second" /></td>
|
78
|
+
<td><input type="text" value="David" /></td>
|
79
|
+
</tr>
|
80
|
+
<tr>
|
81
|
+
<td><input type="text" value="Third" /></td>
|
82
|
+
<td><input type="text" value="" /></td>
|
83
|
+
</tr>}
|
84
|
+
}
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context "configured with xpath selecto" do
|
89
|
+
before do
|
90
|
+
ElabsMatchers.table_row_selector = lambda do |row, table|
|
91
|
+
exps = row.map do |header, value|
|
92
|
+
col_index = table.all("th").index { |th| th.text.include?(header.to_s) }
|
93
|
+
col_index = if col_index then col_index + 1 else 0 end
|
94
|
+
|
95
|
+
XPath.generate do |x|
|
96
|
+
cell = x.child(:td, :th)[col_index.to_s.to_sym]
|
97
|
+
|
98
|
+
if value.blank?
|
99
|
+
cell.child(:span)["not(node())".to_sym]
|
100
|
+
else
|
101
|
+
cell.child(:span)[x.contains(value)]
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
XPath.descendant["tr"][exps.reduce(:&)]
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
it_behaves_like "a table row matcher" do
|
111
|
+
let(:html) { %Q{
|
112
|
+
<tr><td><span>First<span></td><td><span>Adam<span></td></tr>
|
113
|
+
<tr><td><span>Second<span></td><td><span>David<span></td></tr>
|
114
|
+
<tr><td><span>Third<span></td><td><span></span></td></tr>}
|
115
|
+
}
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe ElabsMatchers::Matchers::OnlyInclude do
|
4
|
+
subject { %w[foo bar] }
|
5
|
+
|
6
|
+
describe "#only_include" do
|
7
|
+
it "returns true when all the elements are passed in the wrong order" do
|
8
|
+
should only_include("bar", "foo")
|
9
|
+
expect { should only_include("quox", "foo") }.to fail_assertion
|
10
|
+
end
|
11
|
+
|
12
|
+
it "returns false when given a present element several times" do
|
13
|
+
should_not only_include("foo", "foo")
|
14
|
+
expect { should only_include("foo", "foo") }.to fail_assertion
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns true when all the elements are passed in the correct order" do
|
18
|
+
should only_include("foo", "bar")
|
19
|
+
expect { should only_include("quox", "baz") }.to fail_assertion
|
20
|
+
end
|
21
|
+
|
22
|
+
it "returns false when one or more element is missing" do
|
23
|
+
should_not only_include("foo")
|
24
|
+
expect { should_not only_include("bar", "foo") }.to fail_assertion
|
25
|
+
end
|
26
|
+
|
27
|
+
it "returns false when one of the element is not in the list" do
|
28
|
+
should_not only_include("foo", "bar", "baz")
|
29
|
+
expect { should_not only_include("foo", "bar") }.to fail_assertion
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|