Hi,
I want to test the user controller, how can i do
the code is
if @user.save
redirect_to :action => "confirm"
else
.....
test
user = User.new(:email => "blad-O5WfVfzUwx8@public.gmane.org",
:password => "12345",
:name => "you")
post :create
user.should_receive(:save).and_return(true)
response.should redirect_to(''confirm'')
the error
1) UsersController GET create should save redirect to confirm
Failure/Error: response.should redirect_to(:action =>
''confirm'')
Expected response to be a <:redirect>, but was <200>.
Expected block to return true value.
please help
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
You have to send params along with call to post. Since there are no params in post, it goes to the else section of you controller, where you render a action, and response code for render is 200. So the test fails saying that you expected a redirect but got render. Chirag http://sumeruonrails.com On Mon, Jul 18, 2011 at 7:14 PM, Yennie <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I want to test the user controller, how can i do > > the code is > > if @user.save > redirect_to :action => "confirm" > else > ..... > > > test > user = User.new(:email => "blad-O5WfVfzUwx8@public.gmane.org", > :password => "12345", > :name => "you") > post :create > user.should_receive(:save).and_return(true) > response.should redirect_to(''confirm'') > > > the error > > 1) UsersController GET create should save redirect to confirm > Failure/Error: response.should redirect_to(:action => ''confirm'') > Expected response to be a <:redirect>, but was <200>. > Expected block to return true value. > > please help > > > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jul 18, 9:57 am, Chirag Singhal <chirag.sing...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> You have to send params along with call to post. > Since there are no params in post, it goes to the else section of you > controller, where you render a action, and response code for render is 200. > So the test fails saying that you expected a redirect but got render.Can you give me an example that how to send the param to the post. I am pretty new with testing controller in rails> > Chiraghttp://sumeruonrails.com > > > > > > > > On Mon, Jul 18, 2011 at 7:14 PM, Yennie <joanne0...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Hi, > > > I want to test the user controller, how can i do > > > the code is > > > if @user.save > > redirect_to :action => "confirm" > > else > > ..... > > > test > > user = User.new(:email => "b...-O5WfVfzUwx8@public.gmane.org", > > :password => "12345", > > :name => "you") > > post :create > > user.should_receive(:save).and_return(true) > > response.should redirect_to(''confirm'') > > > the error > > > 1) UsersController GET create should save redirect to confirm > > Failure/Error: response.should redirect_to(:action => ''confirm'') > > Expected response to be a <:redirect>, but was <200>. > > Expected block to return true value. > > > please help > > > -- > > You received this message because you are subscribed to the Google Groups > > "Ruby on Rails: Talk" group. > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit this group at > >http://groups.google.com/group/rubyonrails-talk?hl=en.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Your test can be something like this:
post :create, :user => {:email =>
"test_email-O5WfVfzUwx8@public.gmane.org", :password =>
"12345", :name => "you"}
response.should redirect_to(''confirm'')
Chirag
http://sumeruonrails.com
On Mon, Jul 18, 2011 at 7:38 PM, Yennie
<joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
>
> On Jul 18, 9:57 am, Chirag Singhal
<chirag.sing...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> > You have to send params along with call to post.
> > Since there are no params in post, it goes to the else section of you
> > controller, where you render a action, and response code for render is
> 200.
> > So the test fails saying that you expected a redirect but got render.
>
> Can you give me an example that how to send the param to the post. I
> am pretty new with testing controller in rails
> >
> > Chiraghttp://sumeruonrails.com
> >
> >
> >
> >
> >
> >
> >
> > On Mon, Jul 18, 2011 at 7:14 PM, Yennie
<joanne0...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> > > Hi,
> >
> > > I want to test the user controller, how can i do
> >
> > > the code is
> >
> > > if @user.save
> > > redirect_to :action => "confirm"
> > > else
> > > .....
> >
> > > test
> > > user = User.new(:email =>
"b...-O5WfVfzUwx8@public.gmane.org",
> > > :password => "12345",
> > > :name => "you")
> > > post :create
> > > user.should_receive(:save).and_return(true)
> > > response.should redirect_to(''confirm'')
> >
> > > the error
> >
> > > 1) UsersController GET create should save redirect to confirm
> > > Failure/Error: response.should redirect_to(:action =>
''confirm'')
> > > Expected response to be a <:redirect>, but was
<200>.
> > > Expected block to return true value.
> >
> > > please help
> >
> > > --
> > > You received this message because you are subscribed to the
Google
> Groups
> > > "Ruby on Rails: Talk" group.
> > > To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> .
> > > To unsubscribe from this group, send email to
> > >
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> > > For more options, visit this group at
> > >http://groups.google.com/group/rubyonrails-talk?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To unsubscribe from this group, send email to
>
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
You may also want to read through Rails guides on testing - http://guides.rubyonrails.org/testing.html#functional-tests-for-your-controllers Chirag http://sumeruonrails.com On Tue, Jul 19, 2011 at 9:34 AM, Chirag Singhal <chirag.singhal-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> Your test can be something like this: > > post :create, :user => {:email => "test_email-O5WfVfzUwx8@public.gmane.org", :password => > "12345", :name => "you"} > response.should redirect_to(''confirm'') > > > > Chirag > http://sumeruonrails.com > > > > On Mon, Jul 18, 2011 at 7:38 PM, Yennie <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> >> >> On Jul 18, 9:57 am, Chirag Singhal <chirag.sing...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> > You have to send params along with call to post. >> > Since there are no params in post, it goes to the else section of you >> > controller, where you render a action, and response code for render is >> 200. >> > So the test fails saying that you expected a redirect but got render. >> >> Can you give me an example that how to send the param to the post. I >> am pretty new with testing controller in rails >> > >> > Chiraghttp://sumeruonrails.com >> > >> > >> > >> > >> > >> > >> > >> > On Mon, Jul 18, 2011 at 7:14 PM, Yennie <joanne0...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> > > Hi, >> > >> > > I want to test the user controller, how can i do >> > >> > > the code is >> > >> > > if @user.save >> > > redirect_to :action => "confirm" >> > > else >> > > ..... >> > >> > > test >> > > user = User.new(:email => "b...-O5WfVfzUwx8@public.gmane.org", >> > > :password => "12345", >> > > :name => "you") >> > > post :create >> > > user.should_receive(:save).and_return(true) >> > > response.should redirect_to(''confirm'') >> > >> > > the error >> > >> > > 1) UsersController GET create should save redirect to confirm >> > > Failure/Error: response.should redirect_to(:action => ''confirm'') >> > > Expected response to be a <:redirect>, but was <200>. >> > > Expected block to return true value. >> > >> > > please help >> > >> > > -- >> > > You received this message because you are subscribed to the Google >> Groups >> > > "Ruby on Rails: Talk" group. >> > > To post to this group, send email to >> rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> > > To unsubscribe from this group, send email to >> > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> > > For more options, visit this group at >> > >http://groups.google.com/group/rubyonrails-talk?hl=en. >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Ruby on Rails: Talk" group. >> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> For more options, visit this group at >> http://groups.google.com/group/rubyonrails-talk?hl=en. >> >> >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jul 19, 12:04 am, Chirag Singhal <chirag.sing...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Your test can be something like this: > > post :create, :user => {:email => "test_em...-O5WfVfzUwx8@public.gmane.org", :password => > "12345", :name => "you"} > response.should redirect_to(''confirm'')Thank you Chirag, it s good now> > Chiraghttp://sumeruonrails.com > > > > > > > > On Mon, Jul 18, 2011 at 7:38 PM, Yennie <joanne0...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > On Jul 18, 9:57 am, Chirag Singhal <chirag.sing...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > You have to send params along with call to post. > > > Since there are no params in post, it goes to the else section of you > > > controller, where you render a action, and response code for render is > > 200. > > > So the test fails saying that you expected a redirect but got render. > > > Can you give me an example that how to send the param to the post. I > > am pretty new with testing controller in rails > > > > Chiraghttp://sumeruonrails.com > > > > On Mon, Jul 18, 2011 at 7:14 PM, Yennie <joanne0...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Hi, > > > > > I want to test the user controller, how can i do > > > > > the code is > > > > > if @user.save > > > > redirect_to :action => "confirm" > > > > else > > > > ..... > > > > > test > > > > user = User.new(:email => "b...-O5WfVfzUwx8@public.gmane.org", > > > > :password => "12345", > > > > :name => "you") > > > > post :create > > > > user.should_receive(:save).and_return(true) > > > > response.should redirect_to(''confirm'') > > > > > the error > > > > > 1) UsersController GET create should save redirect to confirm > > > > Failure/Error: response.should redirect_to(:action => ''confirm'') > > > > Expected response to be a <:redirect>, but was <200>. > > > > Expected block to return true value. > > > > > please help > > > > > -- > > > > You received this message because you are subscribed to the Google > > Groups > > > > "Ruby on Rails: Talk" group. > > > > To post to this group, send email to rubyonrails-talk@googlegroups.com > > . > > > > To unsubscribe from this group, send email to > > > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > > For more options, visit this group at > > > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > > -- > > You received this message because you are subscribed to the Google Groups > > "Ruby on Rails: Talk" group. > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit this group at > >http://groups.google.com/group/rubyonrails-talk?hl=en.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.