[rspec-users] can't seem to test redirect?

Harry Bishop lists at ruby-forum.com
Fri Oct 24 14:24:39 EDT 2008


Pat Maddox wrote:
> Harry Bishop <lists at ruby-forum.com> writes:
> 
>>         format.html { redirect_to(@motion) }
>>
>> TIA,
>> Harry
> 
> Can you post your example code as well?  Also, are there any errors?
> Here are my two guesses at this point:
> 
> * you forgot to make a request in the example (post :create)
> * there's some error that is keeping the action from getting to the
>   redirect
> 
> Also, what is the value of response.code in the example?
> 
> Pat

Hi Pat,
My examples code is
  before(:each) do
    login_as(:username)
    @motion = mock(motions(:four))
    @motion.stub!(:new_record?).and_return(true)
    Motion.stub!(:new).and_return(@motion)
    @motion.stub!(:save).and_return(@motion)
    controller.stub!(:redirect_to).with(@motion).and_return(true)

  end

  def do_post
    post :create, {:motion => do_motion_input("ten")} #reads yml input 
as hash
  end

  it "create new proposal with proposer set" do
    do_post
    response.should be_success
    response.should render_template("motions/create")
    response.should redirect_to(@motion)
  end

The only error is the "got no redirect"
response.code is 200
HR
-- 
Posted via http://www.ruby-forum.com/.


More information about the rspec-users mailing list