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.
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
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
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) 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.’
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.
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.
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
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.