From e51e47c7d7aab7d686be99f68c9a88588be94cc8 Mon Sep 17 00:00:00 2001 From: Hiroshi Saito Date: Tue, 26 Apr 2011 18:56:37 +0900 Subject: [PATCH] description methods for Capybara::RSpecMatchers --- lib/capybara/rspec/matchers.rb | 8 +++++++ spec/rspec/matchers_spec.rb | 44 ++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/lib/capybara/rspec/matchers.rb b/lib/capybara/rspec/matchers.rb index fc40ce9f4..33689573c 100644 --- a/lib/capybara/rspec/matchers.rb +++ b/lib/capybara/rspec/matchers.rb @@ -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] @@ -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] diff --git a/spec/rspec/matchers_spec.rb b/spec/rspec/matchers_spec.rb index 17d5c5ab9..bd0e1a3a5 100644 --- a/spec/rspec/matchers_spec.rb +++ b/spec/rspec/matchers_spec.rb @@ -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 @@ -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 @@ -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 @@ -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 @@ -299,6 +315,10 @@ describe "have_link matcher" do let(:html) { 'Just a link' } + 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 @@ -313,6 +333,10 @@ describe "have_button matcher" do let(:html) { '' } + 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 @@ -327,6 +351,10 @@ describe "have_field matcher" do let(:html) { '

' } + 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 @@ -344,6 +372,10 @@ ' 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') @@ -385,6 +417,10 @@ ' 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') @@ -423,6 +459,10 @@ describe "have_select matcher" do let(:html) { '' } + 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 @@ -437,6 +477,10 @@ describe "have_table matcher" do let(:html) { '
Lovely 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