Skip to content

Commit

Permalink
description methods for Capybara::RSpecMatchers
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroshi committed Apr 26, 2011
1 parent aa5fefa commit e51e47c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/capybara/rspec/matchers.rb
Expand Up @@ -27,6 +27,10 @@ def failure_message_for_should_not
"expected #{selector_name} not to return anything"
end

def description
"has #{selector_name}"
end

def selector_name
name = "#{normalized.name} #{normalized.locator.inspect}"
name << " with text #{normalized.options[:text].inspect}" if normalized.options[:text]
Expand Down Expand Up @@ -82,6 +86,10 @@ def failure_message_for_should_not
"expected #{selector_name} not to return anything"
end

def description
"has #{selector_name}"
end

def selector_name
selector_name = "#{name} #{locator.inspect}"
selector_name << " with text #{options[:text].inspect}" if options[:text]
Expand Down
44 changes: 44 additions & 0 deletions spec/rspec/matchers_spec.rb
Expand Up @@ -9,6 +9,10 @@
include Capybara::RSpecMatchers

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 "with should" do
it "passes if has_css? returns true" do
Expand Down Expand Up @@ -87,6 +91,10 @@
end

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 "with should" do
it "passes if has_css? returns true" do
Expand Down Expand Up @@ -145,6 +153,10 @@
end

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 "with should" do
it "passes if has_css? returns true" do
Expand Down Expand Up @@ -229,6 +241,10 @@
end

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 "with should" do
it "passes if has_css? returns true" do
Expand Down Expand Up @@ -299,6 +315,10 @@
describe "have_link matcher" do
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
html.should have_link('Just a link')
end
Expand All @@ -313,6 +333,10 @@
describe "have_button matcher" do
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
html.should have_button('A button')
end
Expand All @@ -327,6 +351,10 @@
describe "have_field matcher" do
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
html.should have_field('Text field')
end
Expand All @@ -344,6 +372,10 @@
<label>unchecked field<input type="checkbox"/></label>'
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
it "passes if there is such a field and it is checked" do
html.should have_checked_field('it is checked')
Expand Down Expand Up @@ -385,6 +417,10 @@
<label>unchecked field<input type="checkbox"/></label>'
end

it "gives proper description" do
have_unchecked_field('unchecked field').description.should == "has unchecked_field \"unchecked field\""
end

context "with should" do
it "passes if there is such a field and it is not checked" do
html.should have_unchecked_field('unchecked field')
Expand Down Expand Up @@ -423,6 +459,10 @@
describe "have_select matcher" do
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
html.should have_select('Select Box')
end
Expand All @@ -437,6 +477,10 @@
describe "have_table matcher" do
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
html.should have_table('Lovely table')
end
Expand Down

0 comments on commit e51e47c

Please sign in to comment.