Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 23rd, 2012  |  syntax: None  |  size: 0.69 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. RSpec::Matchers.define :have_country do |expected|
  2.   match do |actual|
  3. # usage:
  4. #  field_labeled('Select your address').should have_option("Home Address")
  5. RSpec::Matchers.define :have_option do |expected|
  6.   def options_for(select_field)
  7.     select_field.all('option').map &:text
  8.   end
  9.    
  10.   match do |select_field|
  11.     select_field.has_selector?('option', :text => expected)
  12.   end
  13.    
  14.   failure_message_for_should do |actual|
  15.     "Expected this select field to have the following option: '#{expected}'. Actual options: #{options_for(actual).inspect}"
  16.   end
  17.      
  18.   failure_message_for_should_not do |actual|
  19.     "Expected the select field not to have the following option: '#{expected}'. It did!"
  20.   end
  21. end