Skip to content

Instantly share code, notes, and snippets.

@poulter7
Created November 25, 2011 01:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save poulter7/1392636 to your computer and use it in GitHub Desktop.
Save poulter7/1392636 to your computer and use it in GitHub Desktop.
Detecting flashes in Ruby
# 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
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