require 'webrat' require 'suhyo' World(Webrat::Matchers) include Suhyo::ViewMatchers include Suhyo::HashMatchers # The form class can be something like "user search," which will find form.user_search When /^I press "([^\"]*)" in the "([^\"]*)" form$/ do |button, form_class| within '.' + form_class.downcase.gsub(' ', '_') do |scope| scope.click_button(button) end end Then /^I should see a link that says "([^\"]*)"$/ do |text| response.should have_link(:text => text) end Then /^I should not see a link that says "([^\"]*)"$/ do |text| response.should_not have_link(:text => text) end Then /^I should see a link to "([^\"]*)"$/ do |url| response.should have_link(:url => url) end Then /^I should not see a link to "([^\"]*)"$/ do |url| response.should_not have_link(:url => url) end Then /^I should see a button that says "([^\"]*)"$/ do |text| response.should have_button(:text => text) end Then /^I should not see a button that says "([^\"]*)"$/ do |text| response.should_not have_button(:text => text) end Then /^the page title should be "([^\"]*)"$/ do |title| if Suhyo.config.site_title_ends_in title = title + Suhyo.config.site_title_ends_in end response.should have_selector('title', :content => title) end Then /^I should see "([^\"]*)" before "([^\"]*)"$/ do |first, second| response.should contain_in_order(first, :before => second) end Then /^I should see "([^\"]*)" after "([^\"]*)"$/ do |second, first| response.should contain_in_order(second, :after => first) end module Suhyo module ParseQueryHelper def parse_query_string(str) str.split('&').inject({}) do |hash, pair| key, value = pair.split('=') hash[key] = value hash end end end end World(::Suhyo::ParseQueryHelper) # "At" instead of "on" because "on" would create an ambiguous match Then /^I should be at (.+) with the query string "([^\"]*)"$/ do |page_name, query_string| uri = URI.parse(current_url) uri.path.should == path_to(page_name) expected_query_hash = parse_query_string(query_string) actual_query_hash = parse_query_string(uri.query) actual_query_hash.should == expected_query_hash end Then /^I should be at (.+) with the query string including "([^\"]*)"$/ do |page_name, query_string| uri = URI.parse(current_url) uri.path.should == path_to(page_name) expected_query_hash = parse_query_string(query_string) actual_query_hash = parse_query_string(uri.query) actual_query_hash.should include_hash(expected_query_hash) end