2016-03-07 19:52:19 -05:00
|
|
|
# frozen_string_literal: true
|
2011-02-04 08:47:15 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
require 'capybara/dsl'
|
2011-02-11 08:03:46 -05:00
|
|
|
require 'capybara/rspec/matchers'
|
2011-02-04 08:47:15 -05:00
|
|
|
|
2016-10-13 22:50:03 -04:00
|
|
|
RSpec.shared_examples Capybara::RSpecMatchers do |session, mode|
|
|
|
|
|
2011-04-11 01:58:42 -04:00
|
|
|
include Capybara::DSL
|
2011-02-04 08:47:15 -05:00
|
|
|
include Capybara::RSpecMatchers
|
2014-02-16 12:13:58 -05:00
|
|
|
|
2011-02-04 08:47:15 -05:00
|
|
|
describe "have_css matcher" do
|
2011-04-26 05:56:37 -04:00
|
|
|
it "gives proper description" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(have_css('h1').description).to eq("have css \"h1\"")
|
2011-04-26 05:56:37 -04:00
|
|
|
end
|
2014-02-16 12:13:58 -05:00
|
|
|
|
2011-02-04 08:47:15 -05:00
|
|
|
context "on a string" do
|
|
|
|
context "with should" do
|
|
|
|
it "passes if has_css? returns true" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect("<h1>Text</h1>").to have_css('h1')
|
2011-02-04 08:47:15 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "fails if has_css? returns false" do
|
|
|
|
expect do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect("<h1>Text</h1>").to have_css('h2')
|
2012-07-09 07:33:45 -04:00
|
|
|
end.to raise_error(/expected to find css "h2" but there were no matches/)
|
2011-02-04 08:47:15 -05:00
|
|
|
end
|
2011-03-10 12:58:33 -05:00
|
|
|
|
|
|
|
it "passes if matched node count equals expected count" do
|
2016-10-04 14:10:29 -04:00
|
|
|
expect("<h1>Text</h1>").to have_css('h1', count: 1)
|
2011-03-10 12:58:33 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "fails if matched node count does not equal expected count" do
|
|
|
|
expect do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect("<h1>Text</h1>").to have_css('h1', count: 2)
|
2013-03-03 18:04:23 -05:00
|
|
|
end.to raise_error("expected to find css \"h1\" 2 times, found 1 match: \"Text\"")
|
2011-03-10 12:58:33 -05:00
|
|
|
end
|
2013-03-04 16:35:11 -05:00
|
|
|
|
|
|
|
it "fails if matched node count is less than expected minimum count" do
|
|
|
|
expect do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect("<h1>Text</h1>").to have_css('p', minimum: 1)
|
2013-03-04 16:35:11 -05:00
|
|
|
end.to raise_error("expected to find css \"p\" at least 1 time but there were no matches")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "fails if matched node count is more than expected maximum count" do
|
|
|
|
expect do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect("<h1>Text</h1><h1>Text</h1><h1>Text</h1>").to have_css('h1', maximum: 2)
|
2013-03-04 16:35:11 -05:00
|
|
|
end.to raise_error('expected to find css "h1" at most 2 times, found 3 matches: "Text", "Text", "Text"')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "fails if matched node count does not belong to expected range" do
|
|
|
|
expect do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect("<h1>Text</h1>").to have_css('h1', between: 2..3)
|
2013-03-04 16:35:11 -05:00
|
|
|
end.to raise_error("expected to find css \"h1\" between 2 and 3 times, found 1 match: \"Text\"")
|
|
|
|
end
|
|
|
|
|
2011-02-04 08:47:15 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context "with should_not" do
|
|
|
|
it "passes if has_no_css? returns true" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect("<h1>Text</h1>").not_to have_css('h2')
|
2011-02-04 08:47:15 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "fails if has_no_css? returns false" do
|
|
|
|
expect do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect("<h1>Text</h1>").not_to have_css('h1')
|
2012-07-09 07:33:45 -04:00
|
|
|
end.to raise_error(/expected not to find css "h1"/)
|
2011-02-04 08:47:15 -05:00
|
|
|
end
|
2011-03-10 12:58:33 -05:00
|
|
|
|
|
|
|
it "passes if matched node count does not equal expected count" do
|
2016-10-04 14:10:29 -04:00
|
|
|
expect("<h1>Text</h1>").not_to have_css('h1', count: 2)
|
2011-03-10 12:58:33 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "fails if matched node count equals expected count" do
|
|
|
|
expect do
|
2016-10-04 14:10:29 -04:00
|
|
|
expect("<h1>Text</h1>").not_to have_css('h1', count: 1)
|
2012-07-09 07:33:45 -04:00
|
|
|
end.to raise_error(/expected not to find css "h1"/)
|
2011-03-10 12:58:33 -05:00
|
|
|
end
|
2011-02-04 08:47:15 -05:00
|
|
|
end
|
2015-08-24 01:14:48 -04:00
|
|
|
|
2014-06-11 14:52:29 -04:00
|
|
|
it "supports compounding" do
|
|
|
|
expect("<h1>Text</h1><h2>Text</h2>").to have_css('h1').and have_css('h2')
|
|
|
|
expect("<h1>Text</h1><h2>Text</h2>").to have_css('h3').or have_css('h1')
|
|
|
|
end if RSpec::Version::STRING.to_f >= 3.0
|
2011-02-04 08:47:15 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context "on a page or node" do
|
|
|
|
before do
|
|
|
|
visit('/with_html')
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with should" do
|
|
|
|
it "passes if has_css? returns true" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(page).to have_css('h1')
|
2011-02-04 08:47:15 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "fails if has_css? returns false" do
|
|
|
|
expect do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(page).to have_css('h1#doesnotexist')
|
2012-07-09 07:33:45 -04:00
|
|
|
end.to raise_error(/expected to find css "h1#doesnotexist" but there were no matches/)
|
2011-02-04 08:47:15 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with should_not" do
|
|
|
|
it "passes if has_no_css? returns true" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(page).not_to have_css('h1#doesnotexist')
|
2011-02-04 08:47:15 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "fails if has_no_css? returns false" do
|
|
|
|
expect do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(page).not_to have_css('h1')
|
2012-07-09 07:33:45 -04:00
|
|
|
end.to raise_error(/expected not to find css "h1"/)
|
2011-02-04 08:47:15 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "have_xpath matcher" do
|
2011-04-26 05:56:37 -04:00
|
|
|
it "gives proper description" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(have_xpath('//h1').description).to eq("have xpath \"\/\/h1\"")
|
2011-04-26 05:56:37 -04:00
|
|
|
end
|
|
|
|
|
2011-02-04 08:47:15 -05:00
|
|
|
context "on a string" do
|
|
|
|
context "with should" do
|
2012-07-08 12:34:45 -04:00
|
|
|
it "passes if has_xpath? returns true" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect("<h1>Text</h1>").to have_xpath('//h1')
|
2011-02-04 08:47:15 -05:00
|
|
|
end
|
|
|
|
|
2012-07-08 12:34:45 -04:00
|
|
|
it "fails if has_xpath? returns false" do
|
2011-02-04 08:47:15 -05:00
|
|
|
expect do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect("<h1>Text</h1>").to have_xpath('//h2')
|
2012-07-09 07:33:45 -04:00
|
|
|
end.to raise_error(%r(expected to find xpath "//h2" but there were no matches))
|
2011-02-04 08:47:15 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with should_not" do
|
2012-07-08 12:34:45 -04:00
|
|
|
it "passes if has_no_xpath? returns true" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect("<h1>Text</h1>").not_to have_xpath('//h2')
|
2011-02-04 08:47:15 -05:00
|
|
|
end
|
|
|
|
|
2012-07-08 12:34:45 -04:00
|
|
|
it "fails if has_no_xpath? returns false" do
|
2011-02-04 08:47:15 -05:00
|
|
|
expect do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect("<h1>Text</h1>").not_to have_xpath('//h1')
|
2012-07-09 07:33:45 -04:00
|
|
|
end.to raise_error(%r(expected not to find xpath "//h1"))
|
2011-02-04 08:47:15 -05:00
|
|
|
end
|
|
|
|
end
|
2015-08-24 01:14:48 -04:00
|
|
|
|
2014-06-11 14:52:29 -04:00
|
|
|
it "supports compounding" do
|
|
|
|
expect("<h1>Text</h1><h2>Text</h2>").to have_xpath('//h1').and have_xpath('//h2')
|
|
|
|
expect("<h1>Text</h1><h2>Text</h2>").to have_xpath('//h3').or have_xpath('//h1')
|
|
|
|
end if RSpec::Version::STRING.to_f >= 3.0
|
2011-02-04 08:47:15 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context "on a page or node" do
|
|
|
|
before do
|
|
|
|
visit('/with_html')
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with should" do
|
2012-07-08 12:34:45 -04:00
|
|
|
it "passes if has_xpath? returns true" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(page).to have_xpath('//h1')
|
2011-02-04 08:47:15 -05:00
|
|
|
end
|
|
|
|
|
2012-07-08 12:34:45 -04:00
|
|
|
it "fails if has_xpath? returns false" do
|
2011-02-04 08:47:15 -05:00
|
|
|
expect do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(page).to have_xpath("//h1[@id='doesnotexist']")
|
2012-07-09 07:33:45 -04:00
|
|
|
end.to raise_error(%r(expected to find xpath "//h1\[@id='doesnotexist'\]" but there were no matches))
|
2011-02-04 08:47:15 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with should_not" do
|
2012-07-08 12:34:45 -04:00
|
|
|
it "passes if has_no_xpath? returns true" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(page).not_to have_xpath('//h1[@id="doesnotexist"]')
|
2011-02-04 08:47:15 -05:00
|
|
|
end
|
|
|
|
|
2012-07-08 12:34:45 -04:00
|
|
|
it "fails if has_no_xpath? returns false" do
|
2011-02-04 08:47:15 -05:00
|
|
|
expect do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(page).not_to have_xpath('//h1')
|
2012-07-09 07:33:45 -04:00
|
|
|
end.to raise_error(%r(expected not to find xpath "//h1"))
|
2011-02-04 08:47:15 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "have_selector matcher" do
|
2011-04-26 05:56:37 -04:00
|
|
|
it "gives proper description" do
|
2012-01-31 11:24:34 -05:00
|
|
|
matcher = have_selector('//h1')
|
2013-11-14 12:43:36 -05:00
|
|
|
expect("<h1>Text</h1>").to matcher
|
|
|
|
expect(matcher.description).to eq("have xpath \"//h1\"")
|
2011-04-26 05:56:37 -04:00
|
|
|
end
|
|
|
|
|
2011-02-04 08:47:15 -05:00
|
|
|
context "on a string" do
|
|
|
|
context "with should" do
|
2012-07-08 12:34:45 -04:00
|
|
|
it "passes if has_selector? returns true" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect("<h1>Text</h1>").to have_selector('//h1')
|
2011-02-04 08:47:15 -05:00
|
|
|
end
|
|
|
|
|
2012-07-08 12:34:45 -04:00
|
|
|
it "fails if has_selector? returns false" do
|
2011-02-04 08:47:15 -05:00
|
|
|
expect do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect("<h1>Text</h1>").to have_selector('//h2')
|
2012-07-09 07:33:45 -04:00
|
|
|
end.to raise_error(%r(expected to find xpath "//h2" but there were no matches))
|
2011-02-04 10:56:27 -05:00
|
|
|
end
|
2011-02-04 08:47:15 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context "with should_not" do
|
2012-07-08 12:34:45 -04:00
|
|
|
it "passes if has_no_selector? returns true" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect("<h1>Text</h1>").not_to have_selector(:css, 'h2')
|
2011-02-04 08:47:15 -05:00
|
|
|
end
|
|
|
|
|
2012-07-08 12:34:45 -04:00
|
|
|
it "fails if has_no_selector? returns false" do
|
2011-02-04 08:47:15 -05:00
|
|
|
expect do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect("<h1>Text</h1>").not_to have_selector(:css, 'h1')
|
2012-07-09 07:33:45 -04:00
|
|
|
end.to raise_error(%r(expected not to find css "h1"))
|
2011-02-04 08:47:15 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "on a page or node" do
|
|
|
|
before do
|
|
|
|
visit('/with_html')
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with should" do
|
2012-07-08 12:34:45 -04:00
|
|
|
it "passes if has_selector? returns true" do
|
2016-10-04 14:10:29 -04:00
|
|
|
expect(page).to have_selector('//h1', text: 'test')
|
2011-02-04 08:47:15 -05:00
|
|
|
end
|
|
|
|
|
2012-07-08 12:34:45 -04:00
|
|
|
it "fails if has_selector? returns false" do
|
2011-02-04 08:47:15 -05:00
|
|
|
expect do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(page).to have_selector("//h1[@id='doesnotexist']")
|
2012-07-09 07:33:45 -04:00
|
|
|
end.to raise_error(%r(expected to find xpath "//h1\[@id='doesnotexist'\]" but there were no matches))
|
2011-02-04 08:47:15 -05:00
|
|
|
end
|
2011-02-04 10:56:27 -05:00
|
|
|
|
2011-02-06 14:07:12 -05:00
|
|
|
it "includes text in error message" do
|
|
|
|
expect do
|
2016-10-04 14:10:29 -04:00
|
|
|
expect(page).to have_selector("//h1", text: 'wrong text')
|
2012-07-09 07:33:45 -04:00
|
|
|
end.to raise_error(%r(expected to find xpath "//h1" with text "wrong text" but there were no matches))
|
2011-02-04 10:56:27 -05:00
|
|
|
end
|
2011-02-04 08:47:15 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context "with should_not" do
|
|
|
|
it "passes if has_no_css? returns true" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(page).not_to have_selector(:css, 'h1#doesnotexist')
|
2011-02-04 08:47:15 -05:00
|
|
|
end
|
|
|
|
|
2012-07-08 12:34:45 -04:00
|
|
|
it "fails if has_no_selector? returns false" do
|
2011-02-04 08:47:15 -05:00
|
|
|
expect do
|
2016-10-04 14:10:29 -04:00
|
|
|
expect(page).not_to have_selector(:css, 'h1', text: 'test')
|
2012-07-09 07:33:45 -04:00
|
|
|
end.to raise_error(%r(expected not to find css "h1" with text "test"))
|
2011-02-04 08:47:15 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-08-24 01:14:48 -04:00
|
|
|
|
2014-06-11 14:52:29 -04:00
|
|
|
it "supports compounding" do
|
|
|
|
expect("<h1>Text</h1><h2>Text</h2>").to have_selector('//h1').and have_selector('//h2')
|
|
|
|
expect("<h1>Text</h1><h2>Text</h2>").to have_selector('//h3').or have_selector('//h1')
|
|
|
|
end if RSpec::Version::STRING.to_f >= 3.0
|
2011-02-04 08:47:15 -05:00
|
|
|
end
|
2011-02-10 11:15:28 -05:00
|
|
|
|
|
|
|
describe "have_content matcher" do
|
2011-04-26 05:56:37 -04:00
|
|
|
it "gives proper description" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(have_content('Text').description).to eq("text \"Text\"")
|
2011-04-26 05:56:37 -04:00
|
|
|
end
|
|
|
|
|
2011-02-10 11:15:28 -05:00
|
|
|
context "on a string" do
|
|
|
|
context "with should" do
|
2012-07-08 12:34:45 -04:00
|
|
|
it "passes if has_content? returns true" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect("<h1>Text</h1>").to have_content('Text')
|
2011-02-10 11:15:28 -05:00
|
|
|
end
|
|
|
|
|
2012-07-08 17:13:25 -04:00
|
|
|
it "passes if has_content? returns true using regexp" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect("<h1>Text</h1>").to have_content(/ext/)
|
2012-07-08 17:13:25 -04:00
|
|
|
end
|
|
|
|
|
2012-07-08 12:34:45 -04:00
|
|
|
it "fails if has_content? returns false" do
|
2011-02-10 11:15:28 -05:00
|
|
|
expect do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect("<h1>Text</h1>").to have_content('No such Text')
|
2013-03-03 18:04:23 -05:00
|
|
|
end.to raise_error(/expected to find text "No such Text" in "Text"/)
|
2011-02-10 11:15:28 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with should_not" do
|
2012-07-08 12:34:45 -04:00
|
|
|
it "passes if has_no_content? returns true" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect("<h1>Text</h1>").not_to have_content('No such Text')
|
2011-02-10 11:15:28 -05:00
|
|
|
end
|
|
|
|
|
2012-07-08 17:13:25 -04:00
|
|
|
it "passes because escapes any characters that would have special meaning in a regexp" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect("<h1>Text</h1>").not_to have_content('.')
|
2012-07-08 17:13:25 -04:00
|
|
|
end
|
|
|
|
|
2012-07-08 12:34:45 -04:00
|
|
|
it "fails if has_no_content? returns false" do
|
2011-02-10 11:15:28 -05:00
|
|
|
expect do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect("<h1>Text</h1>").not_to have_content('Text')
|
2013-03-03 18:04:23 -05:00
|
|
|
end.to raise_error(/expected not to find text "Text" in "Text"/)
|
2011-02-10 11:15:28 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "on a page or node" do
|
|
|
|
before do
|
|
|
|
visit('/with_html')
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with should" do
|
2012-07-08 12:34:45 -04:00
|
|
|
it "passes if has_content? returns true" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(page).to have_content('This is a test')
|
2011-02-10 11:15:28 -05:00
|
|
|
end
|
|
|
|
|
2012-07-08 17:13:25 -04:00
|
|
|
it "passes if has_content? returns true using regexp" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(page).to have_content(/test/)
|
2012-07-08 17:13:25 -04:00
|
|
|
end
|
|
|
|
|
2012-07-08 12:34:45 -04:00
|
|
|
it "fails if has_content? returns false" do
|
2011-02-10 11:15:28 -05:00
|
|
|
expect do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(page).to have_content('No such Text')
|
2013-03-03 18:04:23 -05:00
|
|
|
end.to raise_error(/expected to find text "No such Text" in "(.*)This is a test(.*)"/)
|
2011-02-10 11:15:28 -05:00
|
|
|
end
|
2011-02-18 16:29:51 -05:00
|
|
|
|
|
|
|
context "with default selector CSS" do
|
|
|
|
before { Capybara.default_selector = :css }
|
2012-07-08 12:34:45 -04:00
|
|
|
it "fails if has_content? returns false" do
|
2011-02-18 16:29:51 -05:00
|
|
|
expect do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(page).to have_content('No such Text')
|
2013-03-03 18:04:23 -05:00
|
|
|
end.to raise_error(/expected to find text "No such Text" in "(.*)This is a test(.*)"/)
|
2011-02-18 16:29:51 -05:00
|
|
|
end
|
|
|
|
after { Capybara.default_selector = :xpath }
|
|
|
|
end
|
2011-02-10 11:15:28 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context "with should_not" do
|
2012-07-08 12:34:45 -04:00
|
|
|
it "passes if has_no_content? returns true" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(page).not_to have_content('No such Text')
|
2011-02-10 11:15:28 -05:00
|
|
|
end
|
|
|
|
|
2012-07-08 12:34:45 -04:00
|
|
|
it "fails if has_no_content? returns false" do
|
2011-02-10 11:15:28 -05:00
|
|
|
expect do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(page).not_to have_content('This is a test')
|
2013-03-03 18:04:23 -05:00
|
|
|
end.to raise_error(/expected not to find text "This is a test"/)
|
2011-02-10 11:15:28 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-08-24 01:14:48 -04:00
|
|
|
|
2014-06-11 14:52:29 -04:00
|
|
|
it "supports compounding" do
|
|
|
|
expect("<h1>Text</h1><h2>And</h2>").to have_content('Text').and have_content('And')
|
|
|
|
expect("<h1>Text</h1><h2>Or</h2>").to have_content('XYZ').or have_content('Or')
|
|
|
|
end if RSpec::Version::STRING.to_f >= 3.0
|
2011-02-10 11:15:28 -05:00
|
|
|
end
|
2011-02-13 11:04:13 -05:00
|
|
|
|
2011-10-16 19:46:19 -04:00
|
|
|
describe "have_text matcher" do
|
|
|
|
it "gives proper description" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(have_text('Text').description).to eq("text \"Text\"")
|
2011-10-16 19:46:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context "on a string" do
|
|
|
|
context "with should" do
|
2014-02-16 12:13:58 -05:00
|
|
|
it "passes if text contains given string" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect("<h1>Text</h1>").to have_text('Text')
|
2011-10-16 19:46:19 -04:00
|
|
|
end
|
|
|
|
|
2014-02-16 12:13:58 -05:00
|
|
|
it "passes if text matches given regexp" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect("<h1>Text</h1>").to have_text(/ext/)
|
2012-07-08 17:13:25 -04:00
|
|
|
end
|
|
|
|
|
2014-02-16 12:13:58 -05:00
|
|
|
it "fails if text doesn't contain given string" do
|
2011-10-16 19:46:19 -04:00
|
|
|
expect do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect("<h1>Text</h1>").to have_text('No such Text')
|
2013-03-03 18:04:23 -05:00
|
|
|
end.to raise_error(/expected to find text "No such Text" in "Text"/)
|
2011-10-16 19:46:19 -04:00
|
|
|
end
|
2012-08-01 15:56:11 -04:00
|
|
|
|
2014-02-16 12:13:58 -05:00
|
|
|
it "fails if text doesn't match given regexp" do
|
|
|
|
expect do
|
|
|
|
expect("<h1>Text</h1>").to have_text(/No such Text/)
|
|
|
|
end.to raise_error('expected to find text matching /No such Text/ in "Text"')
|
|
|
|
end
|
|
|
|
|
2013-03-10 18:55:32 -04:00
|
|
|
it "casts Fixnum to string" do
|
2012-08-01 15:56:11 -04:00
|
|
|
expect do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect("<h1>Text</h1>").to have_text(3)
|
2013-03-10 18:55:32 -04:00
|
|
|
end.to raise_error(/expected to find text "3" in "Text"/)
|
2012-08-01 15:56:11 -04:00
|
|
|
end
|
2013-03-04 16:35:11 -05:00
|
|
|
|
|
|
|
it "fails if matched text count does not equal to expected count" do
|
|
|
|
expect do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect("<h1>Text</h1>").to have_text('Text', count: 2)
|
2014-02-16 12:13:58 -05:00
|
|
|
end.to raise_error('expected to find text "Text" 2 times but found 1 time in "Text"')
|
2013-03-04 16:35:11 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "fails if matched text count is less than expected minimum count" do
|
|
|
|
expect do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect("<h1>Text</h1>").to have_text('Lorem', minimum: 1)
|
2014-02-16 12:13:58 -05:00
|
|
|
end.to raise_error('expected to find text "Lorem" at least 1 time but found 0 times in "Text"')
|
2013-03-04 16:35:11 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "fails if matched text count is more than expected maximum count" do
|
|
|
|
expect do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect("<h1>Text TextText</h1>").to have_text('Text', maximum: 2)
|
2014-02-16 12:13:58 -05:00
|
|
|
end.to raise_error('expected to find text "Text" at most 2 times but found 3 times in "Text TextText"')
|
2013-03-04 16:35:11 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "fails if matched text count does not belong to expected range" do
|
|
|
|
expect do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect("<h1>Text</h1>").to have_text('Text', between: 2..3)
|
2014-02-16 12:13:58 -05:00
|
|
|
end.to raise_error('expected to find text "Text" between 2 and 3 times but found 1 time in "Text"')
|
2013-03-04 16:35:11 -05:00
|
|
|
end
|
2011-10-16 19:46:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context "with should_not" do
|
2014-02-16 12:13:58 -05:00
|
|
|
it "passes if text doesn't contain a string" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect("<h1>Text</h1>").not_to have_text('No such Text')
|
2011-10-16 19:46:19 -04:00
|
|
|
end
|
|
|
|
|
2012-07-08 17:13:25 -04:00
|
|
|
it "passes because escapes any characters that would have special meaning in a regexp" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect("<h1>Text</h1>").not_to have_text('.')
|
2012-07-08 17:13:25 -04:00
|
|
|
end
|
|
|
|
|
2014-02-16 12:13:58 -05:00
|
|
|
it "fails if text contains a string" do
|
2011-10-16 19:46:19 -04:00
|
|
|
expect do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect("<h1>Text</h1>").not_to have_text('Text')
|
2013-03-03 18:04:23 -05:00
|
|
|
end.to raise_error(/expected not to find text "Text" in "Text"/)
|
2011-10-16 19:46:19 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "on a page or node" do
|
|
|
|
before do
|
|
|
|
visit('/with_html')
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with should" do
|
|
|
|
it "passes if has_text? returns true" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(page).to have_text('This is a test')
|
2011-10-16 19:46:19 -04:00
|
|
|
end
|
|
|
|
|
2012-07-08 17:13:25 -04:00
|
|
|
it "passes if has_text? returns true using regexp" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(page).to have_text(/test/)
|
2012-07-08 17:13:25 -04:00
|
|
|
end
|
|
|
|
|
2013-02-17 09:45:14 -05:00
|
|
|
it "can check for all text" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(page).to have_text(:all, 'Some of this text is hidden!')
|
2013-02-17 09:45:14 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "can check for visible text" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(page).to have_text(:visible, 'Some of this text is')
|
|
|
|
expect(page).not_to have_text(:visible, 'Some of this text is hidden!')
|
2013-02-17 09:45:14 -05:00
|
|
|
end
|
|
|
|
|
2011-10-16 19:46:19 -04:00
|
|
|
it "fails if has_text? returns false" do
|
|
|
|
expect do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(page).to have_text('No such Text')
|
2013-03-03 18:04:23 -05:00
|
|
|
end.to raise_error(/expected to find text "No such Text" in "(.*)This is a test(.*)"/)
|
2011-10-16 19:46:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context "with default selector CSS" do
|
|
|
|
before { Capybara.default_selector = :css }
|
|
|
|
it "fails if has_text? returns false" do
|
|
|
|
expect do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(page).to have_text('No such Text')
|
2013-03-03 18:04:23 -05:00
|
|
|
end.to raise_error(/expected to find text "No such Text" in "(.*)This is a test(.*)"/)
|
2011-10-16 19:46:19 -04:00
|
|
|
end
|
|
|
|
after { Capybara.default_selector = :xpath }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with should_not" do
|
|
|
|
it "passes if has_no_text? returns true" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(page).not_to have_text('No such Text')
|
2011-10-16 19:46:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "fails if has_no_text? returns false" do
|
|
|
|
expect do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(page).not_to have_text('This is a test')
|
2013-03-03 18:04:23 -05:00
|
|
|
end.to raise_error(/expected not to find text "This is a test"/)
|
2011-10-16 19:46:19 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-08-24 01:14:48 -04:00
|
|
|
|
2014-06-11 14:52:29 -04:00
|
|
|
it "supports compounding" do
|
|
|
|
expect("<h1>Text</h1><h2>And</h2>").to have_text('Text').and have_text('And')
|
|
|
|
expect("<h1>Text</h1><h2>Or</h2>").to have_text('Not here').or have_text('Or')
|
|
|
|
end if RSpec::Version::STRING.to_f >= 3.0
|
2011-10-16 19:46:19 -04:00
|
|
|
end
|
|
|
|
|
2011-03-25 06:35:59 -04:00
|
|
|
describe "have_link matcher" do
|
2014-06-11 14:52:29 -04:00
|
|
|
let(:html) { '<a href="#">Just a link</a><a href="#">Another link</a>' }
|
2011-03-25 06:35:59 -04:00
|
|
|
|
2011-04-26 05:56:37 -04:00
|
|
|
it "gives proper description" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(have_link('Just a link').description).to eq("have link \"Just a link\"")
|
2011-04-26 05:56:37 -04:00
|
|
|
end
|
2014-02-16 12:13:58 -05:00
|
|
|
|
2011-03-25 06:35:59 -04:00
|
|
|
it "passes if there is such a button" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(html).to have_link('Just a link')
|
2011-03-25 06:35:59 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "fails if there is no such button" do
|
|
|
|
expect do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(html).to have_link('No such Link')
|
2012-07-09 07:33:45 -04:00
|
|
|
end.to raise_error(/expected to find link "No such Link"/)
|
2011-03-25 06:35:59 -04:00
|
|
|
end
|
2015-08-24 01:14:48 -04:00
|
|
|
|
2014-06-11 14:52:29 -04:00
|
|
|
it "supports compounding" do
|
|
|
|
expect(html).to have_link('Just a link').and have_link('Another link')
|
|
|
|
expect(html).to have_link('Not a link').or have_link('Another link')
|
|
|
|
end if RSpec::Version::STRING.to_f >= 3.0
|
2011-03-25 06:35:59 -04:00
|
|
|
end
|
2013-02-16 04:02:32 -05:00
|
|
|
|
|
|
|
describe "have_title matcher" do
|
|
|
|
it "gives proper description" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(have_title('Just a title').description).to eq("have title \"Just a title\"")
|
2013-02-16 04:02:32 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context "on a string" do
|
|
|
|
let(:html) { '<title>Just a title</title>' }
|
|
|
|
|
|
|
|
it "passes if there is such a title" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(html).to have_title('Just a title')
|
2013-02-16 04:02:32 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "fails if there is no such title" do
|
|
|
|
expect do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(html).to have_title('No such title')
|
2014-02-16 12:13:58 -05:00
|
|
|
end.to raise_error('expected "Just a title" to include "No such title"')
|
2013-02-16 04:02:32 -05:00
|
|
|
end
|
|
|
|
|
2014-02-16 12:13:58 -05:00
|
|
|
it "fails if title doesn't match regexp" do
|
|
|
|
expect do
|
|
|
|
expect(html).to have_title(/[[:upper:]]+[[:lower:]]+l{2}o/)
|
|
|
|
end.to raise_error('expected "Just a title" to match /[[:upper:]]+[[:lower:]]+l{2}o/')
|
2013-02-16 04:02:32 -05:00
|
|
|
end
|
2014-02-16 12:13:58 -05:00
|
|
|
end
|
2013-02-16 04:02:32 -05:00
|
|
|
|
2014-02-16 12:13:58 -05:00
|
|
|
context "on a page or node" do
|
2013-02-16 04:02:32 -05:00
|
|
|
it "passes if there is such a title" do
|
2014-02-16 12:13:58 -05:00
|
|
|
visit('/with_js')
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(page).to have_title('with_js')
|
2013-02-16 04:02:32 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "fails if there is no such title" do
|
2014-02-16 12:13:58 -05:00
|
|
|
visit('/with_js')
|
2013-02-16 04:02:32 -05:00
|
|
|
expect do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(page).to have_title('No such title')
|
2014-02-16 12:13:58 -05:00
|
|
|
end.to raise_error('expected "with_js" to include "No such title"')
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with wait' do
|
|
|
|
before(:each) do
|
2016-10-13 22:50:03 -04:00
|
|
|
@session = session
|
2014-02-16 12:13:58 -05:00
|
|
|
@session.visit('/with_js')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'waits if wait time is more than timeout' do
|
|
|
|
@session.click_link("Change title")
|
|
|
|
using_wait_time 0 do
|
|
|
|
expect(@session).to have_title('changed title', wait: 0.5)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't wait if wait time is less than timeout" do
|
|
|
|
@session.click_link("Change title")
|
|
|
|
using_wait_time 0 do
|
|
|
|
expect(@session).not_to have_title('changed title')
|
|
|
|
end
|
|
|
|
end
|
2013-02-16 04:02:32 -05:00
|
|
|
end
|
|
|
|
end
|
2015-08-24 01:14:48 -04:00
|
|
|
|
2014-06-11 14:52:29 -04:00
|
|
|
it "supports compounding" do
|
|
|
|
expect("<title>I compound</title>").to have_title('I dont compound').or have_title('I compound')
|
|
|
|
end if RSpec::Version::STRING.to_f >= 3.0
|
2013-02-16 04:02:32 -05:00
|
|
|
end
|
2011-02-13 11:04:13 -05:00
|
|
|
|
2015-08-24 01:14:48 -04:00
|
|
|
describe "have_current_path matcher" do
|
|
|
|
it "gives proper description" do
|
|
|
|
expect(have_current_path('http://www.example.com').description).to eq("have current path \"http://www.example.com\"")
|
|
|
|
end
|
|
|
|
|
|
|
|
context "on a page or node" do
|
|
|
|
it "passes if there is such a current path" do
|
|
|
|
visit('/with_js')
|
|
|
|
expect(page).to have_current_path('/with_js')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "fails if there is no such current_path" do
|
|
|
|
visit('/with_js')
|
|
|
|
expect do
|
|
|
|
expect(page).to have_current_path('/not_with_js')
|
|
|
|
end.to raise_error('expected "/with_js" to equal "/not_with_js"')
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with wait' do
|
|
|
|
before(:each) do
|
2016-10-13 22:50:03 -04:00
|
|
|
@session = session
|
2015-08-24 01:14:48 -04:00
|
|
|
@session.visit('/with_js')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'waits if wait time is more than timeout' do
|
|
|
|
@session.click_link("Change page")
|
|
|
|
using_wait_time 0 do
|
|
|
|
expect(@session).to have_current_path('/with_html', wait: 1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't wait if wait time is less than timeout" do
|
|
|
|
@session.click_link("Change page")
|
|
|
|
using_wait_time 0 do
|
|
|
|
expect(@session).not_to have_current_path('/with_html')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "supports compounding" do
|
|
|
|
visit('/with_html')
|
|
|
|
expect(page).to have_current_path('/not_with_html').or have_current_path('/with_html')
|
|
|
|
end if RSpec::Version::STRING.to_f >= 3.0
|
|
|
|
end
|
|
|
|
|
2011-02-13 11:04:13 -05:00
|
|
|
describe "have_button matcher" do
|
2011-02-13 11:46:22 -05:00
|
|
|
let(:html) { '<button>A button</button><input type="submit" value="Another button"/>' }
|
|
|
|
|
2011-04-26 05:56:37 -04:00
|
|
|
it "gives proper description" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(have_button('A button').description).to eq("have button \"A button\"")
|
2011-04-26 05:56:37 -04:00
|
|
|
end
|
|
|
|
|
2011-02-13 11:46:22 -05:00
|
|
|
it "passes if there is such a button" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(html).to have_button('A button')
|
2011-02-13 11:46:22 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "fails if there is no such button" do
|
|
|
|
expect do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(html).to have_button('No such Button')
|
2012-07-09 07:33:45 -04:00
|
|
|
end.to raise_error(/expected to find button "No such Button"/)
|
2011-02-13 11:46:22 -05:00
|
|
|
end
|
2015-08-24 01:14:48 -04:00
|
|
|
|
2014-06-11 14:52:29 -04:00
|
|
|
it "supports compounding" do
|
|
|
|
expect(html).to have_button('Not this button').or have_button('A button')
|
|
|
|
end if RSpec::Version::STRING.to_f >= 3.0
|
2011-02-13 11:46:22 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "have_field matcher" do
|
2013-09-25 09:07:02 -04:00
|
|
|
let(:html) { '<p><label>Text field<input type="text" value="some value"/></label></p>' }
|
2011-02-13 11:04:13 -05:00
|
|
|
|
2011-04-26 05:56:37 -04:00
|
|
|
it "gives proper description" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(have_field('Text field').description).to eq("have field \"Text field\"")
|
2011-04-26 05:56:37 -04:00
|
|
|
end
|
|
|
|
|
2013-09-25 09:07:02 -04:00
|
|
|
it "gives proper description for a given value" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(have_field('Text field', with: 'some value').description).to eq("have field \"Text field\" with value \"some value\"")
|
2013-09-25 09:07:02 -04:00
|
|
|
end
|
2015-08-24 01:14:48 -04:00
|
|
|
|
2011-03-25 05:51:10 -04:00
|
|
|
it "passes if there is such a field" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(html).to have_field('Text field')
|
2011-02-13 11:04:13 -05:00
|
|
|
end
|
|
|
|
|
2013-09-25 09:07:02 -04:00
|
|
|
it "passes if there is such a field with value" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(html).to have_field('Text field', with: 'some value')
|
2013-09-25 09:07:02 -04:00
|
|
|
end
|
|
|
|
|
2011-03-25 05:51:10 -04:00
|
|
|
it "fails if there is no such field" do
|
2011-02-13 11:04:13 -05:00
|
|
|
expect do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(html).to have_field('No such Field')
|
2012-07-09 07:33:45 -04:00
|
|
|
end.to raise_error(/expected to find field "No such Field"/)
|
2011-02-13 11:04:13 -05:00
|
|
|
end
|
2013-09-25 09:07:02 -04:00
|
|
|
|
|
|
|
it "fails if there is such field but with false value" do
|
|
|
|
expect do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(html).to have_field('Text field', with: 'false value')
|
2013-09-25 09:07:02 -04:00
|
|
|
end.to raise_error(/expected to find field "Text field"/)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "treats a given value as a string" do
|
|
|
|
class Foo
|
|
|
|
def to_s
|
|
|
|
"some value"
|
|
|
|
end
|
|
|
|
end
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(html).to have_field('Text field', with: Foo.new)
|
2013-09-25 09:07:02 -04:00
|
|
|
end
|
2015-08-24 01:14:48 -04:00
|
|
|
|
2014-06-11 14:52:29 -04:00
|
|
|
it "supports compounding" do
|
|
|
|
expect(html).to have_field('Not this one').or have_field('Text field')
|
|
|
|
end if RSpec::Version::STRING.to_f >= 3.0
|
2011-02-13 11:04:13 -05:00
|
|
|
end
|
|
|
|
|
2011-03-25 06:35:59 -04:00
|
|
|
describe "have_checked_field matcher" do
|
|
|
|
let(:html) do
|
|
|
|
'<label>it is checked<input type="checkbox" checked="checked"/></label>
|
|
|
|
<label>unchecked field<input type="checkbox"/></label>'
|
|
|
|
end
|
|
|
|
|
2011-04-26 05:56:37 -04:00
|
|
|
it "gives proper description" do
|
2014-07-02 14:17:53 -04:00
|
|
|
expect(have_checked_field('it is checked').description).to eq("have field \"it is checked\" that is checked")
|
2011-04-26 05:56:37 -04:00
|
|
|
end
|
2015-08-24 01:14:48 -04:00
|
|
|
|
2011-03-25 06:35:59 -04:00
|
|
|
context "with should" do
|
|
|
|
it "passes if there is such a field and it is checked" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(html).to have_checked_field('it is checked')
|
2011-03-25 06:35:59 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "fails if there is such a field but it is not checked" do
|
|
|
|
expect do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(html).to have_checked_field('unchecked field')
|
2012-07-09 07:33:45 -04:00
|
|
|
end.to raise_error(/expected to find field "unchecked field"/)
|
2011-03-25 06:35:59 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "fails if there is no such field" do
|
|
|
|
expect do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(html).to have_checked_field('no such field')
|
2012-07-09 07:33:45 -04:00
|
|
|
end.to raise_error(/expected to find field "no such field"/)
|
2011-03-25 06:35:59 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with should not" do
|
|
|
|
it "fails if there is such a field and it is checked" do
|
|
|
|
expect do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(html).not_to have_checked_field('it is checked')
|
2012-07-09 07:33:45 -04:00
|
|
|
end.to raise_error(/expected not to find field "it is checked"/)
|
2011-03-25 06:35:59 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "passes if there is such a field but it is not checked" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(html).not_to have_checked_field('unchecked field')
|
2011-03-25 06:35:59 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "passes if there is no such field" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(html).not_to have_checked_field('no such field')
|
2011-03-25 06:35:59 -04:00
|
|
|
end
|
|
|
|
end
|
2015-08-24 01:14:48 -04:00
|
|
|
|
2014-06-11 14:52:29 -04:00
|
|
|
it "supports compounding" do
|
|
|
|
expect(html).to have_checked_field('not this one').or have_checked_field('it is checked')
|
|
|
|
end if RSpec::Version::STRING.to_f >= 3.0
|
2011-03-25 06:35:59 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "have_unchecked_field matcher" do
|
|
|
|
let(:html) do
|
|
|
|
'<label>it is checked<input type="checkbox" checked="checked"/></label>
|
|
|
|
<label>unchecked field<input type="checkbox"/></label>'
|
|
|
|
end
|
|
|
|
|
2011-04-26 05:56:37 -04:00
|
|
|
it "gives proper description" do
|
2014-07-02 14:17:53 -04:00
|
|
|
expect(have_unchecked_field('unchecked field').description).to eq("have field \"unchecked field\" that is not checked")
|
2011-04-26 05:56:37 -04:00
|
|
|
end
|
|
|
|
|
2011-03-25 06:35:59 -04:00
|
|
|
context "with should" do
|
|
|
|
it "passes if there is such a field and it is not checked" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(html).to have_unchecked_field('unchecked field')
|
2011-03-25 06:35:59 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "fails if there is such a field but it is checked" do
|
|
|
|
expect do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(html).to have_unchecked_field('it is checked')
|
2012-07-09 07:33:45 -04:00
|
|
|
end.to raise_error(/expected to find field "it is checked"/)
|
2011-03-25 06:35:59 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "fails if there is no such field" do
|
|
|
|
expect do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(html).to have_unchecked_field('no such field')
|
2012-07-09 07:33:45 -04:00
|
|
|
end.to raise_error(/expected to find field "no such field"/)
|
2011-03-25 06:35:59 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with should not" do
|
|
|
|
it "fails if there is such a field and it is not checked" do
|
|
|
|
expect do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(html).not_to have_unchecked_field('unchecked field')
|
2012-07-09 07:33:45 -04:00
|
|
|
end.to raise_error(/expected not to find field "unchecked field"/)
|
2011-03-25 06:35:59 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "passes if there is such a field but it is checked" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(html).not_to have_unchecked_field('it is checked')
|
2011-03-25 06:35:59 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "passes if there is no such field" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(html).not_to have_unchecked_field('no such field')
|
2011-03-25 06:35:59 -04:00
|
|
|
end
|
|
|
|
end
|
2015-08-24 01:14:48 -04:00
|
|
|
|
2014-06-11 14:52:29 -04:00
|
|
|
it "supports compounding" do
|
|
|
|
expect(html).to have_unchecked_field('it is checked').or have_unchecked_field('unchecked field')
|
|
|
|
end if RSpec::Version::STRING.to_f >= 3.0
|
2011-03-25 06:35:59 -04:00
|
|
|
end
|
|
|
|
|
2011-03-25 06:46:31 -04:00
|
|
|
describe "have_select matcher" do
|
|
|
|
let(:html) { '<label>Select Box<select></select></label>' }
|
|
|
|
|
2011-04-26 05:56:37 -04:00
|
|
|
it "gives proper description" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(have_select('Select Box').description).to eq("have select box \"Select Box\"")
|
2011-04-26 05:56:37 -04:00
|
|
|
end
|
2015-08-24 01:14:48 -04:00
|
|
|
|
2014-07-02 14:17:53 -04:00
|
|
|
it "gives proper description for a given selected value" do
|
|
|
|
expect(have_select('Select Box', selected: 'some value').description).to eq("have select box \"Select Box\" with \"some value\" selected")
|
|
|
|
end
|
2011-04-26 05:56:37 -04:00
|
|
|
|
2011-03-25 06:46:31 -04:00
|
|
|
it "passes if there is such a select" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(html).to have_select('Select Box')
|
2011-03-25 06:46:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "fails if there is no such select" do
|
|
|
|
expect do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(html).to have_select('No such Select box')
|
2012-07-09 07:33:45 -04:00
|
|
|
end.to raise_error(/expected to find select box "No such Select box"/)
|
2011-03-25 06:46:31 -04:00
|
|
|
end
|
2015-08-24 01:14:48 -04:00
|
|
|
|
2014-06-11 14:52:29 -04:00
|
|
|
it "supports compounding" do
|
|
|
|
expect(html).to have_select('Not this one').or have_select('Select Box')
|
|
|
|
end if RSpec::Version::STRING.to_f >= 3.0
|
2011-03-25 06:46:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "have_table matcher" do
|
|
|
|
let(:html) { '<table><caption>Lovely table</caption></table>' }
|
|
|
|
|
2011-04-26 05:56:37 -04:00
|
|
|
it "gives proper description" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(have_table('Lovely table').description).to eq("have table \"Lovely table\"")
|
2011-04-26 05:56:37 -04:00
|
|
|
end
|
2014-02-16 12:13:58 -05:00
|
|
|
|
2011-03-25 06:46:31 -04:00
|
|
|
it "passes if there is such a select" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(html).to have_table('Lovely table')
|
2011-03-25 06:46:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "fails if there is no such select" do
|
|
|
|
expect do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(html).to have_table('No such Table')
|
2012-07-09 07:33:45 -04:00
|
|
|
end.to raise_error(/expected to find table "No such Table"/)
|
2011-03-25 06:46:31 -04:00
|
|
|
end
|
2015-08-24 01:14:48 -04:00
|
|
|
|
2014-06-11 14:52:29 -04:00
|
|
|
it "supports compounding" do
|
|
|
|
expect(html).to have_table('nope').or have_table('Lovely table')
|
|
|
|
end if RSpec::Version::STRING.to_f >= 3.0
|
2011-03-25 06:46:31 -04:00
|
|
|
end
|
2011-02-04 08:47:15 -05:00
|
|
|
end
|