require 'uri' require 'cgi' require File.expand_path("../../support/paths.rb", __FILE__) require File.expand_path("../../support/selectors.rb", __FILE__) def get_parent(parent) case parent.sub(/^the\s/, '') when "flash notice"; ".flash" when "first set of options"; "#option_type_#{@product.option_types.first.id}" when "second set of options"; "#option_type_#{@product.option_types[1].id}" when "variant images label"; "#variant-images" when "price"; ".prices .price" else "[set-your-parent] #{parent}" end end #======================================================================== # Givens Given /^I'm on the ((?!page).*) page$/ do |path| path = "#{path.downcase.gsub(/\s/, '_')}_path".to_sym begin visit send(path) rescue puts "#{path} could not be found!" end end Given /^I'm on the ((?!page).*) page for (.*)$/ do |path, id| id = case id when "the first product" @product ||= Product.last when 'option type "Size"' @option_type = OptionType.find_by_presentation!("Size") else id end path = "#{path.downcase.gsub(/\s/, '_')}_path".to_sym begin visit send(path, id) rescue puts "#{path}(#{id.to_param}) could not be found!" end end #======================================================================== # Actions When /^(?:|I )press "([^"]*)"$/ do |button| # wtf button text spree! button = "#popup_ok" if button == "OK" click_button(button) end When /^I press "([^"]*)" in (.*)$/ do |button, parent| # wtf button text spree! button = "#popup_ok" if button == "OK" within get_parent(parent) do click_button(button) end end When /^(?:|I )follow "([^"]*)"$/ do |link| click_link(link) end When /^(?:|I )follow "([^"]*)" within (.*)$/ do |link, parent| within get_parent(parent) do click_link(link) end end When /^I wait for (\d+) seconds?$/ do |seconds| sleep seconds.to_f end When /^I confirm the popup message$/ do find_by_id("popup_ok").click end #======================================================================== # Assertions Then /^I should see "([^"]*)"$/ do |text| assert page.has_content?(text) end Then /^I should see "([^"]*)" in (.*)$/ do |text, parent| within get_parent(parent) do assert page.has_content?(text) end end Then /^I should not see "([^"]*)"$/ do |text| assert_not page.has_content?(text) end Then /^I should not see "([^"]*)" in (.*)$/ do |text, parent| within get_parent(parent) do assert_not page.has_content?(text) end end Then /^"([^"]*)" should equal "([^"]*)"$/ do |field, value| assert_equal value, find_field(field).value end Then /^"([^"]*)" should have "([^"]*)" selected$/ do |field, value| field = find_field(field) has_match = field.text =~ /#{value}/ has_match = field.value =~ /#{value}/ unless has_match assert has_match end #======================================================================== # Forms When /^(?:|I )fill in "([^"]*)" with "([^"]*)"$/ do |field, value| fill_in(field, :with => value) end When /^(?:|I )fill in the following:$/ do |fields| fields.rows_hash.each do |name, value| When %{I fill in "#{name}" with "#{value}"} end end When /^(?:|I )select "([^"]*)" from "([^"]*)"$/ do |value, field| select(value, :from => field) end