Hello All, I am a rspec beginner and I am trying to find a way out to write render expectation in controller spec.I used the following ways render ''/channels/createchannel.html.erb'' view.should_receive(:render).with(:action => "createchannel") ChannelsController.expect_render(:action => "createchannel") ChannelsController.render_template(:action => "createchannel") controller.expect_render(:action => "createchannel") controller.render_template(:action => "createchannel") All fail giving a NoMethodError ********************************************************************************** My spec is as follows require File.dirname(__FILE__) + ''/../spec_helper'' describe ChannelsController do it "should re-direct to create channel" do Channel.stub!(:checkChannel?).and_return(1) ChannelsController.expect_render(:action => "createchannel") #view.should_receive(:render).with(:action => "createchannel") #render ''/channels/createchannel.html.erb'' end end ********************************************************************************** Can anyone please let me know how this can be fixed.? Thanks & Regards Chandrika -- 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 12, 4:35 am, Chandu80 <chandu.she...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello All, > > *************************************************************************** ******* > My spec is as follows > > require File.dirname(__FILE__) + ''/../spec_helper'' > > describe ChannelsController do > it "should re-direct to create channel" do > Channel.stub!(:checkChannel?).and_return(1) > ChannelsController.expect_render(:action => "createchannel") > > #view.should_receive(:render).with(:action => "createchannel") > #render ''/channels/createchannel.html.erb'' > end > > end > *************************************************************************** ******* > > Can anyone please let me know how this can be fixed.?Check out http://rspec.info/rails/writing/controllers.html Basically you need to do a get or post (in your case probably post :createchannel) and then there''s a response object you can have expectations on, such as response.should render_template(''createchannel.html''). Note, I''m not really sure what the ChannelsController.expect_render(...) does, I''m unfamiliar with that syntax. Thanks, \Peter -- 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.
Bryan Donovan
2011-Jul-13 16:13 UTC
Re: Re: How to write render expectation in Controller Spec?
One good way to see how to write controller specs is to generate one with script/generate (or rails generate if you''re using Rails 3). For example, you could create a new rails app (or use your existing one), and generate an rspec_scaffold. Something like this: rails generate rspec_scaffold Widget name:string .. that will generate a controller spec that will work out of the box if you are using default crud methods. -Bryan On Jul 13, 2011, at 8:54 AM, Peter wrote:> On Jul 12, 4:35 am, Chandu80 <chandu.she...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> Hello All, >> >> *************************************************************************** ******* >> My spec is as follows >> >> require File.dirname(__FILE__) + ''/../spec_helper'' >> >> describe ChannelsController do >> it "should re-direct to create channel" do >> Channel.stub!(:checkChannel?).and_return(1) >> ChannelsController.expect_render(:action => "createchannel") >> >> #view.should_receive(:render).with(:action => "createchannel") >> #render ''/channels/createchannel.html.erb'' >> end >> >> end >> *************************************************************************** ******* >> >> Can anyone please let me know how this can be fixed.? > > > Check out http://rspec.info/rails/writing/controllers.html > Basically you need to do a get or post (in your case probably > post :createchannel) and then there''s a response object you can have > expectations on, such as response.should > render_template(''createchannel.html''). > > Note, I''m not really sure what the > ChannelsController.expect_render(...) does, I''m unfamiliar with that > syntax. > > Thanks, > \Peter > > -- > 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. >-- 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.