Pixel
2010-Jul-05 14:52 UTC
[rspec-users] 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 at rails3/gems/actionpack-3.0.0.beta4/lib/action_view/paths.rb:14:in `find'' # /home/pixel/.rvm/gems/ruby-1.9.2-head at 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 at 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 at 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 at 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 at 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 at 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 at 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 at 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 at 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 at 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 at 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 at 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 at 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 at 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 at 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 at 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 at 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 at 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 at 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 at 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 at 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 at 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 at 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 at 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 at 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 at 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 at 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 at 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 at 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 at 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 at 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 at 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20100705/a50bc0e4/attachment.html>
David Chelimsky
2010-Jul-05 16:16 UTC
[rspec-users] Problem specing application layout, missing partial?
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.txtShort 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20100705/cb94c025/attachment.html>
Pixel
2010-Jul-05 17:21 UTC
[rspec-users] Problem specing application layout, missing partial?
On Mon, Jul 5, 2010 at 11:16 AM, David Chelimsky <dchelimsky at gmail.com>wrote:> 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 >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 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20100705/30ee2a68/attachment.html>
David Chelimsky
2010-Jul-05 17:35 UTC
[rspec-users] Problem specing application layout, missing partial?
On Jul 5, 2010, at 12:21 PM, Pixel wrote:> On Mon, Jul 5, 2010 at 11:16 AM, David Chelimsky <dchelimsky at gmail.com> wrote: > 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 > > 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 :) Happy to help. Cheers, David -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20100705/9929b563/attachment.html>