Skip to content

Instantly share code, notes, and snippets.

@alext
alext / field_matchers.rb
Created February 21, 2013 10:51
Field matchers
module FieldMatchers
def i_should_see_field(name, options = {})
field = find_field(name)
field.should_not be_nil
case options[:type]
when nil
when 'textarea'
field.tag_name.should == type
else
field.tag_name.should == 'input'
@alext
alext / section_helper.rb
Created May 9, 2012 15:35
Section helper for rspec request specs
module SectionHelper
def selector_of_section(section_name)
case section_name
when 'recent podcasts'
[:css, 'ul.podcasts']
when /^the row containing "[\"]+"$/
[:xpath, "//*[.='#{$1}']/ancestor::tr"]
else
raise "Can't find mapping from \"#{section_name}\" to a section."
end
@alext
alext / path_helpers.rb
Created May 9, 2012 15:32
Some path helpers for rspec request specs.
module PathHelpers
# Takes a URL path (with optional query string), and asserts that it matches the current URL.
def i_should_be_on(path_with_query, options = {})
expected = URI.parse(path_with_query)
current = URI.parse(current_url)
current.path.should == expected.path
unless options[:ignore_query]
Rack::Utils.parse_query(current.query).should == Rack::Utils.parse_query(expected.query)
end