Chandrika Shenoy
2011-Jul-14 11:34 UTC
[rspec-users] Render expectation in Controller spec
Hello All, I am a rspec beginner and I am trying to find a way out to write render expectation in controller spec.All methods that I used seem to give me a No Method error. My controller code is as follows http://pastie.org/2211944 and my controller test is as follows http://pastie.org/2211951 I also used render ''/channels/createchannel.html.erb'' ChannelsController.expect_render(:action => "createchannel") ChannelsController.render_template(:action => "createchannel") controller.expect_render(:action => "createchannel") controller.render_template(:action => "createchannel") I am using jRuby on Rails1.5.0 and following are the details of gems:- rails-2.3.5 rspec-1.3.0 rspec-rails-1.3.2 It would be great if someone could help me out with this Thanks & Regards Chandrika -- Posted via http://www.ruby-forum.com/.
On Jul 14, 2011, at 6:34 AM, Chandrika Shenoy wrote:> Hello All, > > I am a rspec beginner and I am trying to find a way out to write render > expectation in controller spec.All methods that I used seem to give me a > No Method error. > > My controller code is as follows > http://pastie.org/2211944 > > and my controller test is as follows > http://pastie.org/2211951I don''t understand what the example is supposed to specify. I see a createchannelpage action in the controller, which might render createchannel, but I don''t see a createchannel action. Then the spec is posting to createchannel. What is the intent here?> I also used > render ''/channels/createchannel.html.erb'' > ChannelsController.expect_render(:action => "createchannel") > ChannelsController.render_template(:action => "createchannel") > controller.expect_render(:action => "createchannel") > controller.render_template(:action => "createchannel") > > I am using jRuby on Rails1.5.0 and following are the > details of gems:- > rails-2.3.5 > rspec-1.3.0 > rspec-rails-1.3.2 > > It would be great if someone could help me out with this
Hi David, Sorry about not pasting the createchannel method earlier,here is the revised controller method. http://pastie.org/2217223 I am trying to test the createchannelpage method which is in the Channels Controller.The createchannelpage renders the createchannel action when the checkChannel? returns a true value. Regards Chandrika On Jul 14, 5:30?pm, David Chelimsky <dchelim... at gmail.com> wrote:> On Jul 14, 2011, at 6:34 AM, Chandrika Shenoy wrote: > > > Hello All, > > > I am a rspec beginner and I am trying to find a way out to write render > > expectation in controller spec.All methods that I used seem to give me a > > No Method error. > > > My controller code is as follows > >http://pastie.org/2211944 > > > and my controller test is as follows > >http://pastie.org/2211951 > > I don''t understand what the example is supposed to specify. I see a createchannelpage action in the controller, which might render createchannel, but I don''t see a createchannel action. Then the spec is posting to createchannel. What is the intent here? > > > I also used > > render ''/channels/createchannel.html.erb'' > > ChannelsController.expect_render(:action => "createchannel") > > ChannelsController.render_template(:action => "createchannel") > > controller.expect_render(:action => "createchannel") > > controller.render_template(:action => "createchannel") > > > I am using jRuby on Rails1.5.0 and following are the > > details of gems:- > > rails-2.3.5 > > rspec-1.3.0 > > rspec-rails-1.3.2 > > > It would be great if someone could help me out with this > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
I moved your post to the bottom - please post either at the bottom or inline so we can follow the conversation more easily. On Jul 15, 2011, at 6:06 AM, Chandu80 wrote:> On Jul 14, 5:30 pm, David Chelimsky <dchelim... at gmail.com> wrote: >> On Jul 14, 2011, at 6:34 AM, Chandrika Shenoy wrote: >> >>> Hello All, >> >>> I am a rspec beginner and I am trying to find a way out to write render >>> expectation in controller spec.All methods that I used seem to give me a >>> No Method error. >> >>> My controller code is as follows >>> http://pastie.org/2211944 >> >>> and my controller test is as follows >>> http://pastie.org/2211951 >> >> I don''t understand what the example is supposed to specify. I see a createchannelpage action in the controller, which might render createchannel, but I don''t see a createchannel action. Then the spec is posting to createchannel. What is the intent here?> Hi David, > Sorry about not pasting the createchannel method earlier,here is the > revised controller method. > > http://pastie.org/2217223 > > I am trying to test the createchannelpage method which is in the > Channels Controller.The createchannelpage renders the createchannel > action when the checkChannel? returns a true value.But the spec is still invoking createchannel directly. I think you want it to invoke createchannelpage, which should then render the createchannel template, right? If so, the spec should read: post :createchannelpage response.should render_template("createchannel") Does that work?