Is anyone else using liquid with the > 1 rspec? This seems to fail: it ''should render show'' do response.should render_template(''buyers/show'') get :show, :id => 1 end with an error like 1) NoMethodError in ''/buyer GET should render show'' You have a nil object when you didn''t expect it! The error occurred while evaluating nil.first_render /rails/store/trunk/vendor/plugins/rspec_on_rails/lib/spec/rails/matchers/render_template.rb:12:in `matches?'' spec/controllers/buyer_controller_spec.rb:57: spec/controllers/buyer_controller_spec.rb:63: should render_template is looking for 11: def matches?(response) 12: @actual = response.rendered_file(!expected.include?(''/'')) 13: actual == expected 14: end TestResponse.rendered_file looks like 208: def rendered_file(with_controller=false) 209: unless template.first_render.nil? 210: unless with_controller 211: template.first_render so TestResponse is missing ''template''. Any clues? Courtenay http://blog.caboo.se http://entp.com
rspec thinks that response.should render_template comes AFTER the get :show Thanks to Dylan (abcde) for this gotcha. Also solves my should_redirect problems :) On 6/12/07, Courtenay <court3nay at gmail.com> wrote:> Is anyone else using liquid with the > 1 rspec? This seems to fail: > > > it ''should render show'' do > response.should render_template(''buyers/show'') > get :show, :id => 1 > end > > > with an error like > > 1) > NoMethodError in ''/buyer GET should render show'' > You have a nil object when you didn''t expect it! > The error occurred while evaluating nil.first_render > /rails/store/trunk/vendor/plugins/rspec_on_rails/lib/spec/rails/matchers/render_template.rb:12:in > `matches?'' > spec/controllers/buyer_controller_spec.rb:57: > spec/controllers/buyer_controller_spec.rb:63: > > > should render_template is looking for > > 11: def matches?(response) > 12: @actual = response.rendered_file(!expected.include?(''/'')) > 13: actual == expected > 14: end > > > TestResponse.rendered_file looks like > > 208: def rendered_file(with_controller=false) > 209: unless template.first_render.nil? > 210: unless with_controller > 211: template.first_render > > > so TestResponse is missing ''template''. Any clues? > > > > Courtenay > > http://blog.caboo.se > http://entp.com >
On 6/12/07, Courtenay <court3nay at gmail.com> wrote:> rspec thinks that response.should render_template comes AFTER the get :showYeah - there was a time when RSpec supported should_render before or after the action. This was an attempt to make things more ''mockish'', which was cool, but the code was bloody invasive (lots of rails monkey patching) and kept breaking every time there was a new changeset committed to Rails Edge. So we (I) gave it up and now these only work after the action. Perhaps we should alias it with have_rendered: response.should have_rendered(''some/template'') WDYT? David> > Thanks to Dylan (abcde) for this gotcha. > Also solves my should_redirect problems :) > > On 6/12/07, Courtenay <court3nay at gmail.com> wrote: > > Is anyone else using liquid with the > 1 rspec? This seems to fail: > > > > > > it ''should render show'' do > > response.should render_template(''buyers/show'') > > get :show, :id => 1 > > end > > > > > > with an error like > > > > 1) > > NoMethodError in ''/buyer GET should render show'' > > You have a nil object when you didn''t expect it! > > The error occurred while evaluating nil.first_render > > /rails/store/trunk/vendor/plugins/rspec_on_rails/lib/spec/rails/matchers/render_template.rb:12:in > > `matches?'' > > spec/controllers/buyer_controller_spec.rb:57: > > spec/controllers/buyer_controller_spec.rb:63: > > > > > > should render_template is looking for > > > > 11: def matches?(response) > > 12: @actual = response.rendered_file(!expected.include?(''/'')) > > 13: actual == expected > > 14: end > > > > > > TestResponse.rendered_file looks like > > > > 208: def rendered_file(with_controller=false) > > 209: unless template.first_render.nil? > > 210: unless with_controller > > 211: template.first_render > > > > > > so TestResponse is missing ''template''. Any clues? > > > > > > > > Courtenay > > > > http://blog.caboo.se > > http://entp.com > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
El 12/6/2007, a las 13:51, David Chelimsky escribi?:> Yeah - there was a time when RSpec supported should_render before or > after the action. This was an attempt to make things more ''mockish'', > which was cool, but the code was bloody invasive (lots of rails > monkey patching) and kept breaking every time there was a new > changeset committed to Rails Edge. So we (I) gave it up and now these > only work after the action. > > Perhaps we should alias it with have_rendered: > > response.should have_rendered(''some/template'') > > WDYT?I think that''s an excellent idea. Much less scope for confusion. Cheers, Wincent