Skip to content

Instantly share code, notes, and snippets.

@sidwood
Created January 16, 2012 14:13
Show Gist options
  • Save sidwood/1621048 to your computer and use it in GitHub Desktop.
Save sidwood/1621048 to your computer and use it in GitHub Desktop.
Quick example of cucumber support code
# features/step_definitions/search_steps.rb
When /^I search for "([^"]*)"$/ do |search_term|
search_catalogue_with search_term, :using_direct_model_access
end
# features/support/search_support.rb
module SearchSupport
class SearchAutomator
extend Capybara::DSL
def self.search_with(term)
visit '/'
fill_in "search_term", with: term
click_on "Search"
end
end
def search_catalogue_with(term, options=nil)
if options == :using_direct_model_access
# bypass the view and controller to test the model layer directly
# do this first, let cucumber drive the model api
# drop down to rspec once you have a model api that looks good
Catalogue.search(term)
else
# when rspec coverage of model is complete
# use an automator to test the full stack
# let the automator drive your routes, controllers and view
# drop down to rspec again if you feel any of those need more attention
SearchAutomator.search_with(term)
end
end
end
World(SearchSupport)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment