[rspec-users] Driving Out A View - Layouts and Sessions?
Lee.Longmore at googlemail.com
Sat Jun 6 01:01:44 EDT 2009
As suggested I started to wrtite a separate spec for the layout:
require File.expand_path(File.dirname(__FILE__) + '/../../
describe "layouts/contexts.html.erb" do
it "should display a link to create a new zone" do
When I execute this, it complains of a missing method "sub_menu". This
method, along with others such as "main_menu", are called within the
layout. Unlike "main_menu" which is defined in my
"application_helper.rb" file, "sub_menu" is defined in the helper file
for the controller "contexts". How do I get the spec to "see" this
file and its contents when executed? I think It's seeing "main_menu".
On 5 June, 17:39, Stephen Eley <sfe... at gmail.com> wrote:
> On Fri, Jun 5, 2009 at 11:40 AM, Lee<Lee.Longm... at googlemail.com> wrote:
> > Firstly, my experiments suggest that the layout is only rendered if
> > the :layout attribute is included in the call to render. Is my
> > understanding correct?
> Yes, and it's the way things should be. I suggest writing a separate
> spec for the layout, and testing its behavior separate from the view.
> After all, you're *unit* testing here. And the layout is a separate
> > Secondly, the link_to code only executes if the session contains a
> > piece of data (member id). How do I set up the session data in my view
> > spec?
> With the session object, e.g. "session[:foo] = bar". See:http://rspec.info/rails/writing/views.html
> Whether the view (or layout) should be looking directly into the
> session and making decisions from what it sees, instead of trusting
> what it gets from the controller, is another question. "Is there a
> current user?" is _probably_ closer to your actual business rules than
> "Does the session contain a member id?"
> Have Fun,
> Steve Eley (sfe... at gmail.com)
> ESCAPE POD - The Science Fiction Podcast Magazine
> rspec-users mailing list
> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
More information about the rspec-users