[mocha-developer] Stubbing a module method

Duncan Beevers duncanbeevers at gmail.com
Thu Sep 27 19:10:11 EDT 2007


SiteController.any_instance.stubs(:login_required).returns(true)

perhaps?

On 9/27/07, Christophe <anaema_ml at yahoo.fr> wrote:
> Hi, I'm trying to stub the login_required() method of the
> acts_as_authenticated plugin in an RoR integration test.
> This method is defined in the AuthenticatedSystem module, in the
> lib/authenticated_system.rb
>
> What happen is that the stub have no effect and the real method is still
> executed.
>
> Here is the code. Any idea ?
>
> Thank you
>
>
>
> require "#{File.dirname(__FILE__)}/../test_helper"
>
> class CheckStopsiteTest < ActionController::IntegrationTest
>   fixtures :users
>
>   def test_closed_site
>     AuthenticatedSystem.stubs(:login_required).returns(true)
>     get '/admin/maintenance/stop_site'
>     assert_response :success
>     get '/fr/site'
>     assert_redirected_to :controller => 'site', :action => 'closed_site'
>   end
>
> end
> _______________________________________________
> mocha-developer mailing list
> mocha-developer at rubyforge.org
> http://rubyforge.org/mailman/listinfo/mocha-developer
>


More information about the mocha-developer mailing list