Skip to content

Instantly share code, notes, and snippets.

@bagwanpankaj
Created October 17, 2010 12:41
Show Gist options
  • Save bagwanpankaj/630815 to your computer and use it in GitHub Desktop.
Save bagwanpankaj/630815 to your computer and use it in GitHub Desktop.
Webrat Step extension
#Created By Bagwan Pankaj (RailsJaipur) “http://bagwanpankaj.com/”
#This file is an extension of default webrat steps. some of the webrat steps have been extended
#in this file so that one need not to write unrequired steps.
#Extends default
#USE: When I follow //
When /^I follow \/([^\/]*)\/$/ do |regexp_link|
click_link(regexp_link)
end
#USE: When I follow // within ""
When /^I follow \/([^\/]*)\/ within "([^\"]*)"$/ do |regexp_link, parent|
click_link_within(parent,regexp_link)
end
#USE: Then It should not include tag ""
Then /^It should not include tag "([^\"]*)"$/ do |tag|
assert_have_no_selector(tag, :count => 0)
end
#USE: Then It should not include tag "" within ""
Then /^It should not include tag "([^\"]*)" within "([^\"]*)"$/ do |tag_match, parent|
within parent do |scope|
scope.should_not have_selector(tag_match, :count => 0)
end
end
#USE: Then It should not include selector ""
Then /^It should not include selector "([^\"]*)"$/ do |tag|
Then %{It should not include tag \"#{tag}\"}
end
#USE: Then It should not include selector "" within ""
Then /^It should not include selector "([^\"]*)" within "([^\"]*)"$/ do |tag_match, parent|
Then %{It should not include tag \"#{tag_match}\" within \"#{parent.to_s}\"}
end
#USE: Then It should include tag ""
Then /^It should include tag "([^\"]*)"$/ do |tag|
assert_have_selector(tag)
end
#USE: Then It should include tag "" within ""
Then /^It should include tag "([^\"]*)" within "([^\"]*)"$/ do |tag_match, parent|
within parent do |scope|
scope.should have_selector(tag_match)
end
end
#USE: Then It should include selector ""
Then /^It should include selector "([^\"]*)"$/ do |tag|
Then %{It should include tag \"#{tag}\"}
end
#USE: Then It should include selector "" within ""
Then /^It should include selector "([^\"]*)" within "([^\"]*)"$/ do |tag_match, parent|
Then %{It should include tag \"#{tag_match}\" within \"#{parent.to_s}\"}
end
#USE: When I check // within “”
When /^I check \/([^\/]*)\/ within "([^\"]*)"$/ do |field, parent|
within parent do |scope|
regexp = Regexp.new(field)
scope.check(regexp)
end
end
#USE: When /^I check “([^\"]*)” within “”
When /^I check "([^\"]*)" within "([^\"]*)"$/ do |field, parent|
within parent do |scope|
scope.check(field)
end
end
#USE: When /^(?:|I )check //
When /^(?:|I )check \/([^\/]*)\/$/ do |field|
regexp = Regexp.new(field)
check(regexp)
end
#USE: I should be able to see "
"
Then /^I should be able to see (\d+) "([^\"]*)"$/ do |count,selector|
assert_have_selector(selector, :count => count)
end
#USE: I should be able to see "
" within "
"
Then /^I should be able to see (\d+) "([^\"]*)" within "([^\"]*)"$/ do |count,selector, parent|
within parent do |scope|
scope.should have_selector(selector, :count => count)
end
end
When /^(?:|I )choose "([^\"]*)" within "([^\"]*)"$/ do |field,parent|
within parent do |scope|
scope.choose(field)
end
end
When /^(?:|I )choose \/([^\/]*)\/ within "([^\"]*)"$/ do |field,parent|
within parent do |scope|
regexp = Regexp.new(field)
scope.choose(regexp)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment