ruby on rails - Cucumber test redirect -
have found advice: http://openmonkey.com/articles/2009/03/cucumber-steps-for-testing-page-urls-and-redirects
i have added above methods web steps definitons, have written feature, ran , got error nil objects. after investigation, have noticed, have no response , request objects, nil
from web_steps.rb:
then /^i should on (.+?) page$/ |page_name| request.request_uri.should == send("#{page_name.downcase.gsub(' ','_')}_path") response.should be_success end /^i should redirected (.+?) page$/ |page_name| request.headers['http_referer'].should_not be_nil request.headers['http_referer'].should_not == request.request_uri "i should on #{page_name} page" end
the request , response objects nil, why ?
are using webrat or capybara driver within cucumber? can tell looking @ features/support/env.rb
. i'm using capybara, mine includes these lines:
require 'capybara/rails' require 'capybara/cucumber' require 'capybara/session'
the default used webrat switched capybara, lot of code older examples on web doesn't work properly. assuming you're using capybara too...
request.request_uri - want current_url instead. returns full url of page driver on. less useful getting path, use helper:
def current_path uri.parse(current_url).path end
response.should be_success - 1 of biggest frustrations working capybara (and extent, cucumber) is downright zealous interacting user can see. can't test response codes using capybara. instead, should test user-visible responses. redirects easy test; assert page should on. 403s little tricker. in application, that's page title "access denied," test that:
within('head title') { page.should_not have_content('access denied') }
here's how i'd write scenario test link supposed redirect , not supposed redirect @ other times:
scenario: redirects given should redirect when click "sometimes redirecting link" should on "redirected_to" page scenario: not redirect given shouldn't redirect when click "sometimes redirecting link" <assert should have happened>
Thank you for providing useful content Ruby on Rails Online Training Bangalore
ReplyDelete