How to expect no layout

Hey guys. I’ve told one of my controllers to not render a layout for a
certain action:
layout false, :only => :map_info_window

Now I’m trying to spec that, but this:
it ‘should not render a layout’ do
controller.expect_render :layout
do_get
end

fails with this:
Spec::Mocks::MockExpectationError in ‘PropertiesController handling
GET /properties/1/map_info_window should not render a layout’
Mock ‘expect_render_mock_proxy’ expected :render with (:layout) once,
but received it 0 times

I’m using RSpec v1.1.4 . I know it’s old, but I haven’t gotten around
to upgrading yet!
-Nick

Nick H. wrote:

Hey guys. I’ve told one of my controllers to not render a layout for a
certain action:
layout false, :only => :map_info_window

Now I’m trying to spec that, but this:
it ‘should not render a layout’ do
controller.expect_render :layout
do_get
end

fails with this:
Spec::Mocks::MockExpectationError in ‘PropertiesController handling
GET /properties/1/map_info_window should not render a layout’
Mock ‘expect_render_mock_proxy’ expected :render with (:layout) once,
but received it 0 times

I’m using RSpec v1.1.4 . I know it’s old, but I haven’t gotten around
to upgrading yet!
-Nick

Try:
controller.should_receive(:layout).with(false, {:only =>
:map_info_window})

On 2008-11-11, at 05:46, Fernando P. wrote:

end

Try:
controller.should_receive(:layout).with(false, {:only =>
:map_info_window})

Hi Fernando. Unfortunately, that didn’t work either. It seems that the
controller object in the “controller” variable doesn’t actually
receive the call to #layout :

Spec::Mocks::MockExpectationError in ‘PropertiesController handling
GET /properties/1/map_info_window should not render a layout’
Mock ‘PropertiesController’ expected :layout with (false,
{:only=>:map_info_window}) once, but received it 0 times

Thanks,
Nick

On Tue, Nov 11, 2008 at 4:46 AM, Fernando P. [email protected]
wrote:

Try:
controller.should_receive(:layout).with(false, {:only =>
:map_info_window})

Declarations like #layout happen when the class definition is
interpreted (when the class is loaded) so you can’t really intercept
them the same way you do with calls that happen as a result of an
action or an instance method call.

One trick for spec’ing class level declarations is to set the
expectation and reload the class file. I’ve seen this used
successfully with models:

ActiveRecord::Base.should_receive(:has_many).with(:cows)
load RAILS_ROOT + “/app/models/cowboy.rb”

Sadly, I’ve not seen that succeed with controllers. I’m not clear why
yet, but there is something in Rails’ internals that make it a
challenge.

One way I’ve handled this successfully is to integrate_views for this
one example (in its own group) and specify that html elements from the
layout are not present in the form. It’s a brittle example, but it’s
only one.

Any better approaches out there?