#493 new
Laust Rud

template.expect_render in controller/view specifications are not automatically verified

Reported by Laust Rud | August 11th, 2008 @ 05:58 PM | in No-Milestone-Assigned

Invoking "template.expect_render" automatically registers a listener on :after, but does it on the class Spec::Example::ExampleGroup - and unfortunately our viewspecs are of the type Spec::Rails::Example::ViewExampleGroup, which does not inherit from Spec::Example::ExampleGroup.

This means the :after listener never fires, because Spec::Example::ExampleGroup is not running, and the expectation goes unverified.

The following patch works around the problem by registering a listener on the correct type.


klass = Spec::Rails::Example::RenderObserver
klass.module_eval do
  def unregister_verify_after_each
    proc = verify_rendered_proc
    Spec::Example::ExampleGroup.remove_after(:each, &proc)
    Spec::Rails::Example::ViewExampleGroup.remove_after(:each, &proc)
    Spec::Rails::Example::ControllerExampleGroup.remove_after(:each, &proc)
  end

  def register_verify_after_each #:nodoc:
    proc = verify_rendered_proc
    Spec::Example::ExampleGroup.after(:each, &proc)
    Spec::Rails::Example::ViewExampleGroup.after(:each, &proc)
    Spec::Rails::Example::ControllerExampleGroup.after(:each, &proc)
  end
end

Comments and changes to this ticket

Please Login or create a free account to add a new comment.

You can update this ticket by sending an email to from your email client. (help)

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Behaviour Driven Development for Ruby.

Shared Ticket Bins

People watching this ticket