No more @controller.expects in Test::Unit?

Hi,

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

Fernando Perez wrote:

Hi,

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?

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?

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?

Up, it's important. Nobody uses functional tests here?

Should still work. What happens instead? What version were you
migrating from? That stuff is setup by ActionController::TestCase

Fred

Hi Fred,

Here is some code:

On Jul 29, 5:23 pm, Fernando Perez <li...@ruby-forum.

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

Do you explicitly require mocha somewhere? By the way you no longer
need to setup @controller/@request/@response -
actioncontroller::testcase does that for you

Fred

Fred

Do you explicitly require mocha somewhere?

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.

It seems that simply installing the mocha gem solved my problem.

> Do you explicitly require mocha somewhere?

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?

it always has, but rails may have been accidentally requiring it for
you

Fred

it always has, but rails may have been accidentally requiring it for
you

Fred

That makes sense. Thanks Fred.