Is there a way to specify which layout an action should use in a
controller?
Andy
Is there a way to specify which layout an action should use in a
controller?
Andy
On 16-apr-2008, at 13:57, Andy C. wrote:
Is there a way to specify which layout an action should use in a
controller?
Off the top of my head, not tested:
describe MyController do
it “should use the foo layout” do
MyController.should_receive(:layout).with(“foo”)
load(“app/controllers/my_controller”)
end
end
but I’m sure there’s a more BDD way to do it (TIMTOWTDI goes BDDWTDI ?).
greetz,
bartz
Bart Z. wrote:
On 16-apr-2008, at 13:57, Andy C. wrote:
Is there a way to specify which layout an action should use in a
controller?Off the top of my head, not tested:
describe MyController do
it “should use the foo layout” do
MyController.should_receive(:layout).with(“foo”)
load(“app/controllers/my_controller”)
end
endbut I’m sure there’s a more BDD way to do it (TIMTOWTDI goes BDDWTDI ?).
greetz,
bartz
Tried it. No dice it seems
So I then tried:
it “should use the admin layout” do
controller.should_receive(:layout).with(“admin”)
end
And I get…
Spec::Mocks::MockExpectationError in ‘Admin::ProductsController should
use the admin layout’
Mock ‘Admin::ProductsController’ expected :layout with (“admin”) once,
but received it 0 times
I’m not doing the load … command you suggested. What is the thinking
behind that? I’m finding that testing using RSpec demands you understand
a lot more of what is going on inside the framework!
Cheers
Andy
On 16-apr-2008, at 16:53, Andy C. wrote:
load("app/controllers/my_controller")
Tried it. No dice it seems
Spec::Mocks::MockExpectationError in ‘Admin::ProductsController should
use the admin layout’
Mock ‘Admin::ProductsController’ expected :layout with (“admin”) once,
but received it 0 timesI’m not doing the load … command you suggested. What is the thinking
behind that? I’m finding that testing using RSpec demands you
understand
a lot more of what is going on inside the framework!
That kind of makes sense, since should_receive’s should be defined
before something happens. So, slightly diverting here, but say a
Post should receive find(:all) when you go to index/, it would look
something like:
describe PostsController do
it “should find all posts” do
Post.should_receive(:find).with(:all)
get “index”
end
end
The “trick” I gave you above was based on this one: http://
www.nabble.com/Testing-that-a-model-helper-method-is-called-
td15856651.html
Perhaps you should try giving the full path to load, eg. load
(RAILS_ROOT + “/app/controllers/my_controller.rb”).
greetz,
bartz
Perhaps you should try giving the full path to load, eg. load
(RAILS_ROOT + “/app/controllers/my_controller.rb”).
That seemed to do it… was perhaps a typo originally. My bad.
Thanks.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs