From 0c494500c96ddc27d8378f34c626d2e7a676dbad Mon Sep 17 00:00:00 2001 From: Rob Holland Date: Wed, 2 Dec 2009 16:56:23 +0000 Subject: [PATCH] Use the Capybara.default_selector instead of hard coding :css into the web_steps. --- generators/cucumber/templates/capybara_env.rb | 6 ++++++ .../cucumber/templates/web_steps/capybara_steps.rb | 12 ++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/generators/cucumber/templates/capybara_env.rb b/generators/cucumber/templates/capybara_env.rb index a741d004..278a93dc 100644 --- a/generators/cucumber/templates/capybara_env.rb +++ b/generators/cucumber/templates/capybara_env.rb @@ -18,3 +18,9 @@ # would prevent the drivers from working. Capybara uses DatabaseCleaner to # wipe the database before each Scenario instead of using transactions. Cucumber::Rails::World.use_transactional_fixtures = false + +# Capybara defaults to XPATH selectors rather than Webrat's default of CSS. In +# order to ease the transition to Capybara we set the default here. If you'd +# prefer to use XPATH just remove this line and adjust any selectors in your +# steps to use the XPATH syntax. +Capybara.default_selector = :css diff --git a/generators/cucumber/templates/web_steps/capybara_steps.rb b/generators/cucumber/templates/web_steps/capybara_steps.rb index e105e737..79bb453b 100644 --- a/generators/cucumber/templates/web_steps/capybara_steps.rb +++ b/generators/cucumber/templates/web_steps/capybara_steps.rb @@ -21,8 +21,8 @@ click_link(link) end -When /^(?:|I )follow "([^\"]*)" within "([^\"]*)"$/ do |link, parent| - within(parent, :css) do +When /^(?:|I )follow "([^\"]*)" within "([^\"]*)"$/ do |link, selector| + within(selector) do click_link(link) end end @@ -128,7 +128,7 @@ end Then /^(?:|I )should see "([^\"]*)" within "([^\"]*)"$/ do |text, selector| - within(selector, :css) do |content| + within(selector) do |content| if defined?(Spec::Rails::Matchers) content.should have_content(text) else @@ -147,7 +147,7 @@ end Then /^(?:|I )should see \/([^\/]*)\/ within "([^\"]*)"$/ do |regexp, selector| - within(selector, :css) do |content| + within(selector) do |content| regexp = Regexp.new(regexp) if defined?(Spec::Rails::Matchers) content.should have_xpath('//*', :text => regexp) @@ -166,7 +166,7 @@ end Then /^(?:|I )should not see "([^\"]*)" within "([^\"]*)"$/ do |text, selector| - within(selector, :css) do |content| + within(selector) do |content| if defined?(Spec::Rails::Matchers) content.should_not have_content(text) else @@ -185,7 +185,7 @@ end Then /^(?:|I )should not see \/([^\/]*)\/ within "([^\"]*)"$/ do |regexp, selector| - within(selector, :css) do |content| + within(selector) do |content| regexp = Regexp.new(regexp) if defined?(Spec::Rails::Matchers) content.should_not have_xpath('//*', :text => regexp)