4

I am running rails 3.0.0, rspec-rails 2.0.0.beta.20, webrat 0.7.2.beta.1, cucumber-rails 0.3.2 I have this scenario:

Scenario:
  Given I am on the new account page
  And I fill in "Name" with "John Doe"
  When I press "Create"
  Then I should be on the access page

When I run it I get:

expected: "/access",
got: "/accounts"

Like its not following the redirect_to in the controller:

#accounts_controller.rb
def create
  @account = Account.new(params[:account])
  if @account.save
    flash[:notice] = "Saved!"
    redirect_to access_url  
  else
    flash[:alert] = "Error!"
    render :new
  end
end

Am I missing a step? I thought webrat followed all redirects. Thanks

Using launchy gem I get a page that says:

"You are being redirected" with a link to the access_path

?

Cameron
  • 4,181
  • 9
  • 36
  • 40
  • Are you sure it's not following redirects? Maybe the form isn't valid and it renders the new action again? You can try the 'show me the page' step (you'll need the launchy gem for that) to see if it isn't showing any errors you missed? – Cimm Sep 03 '10 at 13:41
  • Thanks might try it. Can't see any reasons why it failing, even if I remove the render :new it still come up the same... – Cameron Sep 03 '10 at 13:50

3 Answers3

2

Not sure if this applies in Rails 3, but can you just try this method "follow_redirect!"

Rishav Rastogi
  • 15,484
  • 3
  • 42
  • 47
0

this is answered here:

Webrat and Rails: Using assert_contain after click_button gives me "You are being redirected"

solution worked for me.

Community
  • 1
  • 1
Greg Fairbrother
  • 1,041
  • 8
  • 13
0

I found this solution which helped me.

http://baldowl.github.com/2010/12/06/coercing-cucumber-and-webrat-to-cooperate.html

map7
  • 5,096
  • 6
  • 65
  • 128