Specifying a controller's layout

I want to spec that a controller uses a particular layout

how do I do that?

cheers,
Matt

http://blog.mattwynne.net

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.

On Thu, Sep 4, 2008 at 8:42 AM, Matt W. [email protected] 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

noting my own typo
def negeative_failure_message
should be
def negative_failure_message
:slight_smile:

On 4 Sep 2008, at 16:12, Jonathan L. wrote:

noting my own typo
def negeative_failure_message
should be
def negative_failure_message
:slight_smile:

Copy & Paste Considered Harmfull :wink:

Thanks

David C. wrote:

On Thu, Sep 4, 2008 at 8:42 AM, Matt W. [email protected] 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 times

Thanks

Jim G. 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.

-Jim

Thanks Jim,
It all now makes sense to me. I am barely a wk old in rspec. A lot many
thanks!
Dave

On Thu, Oct 16, 2008 at 9:49 AM, Jim G. [email protected] 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 E. ([email protected])
ESCAPE POD - The Science Fiction Podcast Magazine
http://www.escapepod.org

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.

-Jim

On Thu, Oct 16, 2008 at 1:18 PM, Rahoul B. [email protected]
wrote:

(1) Call spouse to say “Honey, I’m coming home, see you shortly.”

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?

On 16 Oct 2008, at 16:02, Stephen E. 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 B.
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 Sat, Oct 18, 2008 at 2:44 AM, Nick H. [email protected]
wrote:

On 2008-10-17, at 17:16, David C. 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

On 2008-10-17, at 17:16, David C. 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