Module: Spec::Rails::Example::RenderObserver
- Included in:
- ActionView::Base, ControllerExampleGroup::ControllerInstanceMethods, ViewExampleGroupController
- Defined in:
- lib/spec/rails/example/render_observer.rb
Overview
Extends the #should_receive, #should_not_receive and #stub! methods in rspec’s mocking framework to handle #render calls to controller in controller examples and template and view examples
Instance Method Summary collapse
-
#register_verify_after_each ⇒ Object
:nodoc:.
-
#render_proxy ⇒ Object
:nodoc:.
- #should_not_receive(*args) ⇒ Object
- #should_receive(*args) ⇒ Object
- #stub(*args) ⇒ Object
-
#stub!(*args) ⇒ Object
FIXME - for some reason, neither alias nor alias_method are working as expected in the else branch, so this is a duplicate of stub() above.
-
#unregister_verify_after_each ⇒ Object
:nodoc:.
-
#verify_rendered ⇒ Object
:nodoc:.
-
#verify_rendered_proc ⇒ Object
:nodoc:.
Instance Method Details
#register_verify_after_each ⇒ Object
:nodoc:
68 69 70 71 |
# File 'lib/spec/rails/example/render_observer.rb', line 68 def register_verify_after_each #:nodoc: proc = verify_rendered_proc Spec::Example::ExampleGroup.after(:each, &proc) end |
#render_proxy ⇒ Object
:nodoc:
73 74 75 |
# File 'lib/spec/rails/example/render_observer.rb', line 73 def render_proxy #:nodoc: @render_proxy ||= Spec::Mocks::Mock.new("render_proxy") end |
#should_not_receive(*args) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/spec/rails/example/render_observer.rb', line 29 def should_not_receive(*args) if args[0] == :render register_verify_after_each render_proxy.should_not_receive(:render) else super end end |
#should_receive(*args) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/spec/rails/example/render_observer.rb', line 20 def should_receive(*args) if args[0] == :render register_verify_after_each render_proxy.should_receive(:render, :expected_from => caller(1)[0]) else super end end |
#stub(*args) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/spec/rails/example/render_observer.rb', line 38 def stub(*args) if args[0] == :render register_verify_after_each render_proxy.stub(args.first, :expected_from => caller(1)[0]) else super end end |
#stub!(*args) ⇒ Object
FIXME - for some reason, neither alias nor alias_method are working as expected in the else branch, so this is a duplicate of stub() above. Could delegate, but then we’d run into craziness handling :expected_from. This will have to do for the moment.
51 52 53 54 55 56 57 58 |
# File 'lib/spec/rails/example/render_observer.rb', line 51 def stub!(*args) if args[0] == :render register_verify_after_each render_proxy.stub!(args.first, :expected_from => caller(1)[0]) else super end end |
#unregister_verify_after_each ⇒ Object
:nodoc:
15 16 17 18 |
# File 'lib/spec/rails/example/render_observer.rb', line 15 def unregister_verify_after_each #:nodoc: proc = verify_rendered_proc Spec::Example::ExampleGroup.remove_after(:each, &proc) end |
#verify_rendered ⇒ Object
:nodoc:
11 12 13 |
# File 'lib/spec/rails/example/render_observer.rb', line 11 def verify_rendered # :nodoc: render_proxy.rspec_verify end |
#verify_rendered_proc ⇒ Object
:nodoc:
60 61 62 63 64 65 66 |
# File 'lib/spec/rails/example/render_observer.rb', line 60 def verify_rendered_proc #:nodoc: template = self @verify_rendered_proc ||= Proc.new do template.verify_rendered template.unregister_verify_after_each end end |