Problem specing application layout, missing partial?

In an effort to teach myself BDD I’m trying it out. I’m trying to do a
simple (should be straightforward) spec on my application.html.haml file
first looking for a div tag with the class ‘nav’ it seems that rspec
isn’t
able to render the app/views/layouts/application.html.haml file.
Gist with command/error/backtrace:
http://gist.github.com/463978#file_gistfile1.txt

$ rspec spec/views/layouts/application.html.haml_spec.rb -b
F

  1. layouts/application.haml.html displays a navigation area
    Failure/Error: render “layouts/application.html.haml”
    Missing partial layouts/application.html with {:handlers=>[:erb,
    :rjs, :builder, :rhtml, :rxml, :haml], :formats=>[:html, :text, :js,
    :css, :ics, :csv, :xml, :rss, :atom, :yaml, :multipart_form,
    :url_encoded_form, :json], :locale=>[:en, :en]} in view paths
    “/home/pixel/Development/code/achieveit.git/app/views”,
    “/home/pixel/Development/code/achieveit.git/vendor/plugins/haml/app/views”

/home/pixel/.rvm/gems/ruby-1.9.2-head@rails3/gems/actionpack-3.0.0.beta4/lib/action_view/paths.rb:14:in
find' # /home/pixel/.rvm/gems/ruby-1.9.2-head@rails3/gems/actionpack-3.0.0.beta4/lib/action_view/lookup_context.rb:79:in find’
#
/home/pixel/.rvm/gems/ruby-1.9.2-head@rails3/gems/actionpack-3.0.0.beta4/lib/action_view/base.rb:186:in
find_template' # /home/pixel/.rvm/gems/ruby-1.9.2-head@rails3/gems/actionpack-3.0.0.beta4/lib/action_view/render/partials.rb:310:in find_template’
#
/home/pixel/.rvm/gems/ruby-1.9.2-head@rails3/gems/actionpack-3.0.0.beta4/lib/action_view/render/partials.rb:211:in
render' # /home/pixel/.rvm/gems/ruby-1.9.2-head@rails3/gems/actionpack-3.0.0.beta4/lib/action_view/render/partials.rb:332:in _render_partial’
#
/home/pixel/.rvm/gems/ruby-1.9.2-head@rails3/gems/actionpack-3.0.0.beta4/lib/action_view/render/rendering.rb:30:in
render' # /home/pixel/.rvm/gems/ruby-1.9.2-head@rails3/gems/haml-3.0.13/lib/haml/helpers/action_view_mods.rb:13:in render_with_haml’
#
/home/pixel/.rvm/gems/ruby-1.9.2-head@rails3/gems/actionpack-3.0.0.beta4/lib/action_view/test_case.rb:100:in
render' # /home/pixel/.rvm/gems/ruby-1.9.2-head@rails3/gems/rspec-rails-2.0.0.beta.15/lib/rspec/rails/example/view_example_group.rb:58:in render’
# ./spec/views/layouts/application.html.haml_spec.rb:5:in block (2 levels) in <top (required)>' # /home/pixel/.rvm/gems/ruby-1.9.2-head@rails3/gems/rspec-core-2.0.0.beta.15/lib/rspec/core/example.rb:76:in instance_eval’
#
/home/pixel/.rvm/gems/ruby-1.9.2-head@rails3/gems/rspec-core-2.0.0.beta.15/lib/rspec/core/example.rb:76:in
block in with_pending_capture' # /home/pixel/.rvm/gems/ruby-1.9.2-head@rails3/gems/rspec-core-2.0.0.beta.15/lib/rspec/core/example.rb:75:in catch’
#
/home/pixel/.rvm/gems/ruby-1.9.2-head@rails3/gems/rspec-core-2.0.0.beta.15/lib/rspec/core/example.rb:75:in
with_pending_capture' # /home/pixel/.rvm/gems/ruby-1.9.2-head@rails3/gems/rspec-core-2.0.0.beta.15/lib/rspec/core/example.rb:50:in block in run’
#
/home/pixel/.rvm/gems/ruby-1.9.2-head@rails3/gems/rspec-core-2.0.0.beta.15/lib/rspec/core/example.rb:46:in
call' # /home/pixel/.rvm/gems/ruby-1.9.2-head@rails3/gems/rspec-core-2.0.0.beta.15/lib/rspec/core/example.rb:46:in run’
#
/home/pixel/.rvm/gems/ruby-1.9.2-head@rails3/gems/rspec-core-2.0.0.beta.15/lib/rspec/core/example_group.rb:186:in
block in run_examples' # /home/pixel/.rvm/gems/ruby-1.9.2-head@rails3/gems/rspec-core-2.0.0.beta.15/lib/rspec/core/example_group.rb:183:in map’
#
/home/pixel/.rvm/gems/ruby-1.9.2-head@rails3/gems/rspec-core-2.0.0.beta.15/lib/rspec/core/example_group.rb:183:in
run_examples' # /home/pixel/.rvm/gems/ruby-1.9.2-head@rails3/gems/rspec-core-2.0.0.beta.15/lib/rspec/core/example_group.rb:174:in run’
#
/home/pixel/.rvm/gems/ruby-1.9.2-head@rails3/gems/rspec-core-2.0.0.beta.15/lib/rspec/core/command_line.rb:41:in
block in run_examples' # /home/pixel/.rvm/gems/ruby-1.9.2-head@rails3/gems/rspec-core-2.0.0.beta.15/lib/rspec/core/command_line.rb:41:in each’
#
/home/pixel/.rvm/gems/ruby-1.9.2-head@rails3/gems/rspec-core-2.0.0.beta.15/lib/rspec/core/command_line.rb:41:in
inject' # /home/pixel/.rvm/gems/ruby-1.9.2-head@rails3/gems/rspec-core-2.0.0.beta.15/lib/rspec/core/command_line.rb:41:in run_examples’
#
/home/pixel/.rvm/gems/ruby-1.9.2-head@rails3/gems/rspec-core-2.0.0.beta.15/lib/rspec/core/command_line.rb:24:in
block in run' # /home/pixel/.rvm/gems/ruby-1.9.2-head@rails3/gems/rspec-core-2.0.0.beta.15/lib/rspec/core/formatters/base_formatter.rb:37:in block in report’
#
/home/pixel/.rvm/gems/ruby-1.9.2-head@rails3/gems/rspec-core-2.0.0.beta.15/lib/rspec/core/formatters/base_formatter.rb:152:in
sync_output' # /home/pixel/.rvm/gems/ruby-1.9.2-head@rails3/gems/rspec-core-2.0.0.beta.15/lib/rspec/core/formatters/base_formatter.rb:34:in report’
#
/home/pixel/.rvm/gems/ruby-1.9.2-head@rails3/gems/rspec-core-2.0.0.beta.15/lib/rspec/core/command_line.rb:21:in
run' # /home/pixel/.rvm/gems/ruby-1.9.2-head@rails3/gems/rspec-core-2.0.0.beta.15/lib/rspec/core/runner.rb:46:in run_in_process’
#
/home/pixel/.rvm/gems/ruby-1.9.2-head@rails3/gems/rspec-core-2.0.0.beta.15/lib/rspec/core/runner.rb:37:in
run' # /home/pixel/.rvm/gems/ruby-1.9.2-head@rails3/gems/rspec-core-2.0.0.beta.15/lib/rspec/core/runner.rb:22:in block in autorun’

Finished in 0.28094 seconds
1 example, 1 failure

Spec file:
http://gist.github.com/463978#file_application.html.haml_spec.rb
File under spec:
http://gist.github.com/463978#file_application.html.haml
Gem list: http://gist.github.com/463978#file_gistfile4.txt

The problem may be something simple but several hours of googling
haven’t
helped and I’m at a loss.

-Cole

On Jul 5, 2010, at 9:52 AM, Pixel wrote:

In an effort to teach myself BDD I’m trying it out. I’m trying to do a simple (should be straightforward) spec on my application.html.haml file first looking for a div tag with the class ‘nav’ it seems that rspec isn’t able to render the app/views/layouts/application.html.haml file.
Gist with command/error/backtrace: http://gist.github.com/463978#file_gistfile1.txt

Short version:

Don’t pass anything to render() in the spec. It’ll do the right thing as
long as you name the template in the string passed to describe:

require “spec_helper”

describe “layouts/application.html.haml” do
it “displays a navigation area” do
render
rendered.should have_selector(‘div#nav’)
end
end

Only slightly longer version:

There are some confusing things about the render() method in
ActionView::Base, which is ultimately what renders the the template.
View specs handle this for you by building the hash that Rails’ render()
is looking for when you don’t pass anything to render. In this case, the
example above results in the equivalent of:

require “spec_helper”

describe “layouts/application.html.haml” do
it “displays a navigation area” do
render :template => “layouts/application.html.haml”
rendered.should have_selector(‘div#nav’)
end
end

HTH,
David

On Mon, Jul 5, 2010 at 11:16 AM, David C.
[email protected]wrote:

Short version:
end
end

Of course it helps when I write out the file name correctly in the
describe
line, so that rspec can build the correct call. Woops! Thanks for your
help and patience David, much appreciated.

  • Cole

On Jul 5, 2010, at 12:21 PM, Pixel wrote:

require “spec_helper”

describe “layouts/application.html.haml” do
it “displays a navigation area” do
render
rendered.should have_selector(‘div#nav’)
end
end

Of course it helps when I write out the file name correctly in the describe line, so that rspec can build the correct call. Woops! Thanks for your help and patience David, much appreciated.

Yes, it turns out that computers are not great interpreters :slight_smile:

Happy to help.

Cheers,
David