I want to spec that a controller uses a particular layout how do I do that? cheers, Matt ---- http://blog.mattwynne.net http://songkick.com In case you wondered: The opinions expressed in this email are my own and do not necessarily reflect the views of any former, current or future employers of mine. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20080904/6a3c6f9e/attachment.html>
On Thu, Sep 4, 2008 at 8:42 AM, Matt Wynne <matt at mattwynne.net> wrote:> I want to spec that a controller uses a particular layout > how do I do that?Depends on what else is going on, but this is the simplest situation: controller.expect_render(:layout => ''special_layout'') get :some_action
Thanks David. I really struggled to get that to catch anything. My colleague Dan found this, which is working well for me: http://rubyforge.org/pipermail/rspec-users/2007-May/001816.html On 4 Sep 2008, at 15:05, David Chelimsky wrote:> On Thu, Sep 4, 2008 at 8:42 AM, Matt Wynne <matt at mattwynne.net> wrote: >> I want to spec that a controller uses a particular layout >> how do I do that? > > Depends on what else is going on, but this is the simplest situation: > > controller.expect_render(:layout => ''special_layout'') > get :some_action > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
noting my own typo def negeative_failure_message should be def negative_failure_message :) On Sep 4, 2008, at 10:24 AM, Matt Wynne wrote:> Thanks David. > > I really struggled to get that to catch anything. My colleague Dan > found this, which is working well for me: > http://rubyforge.org/pipermail/rspec-users/2007-May/001816.html > > On 4 Sep 2008, at 15:05, David Chelimsky wrote: > >> On Thu, Sep 4, 2008 at 8:42 AM, Matt Wynne <matt at mattwynne.net> >> wrote: >>> I want to spec that a controller uses a particular layout >>> how do I do that? >> >> Depends on what else is going on, but this is the simplest situation: >> >> controller.expect_render(:layout => ''special_layout'') >> get :some_action >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
On 4 Sep 2008, at 16:12, Jonathan Linowes wrote:> noting my own typo > def negeative_failure_message > should be > def negative_failure_message > :)Copy & Paste Considered Harmfull ;) Thanks
David Chelimsky wrote:> On Thu, Sep 4, 2008 at 8:42 AM, Matt Wynne <matt at mattwynne.net> wrote: >> I want to spec that a controller uses a particular layout >> how do I do that? > > Depends on what else is going on, but this is the simplest situation: > > controller.expect_render(:layout => ''special_layout'') > get :some_actionDavid: Why is it that get :some_action controller.expect_render(:layout => ''special_layout'') ie having the get statement before the controller.expect.. statement produces the ff error: Mock ''expect_render_mock_proxy'' expected :render with ({:layout=>"special_layout"}) once, but received it 0 times Thanks -- Posted via http://www.ruby-forum.com/.
On Oct 16, 2008, at 7:59 AM, Dave Phiri wrote:> David Chelimsky wrote: >> On Thu, Sep 4, 2008 at 8:42 AM, Matt Wynne <matt at mattwynne.net> >> wrote: >>> I want to spec that a controller uses a particular layout >>> how do I do that? >> >> Depends on what else is going on, but this is the simplest situation: >> >> controller.expect_render(:layout => ''special_layout'') >> get :some_action > > David: > Why is it that > > get :some_action > controller.expect_render(:layout => ''special_layout'') > > ie having the get statement before the controller.expect.. statement > produces the ff error: > Mock ''expect_render_mock_proxy'' expected :render with > ({:layout=>"special_layout"}) once, but received it 0 timesBecause you are creating an expectation for the following action. In your code above, you are doing the action, and then creating an expectation for a following action which never occurs, so it receives it 0 times following that expectation. -Jim
Jim Gay wrote:> On Oct 16, 2008, at 7:59 AM, Dave Phiri wrote: > >> >> David: >> Why is it that >> >> get :some_action >> controller.expect_render(:layout => ''special_layout'') >> >> ie having the get statement before the controller.expect.. statement >> produces the ff error: >> Mock ''expect_render_mock_proxy'' expected :render with >> ({:layout=>"special_layout"}) once, but received it 0 times > > Because you are creating an expectation for the following action. > In your code above, you are doing the action, and then creating an > expectation for a following action which never occurs, so it receives > it 0 times following that expectation. > > -JimThanks Jim, It all now makes sense to me. I am barely a wk old in rspec. A lot many thanks! Dave -- Posted via http://www.ruby-forum.com/.
On Thu, Oct 16, 2008 at 9:49 AM, Jim Gay <jim at saturnflyer.com> wrote:> > Because you are creating an expectation for the following action. > In your code above, you are doing the action, and then creating an > expectation for a following action which never occurs, so it receives it 0 > times following that expectation.This confused me too at first. To put it another way: (1) controller.expect_render(:layout => ''index'') [set expectation] (2) get :index [perform action] ...is equivalent to... (1) Call spouse to say "Honey, I''m coming home, see you shortly." (2) Go home and kiss spouse. Putting the "get" first and then setting the "expect" would be equivalent to: (1) Go home and kiss spouse. (2) Call spouse to say "Honey, I''m coming home, see you shortly." Your spouse''s natural reaction would be "Ummmm...." Which is basically what RSpec is telling you by that error message when you do the ''get'' then the ''expect.'' -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org
On 16 Oct 2008, at 16:02, Stephen Eley wrote:> This confused me too at first. To put it another way: > > (1) controller.expect_render(:layout => ''index'') [set expectation] > (2) get :index [perform action] > > ...is equivalent to... > > (1) Call spouse to say "Honey, I''m coming home, see you shortly." > (2) Go home and kiss spouse.I''ve written some helpers for this - nothing complex, just reverses the order that things happen in: when_getting :index do expect_some_stuff_to_happen end The helper itself looks like this: def when_getting action, parameters = {} yield if block_given? get action, parameters end Likewise there is when_posting_to, when_putting_to and when_deleting_from One day (soon) I''ll get round to packaging them up and submitting them as a patch. Rahoul Baruah Web design and development: http://www.3hv.co.uk/ Nottingham Forest: http://www.eighteensixtyfive.co.uk/ Serious Rails Hosting: http://www.brightbox.co.uk/ Lifecast: http://www.madeofstone.net/
On Thu, Oct 16, 2008 at 1:18 PM, Rahoul Baruah <baz at madeofstone.net> wrote:> > On 16 Oct 2008, at 16:02, Stephen Eley wrote: > >> This confused me too at first. To put it another way: >> >> (1) controller.expect_render(:layout => ''index'') [set expectation] >> (2) get :index [perform action] >> >> ...is equivalent to... >> >> (1) Call spouse to say "Honey, I''m coming home, see you shortly." >> (2) Go home and kiss spouse. > > I''ve written some helpers for this - nothing complex, just reverses the > order that things happen in: > > when_getting :index do > expect_some_stuff_to_happen > end > > The helper itself looks like this: > > def when_getting action, parameters = {} > yield if block_given? > get action, parameters > end > > Likewise there is when_posting_to, when_putting_to and when_deleting_from > > One day (soon) I''ll get round to packaging them up and submitting them as a > patch.Cool. Don''t forget the seldom used #head, though I don''t know what to call it: when_heading_to?> > > Rahoul Baruah > Web design and development: http://www.3hv.co.uk/ > Nottingham Forest: http://www.eighteensixtyfive.co.uk/ > Serious Rails Hosting: http://www.brightbox.co.uk/ > Lifecast: http://www.madeofstone.net/ > > > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
On 2008-10-17, at 17:16, David Chelimsky wrote:> Cool. Don''t forget the seldom used #head, though I don''t know what to > call it: when_heading_to?I looked through the docs at http://rspec.rubyforge.org/rspec/1.1.8/ for #head , but the closest thing I found was #header , which is undocumented. When you have a minute, would you mind telling us about #head please? Thanks! Nick
On Sat, Oct 18, 2008 at 2:44 AM, Nick Hoffman <nick at deadorange.com> wrote:> On 2008-10-17, at 17:16, David Chelimsky wrote: >> >> Cool. Don''t forget the seldom used #head, though I don''t know what to >> call it: when_heading_to? > > I looked through the docs at http://rspec.rubyforge.org/rspec/1.1.8/ for > #head , but the closest thing I found was #header , which is undocumented. > When you have a minute, would you mind telling us about #head please?It''s a rails method, not rspec. Check out ActionController::Base#head. Cheers, David> > Thanks! > Nick > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >