Created
November 25, 2011 01:51
-
-
Save poulter7/1392636 to your computer and use it in GitHub Desktop.
Detecting flashes in Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A generic step to detect for a flash, currently either an alert or a notice (called a notification) | |
# Usage should be: | |
# I should see [notification title] [titletype] | |
# | |
# Notification titles are defined within $ROOT/features/support/flashes.rb | |
Then /^I should see ([^"]*) (alert|notification)$/ do |name, type| | |
within "div#flash-#{type}" do | |
page.should have_content flash_of(name) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module FlashHelpers | |
# Maps a name to a flash message. | |
def flash_of(flash_name) | |
case flash_name | |
when /^invalid sign in$/ | |
'Invalid username or password.' | |
else | |
raise "Can't find mapping for \"#{flash_name}\" to a flash message:.\n" + | |
"Now, go and add a mapping in #{__FILE__}" | |
end | |
end | |
end | |
World(FlashHelpers) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment