In my functional tests it was convenient to use:
@controller.expects(:admin?).at_least_once.returns(true)
to simulate requests which come from an admin user. But it seems that in
Rails 2.3.8 it's gone away. What replaces it now?
Thanks
--
Posted via http://www.ruby-forum.com/.
Anyone? Currently my apps are running test less because I can't use
expects or whatever method to stub out some behavior.
Where could I find relevant information about that?
Up, it's important. Nobody uses functional tests here?
Here is some code:
------------------
require 'test_helper'
class Admin::OrdersControllerTest < ActionController::TestCase
def setup
@controller = Admin::OrdersController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
@controller.expects(:admin?).at_least_once.returns(true)
@order = Factory.order
end
def test_index
get :index
assert_response :success
end
end
And here is the error message:
------------------------------
1) Error:
test_index(Admin::OrdersControllerTest):
NoMethodError: undefined method `expects' for
#<Admin::OrdersController:0x229a32c @real_format=nil>
I don't use mocha. Did rails delegate the stubbing to mocha recently? So
that could be my missing piece of the puzzle. Where should I require it
in? test_helper.rb?
> By the way you no longer need to setup @controller/@request/@response -
> actioncontroller::testcase does that for you
Indeed, I'll update my tests accordingly, thanks for pointing that out.
That makes sense. Thanks Fred.