[rspec-users] rspec-rails 2 adding current account helper to all view specs

Rob Westgeest rob.westgeest at gmail.com
Thu Jan 27 16:45:10 EST 2011


in rspec-1 view specs i had the ability to say:


which made some helper methods like


that where used in views and controllers return something valuable.

Implementation was based on the fact that the controller in rspec-1
was ApplicationController. My ApplicationController contained a method
for setting the current_account.

In Rspec2 this is broken as the controller in ViewExampleGroup is now

Would anyone know of an elegant way to add functionality, like helper
methods, to this controller instance in all ViewExampleGroups only.

option 1, which i don't like because it depends on the fact that
ViewExampleGroup uses ActionView::TestCase::TestController:

   class ActionView::TestCase::TestController
       attr_accessor :current_account
       helper_method :current_account
   module RSpec::Rails::ViewExampleGroup
       def login_as account
           controller.current_account = account

I would like to use some hook to add these methods only to the
controller instance used in the view specs, regardless of what class
it is.

There must be an elegant way, is there?


More information about the rspec-users mailing list