[rspec-users] should_redirect_to in rspec-0.8.0 / rspec_on_rails 1453

David Chelimsky dchelimsky at gmail.com
Thu Feb 1 18:23:18 EST 2007


On 2/1/07, s.ross <cwdinfo at gmail.com> wrote:
> I changed it to:
>
> response.should_redirect_to
>
> and it worked. I'm most interested in whether, given a set of circumstances,
> a particular redirection happens, so I think it has to go after the post.
>
> I'm not certain how controller.should_redirect_to would answer this
> question.
>
> Thoughts?

Definitely use response.should_redirect_to after the action. The
before the action version is going to be deprecated (it is invasive
and buggy).

Also, if you're using the trunk, I'd recommend that you give the
matcher equivalent a shot:

response.should redirect_to #no space after should

Cheers,
David

>
>
>
> On Feb 1, 2007, at 1:20 PM, Robert Martin wrote:
> The "should-redirect-to" has to be called before the 'post'.  I think it's
> setting up a mock.
>
> On Feb 1, 2007, at 1:23 PM, s.ross wrote:
>
> I have a spec:
>
>    specify "a post with no user id should add a record" do
>      post :edit_or_create, :user => {:login => 'joeschmoe', :email =>
> 'joe at shmoe.com', :email_confirmation => 'joe at shmoe.com', :full_name
> => 'Joe Schmoe'}
>      assigns[:user].should_not_be_nil
>      assigns[:user].new_record?.should_not_be(true)
>      flash[:notice].should_match(/user added/)
>      response.should_be_redirect
>      puts "redirecting to #{response.redirect_url}"
>      puts "this response was #{response.redirect?}"
>      controller.should_redirect_to 'http://test.host/user'
>    end
>
> the puts statements output the following:
>
> redirecting to http://test.host/user
> this response was true
>
> Any idea why this line:
>
> controller.should_redirect_to 'http://test.host/user'
>
> would fail with the message:
>
> 'Given a UserController edit a post with no user id should add a
> record' FAILED
> controller expected call to redirect_to "http://test.host/user" but
> it was never received
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
>
> ----
> Robert C. Martin (Uncle Bob)  | email: unclebob at objectmentor.com
> Object Mentor Inc.            | blog:  www.butunclebob.com
> The Agile Transition Experts  | web:   www.objectmentor.com
> 800-338-6716                  |
>
>
>
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


More information about the rspec-users mailing list