1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

description methods for Capybara::RSpecMatchers

This commit is contained in:
Hiroshi Saito 2011-04-26 18:56:37 +09:00
parent aa5fefa385
commit e51e47c7d7
2 changed files with 52 additions and 0 deletions

View file

@ -27,6 +27,10 @@ module Capybara
"expected #{selector_name} not to return anything" "expected #{selector_name} not to return anything"
end end
def description
"has #{selector_name}"
end
def selector_name def selector_name
name = "#{normalized.name} #{normalized.locator.inspect}" name = "#{normalized.name} #{normalized.locator.inspect}"
name << " with text #{normalized.options[:text].inspect}" if normalized.options[:text] name << " with text #{normalized.options[:text].inspect}" if normalized.options[:text]
@ -82,6 +86,10 @@ module Capybara
"expected #{selector_name} not to return anything" "expected #{selector_name} not to return anything"
end end
def description
"has #{selector_name}"
end
def selector_name def selector_name
selector_name = "#{name} #{locator.inspect}" selector_name = "#{name} #{locator.inspect}"
selector_name << " with text #{options[:text].inspect}" if options[:text] selector_name << " with text #{options[:text].inspect}" if options[:text]

View file

@ -9,6 +9,10 @@ describe Capybara::RSpecMatchers do
include Capybara::RSpecMatchers include Capybara::RSpecMatchers
describe "have_css matcher" do describe "have_css matcher" do
it "gives proper description" do
have_css('h1').description.should == "has css \"h1\""
end
context "on a string" do context "on a string" do
context "with should" do context "with should" do
it "passes if has_css? returns true" do it "passes if has_css? returns true" do
@ -87,6 +91,10 @@ describe Capybara::RSpecMatchers do
end end
describe "have_xpath matcher" do describe "have_xpath matcher" do
it "gives proper description" do
have_xpath('//h1').description.should == "has xpath \"\/\/h1\""
end
context "on a string" do context "on a string" do
context "with should" do context "with should" do
it "passes if has_css? returns true" do it "passes if has_css? returns true" do
@ -145,6 +153,10 @@ describe Capybara::RSpecMatchers do
end end
describe "have_selector matcher" do describe "have_selector matcher" do
it "gives proper description" do
have_selector('//h1').description.should == "has xpath \"//h1\""
end
context "on a string" do context "on a string" do
context "with should" do context "with should" do
it "passes if has_css? returns true" do it "passes if has_css? returns true" do
@ -229,6 +241,10 @@ describe Capybara::RSpecMatchers do
end end
describe "have_content matcher" do describe "have_content matcher" do
it "gives proper description" do
have_content('Text').description.should == "has content \"Text\""
end
context "on a string" do context "on a string" do
context "with should" do context "with should" do
it "passes if has_css? returns true" do it "passes if has_css? returns true" do
@ -299,6 +315,10 @@ describe Capybara::RSpecMatchers do
describe "have_link matcher" do describe "have_link matcher" do
let(:html) { '<a href="#">Just a link</a>' } let(:html) { '<a href="#">Just a link</a>' }
it "gives proper description" do
have_link('Just a link').description.should == "has link \"Just a link\""
end
it "passes if there is such a button" do it "passes if there is such a button" do
html.should have_link('Just a link') html.should have_link('Just a link')
end end
@ -313,6 +333,10 @@ describe Capybara::RSpecMatchers do
describe "have_button matcher" do describe "have_button matcher" do
let(:html) { '<button>A button</button><input type="submit" value="Another button"/>' } let(:html) { '<button>A button</button><input type="submit" value="Another button"/>' }
it "gives proper description" do
have_button('A button').description.should == "has button \"A button\""
end
it "passes if there is such a button" do it "passes if there is such a button" do
html.should have_button('A button') html.should have_button('A button')
end end
@ -327,6 +351,10 @@ describe Capybara::RSpecMatchers do
describe "have_field matcher" do describe "have_field matcher" do
let(:html) { '<p><label>Text field<input type="text"/></label></p>' } let(:html) { '<p><label>Text field<input type="text"/></label></p>' }
it "gives proper description" do
have_field('Text field').description.should == "has field \"Text field\""
end
it "passes if there is such a field" do it "passes if there is such a field" do
html.should have_field('Text field') html.should have_field('Text field')
end end
@ -344,6 +372,10 @@ describe Capybara::RSpecMatchers do
<label>unchecked field<input type="checkbox"/></label>' <label>unchecked field<input type="checkbox"/></label>'
end end
it "gives proper description" do
have_checked_field('it is checked').description.should == "has checked_field \"it is checked\""
end
context "with should" do context "with should" do
it "passes if there is such a field and it is checked" do it "passes if there is such a field and it is checked" do
html.should have_checked_field('it is checked') html.should have_checked_field('it is checked')
@ -385,6 +417,10 @@ describe Capybara::RSpecMatchers do
<label>unchecked field<input type="checkbox"/></label>' <label>unchecked field<input type="checkbox"/></label>'
end end
it "gives proper description" do
have_unchecked_field('unchecked field').description.should == "has unchecked_field \"unchecked field\""
end
context "with should" do context "with should" do
it "passes if there is such a field and it is not checked" do it "passes if there is such a field and it is not checked" do
html.should have_unchecked_field('unchecked field') html.should have_unchecked_field('unchecked field')
@ -423,6 +459,10 @@ describe Capybara::RSpecMatchers do
describe "have_select matcher" do describe "have_select matcher" do
let(:html) { '<label>Select Box<select></select></label>' } let(:html) { '<label>Select Box<select></select></label>' }
it "gives proper description" do
have_select('Select Box').description.should == "has select \"Select Box\""
end
it "passes if there is such a select" do it "passes if there is such a select" do
html.should have_select('Select Box') html.should have_select('Select Box')
end end
@ -437,6 +477,10 @@ describe Capybara::RSpecMatchers do
describe "have_table matcher" do describe "have_table matcher" do
let(:html) { '<table><caption>Lovely table</caption></table>' } let(:html) { '<table><caption>Lovely table</caption></table>' }
it "gives proper description" do
have_table('Lovely table').description.should == "has table \"Lovely table\""
end
it "passes if there is such a select" do it "passes if there is such a select" do
html.should have_table('Lovely table') html.should have_table('Lovely table')
end end