Dave Gamphani Phiri
2008-Oct-16 06:50 UTC
[rspec-users] testing a render layout statement in a controller
I am new to rSpec and I am writing a test for a controller which has already been developed This is the example in my reports_controller_spec.rb: it "should render the layouts/menu template" do get :select_missing_persons response.should render_template("layouts/menu") end and this is the method in the reports_controller.rb def select_missing_identifiers render(:layout => "layouts/menu") end I am getting the following output when running autotest: ''ReportsController should render the layouts/menu template'' FAILED expected "layouts/menu", got "reports/select_missing_persons" ./spec/controllers/reports_controller_spec.rb:39: script/spec:4: Here, I was trying to test if the out put displays with a layouts/menu template. Can somebody help on how you test the render(:layout => "layouts/ menu") statement in a controller or this is supposed to be tested in the view? -------------- next part -------------- A non-text attachment was scrubbed... Name: davegamphaniphiri.vcf Type: text/x-vcard Size: 165 bytes Desc: not available URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20081016/751fbb53/attachment.vcf>
wei wei
2008-Oct-16 06:56 UTC
[rspec-users] testing a render layout statement in a controller
Try to write a customized matcher, here is an example # custom matchers #--------------------- class UseLayout def initialize(expected) @expected = ''layouts/'' + expected + ''_layout'' end def matches?(controller) @actual = controller.layout #@actual.equal?(@expected) @actual == @expected end def failure_message return "use_layout expected #{@expected.inspect}, got #{@actual.inspect}", @expected, @actual end def negative_failure_message return "use_layout expected #{@expected.inspect} not to equal #{@actual.inspect}", @expected, @actual end end def use_layout(expected) UseLayout.new(expected) end On Thu, Oct 16, 2008 at 2:50 PM, Dave Gamphani Phiri < davegamphaniphiri at gmail.com> wrote:> I am new to rSpec and I am writing a test for a controller which has > already been developed > > This is the example in my reports_controller_spec.rb: > > it "should render the layouts/menu template" do > get :select_missing_persons > response.should render_template("layouts/menu") > end > > and this is the method in the reports_controller.rb > > def select_missing_identifiers > render(:layout => "layouts/menu") > end > > I am getting the following output when running autotest: > > ''ReportsController should render the layouts/menu template'' FAILED > expected "layouts/menu", got "reports/select_missing_persons" > ./spec/controllers/reports_controller_spec.rb:39: > script/spec:4: > > Here, I was trying to test if the out put displays with a layouts/menu > template. > Can somebody help on how you test the render(:layout => "layouts/ > menu") statement in a controller or this is supposed to be tested in > the view? > > > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-- Wei Wei -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20081016/b0c72f23/attachment-0001.html>
Bart Zonneveld
2008-Oct-20 11:35 UTC
[rspec-users] testing a render layout statement in a controller
On 16-okt-2008, at 8:50, Dave Gamphani Phiri wrote:> Here, I was trying to test if the out put displays with a layouts/menu > template. > Can somebody help on how you test the render(:layout => "layouts/ > menu") statement in a controller or this is supposed to be tested in > the view?Try this: render(:layout => "layouts/menu") and return cheers, bartz
Harry Bishop
2008-Oct-31 17:26 UTC
[rspec-users] testing a render layout statement in a controller
Bart Zonneveld wrote:> On 16-okt-2008, at 8:50, Dave Gamphani Phiri wrote: > >> Here, I was trying to test if the out put displays with a layouts/menu >> template. >> Can somebody help on how you test the render(:layout => "layouts/ >> menu") statement in a controller or this is supposed to be tested in >> the view? > > Try this: > > render(:layout => "layouts/menu") and return > > cheers, > bartzThanks Bartz, I used your input to try a controller line of format.html { render :action => "show" } and rspec of response.should render_template( :(controller name) => "/show") I tried it with and without the "and return" and both worked. Harry -- Posted via http://www.ruby-forum.com/.