Forked from sidwood/cucumber_support_code_example.rb
Created
November 23, 2013 19:25
-
-
Save hugobarauna/7618807 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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