Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
# This was ripped from one of our Webrat suites - Capybara would be similar, but slightly different...
Then /^I should( not)? see "([^\"]*)" in (.+)$/ do |negatory, text, area|
within(selector_for(area)) do |content|
if negatory.blank? then
content.should contain(text)
else
content.should_not contain(text)
end
end
end
When I am on the login page
And I fill in "Username" with "joe"
And I fill in "Password" with "password"
And I press "Log In"
Then I should be on the dashboard
And I should see "Welcome back, Joe!" in the notification area
Given I am logged in as joe
# When I am on the Dashboard
# And I follow "Little Johnny"
# Then I should be on the Student page for "Little Johnny"
# In paths.rb :
when /the Student page for "([^"]+)"/i
user=User.find_by_name($1)
"/classes/#{user.school_classes.first.id}/students/#{user.id}"
Then I should see "Welcome Back, Jason!" in the notification area
# Put this in features/support/selectors.rb
module AreaHelpers
# Maps a name to a selector.
def selector_for(area_name)
case area_name
when /^"(.*)"$/
$1
when /the notification area/
'#notice'
when /the error message/
'#error'
when /the menu/
'#menu'
when /the sidebar/
'#sidebar'
when /the requests table/
'table#requests'
when /the history/
'.history'
# Add more mappings here.
else
raise "Can't find mapping from \"#{area_name}\" to a selector.\n" +
"Now, go and add a mapping in #{__FILE__}"
end
end
end
World(AreaHelpers)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment