views:

67

answers:

1

In my RSpec controller test, I'm trying to test a particular action that makes a call to a subfunction. But I don't want the test to include the call to that subfunction. (it'll raise an error that simply cannot be fixed in my dev environment)

What's the best way to omit this subfunction call from this controller action while I'm running a test over it?

Thanks.

+1  A: 

You can stub that subfunction call in the before block of your rspec test for that function like so

describe "test for the main_action"
  before(:each) do
    controller.stub!(:sub_action).returns(true)
  end
end

Then none of your test examples would actually call this sub_action.

Just for semantics, Rspec always runs in test environment not in development but I gather what you mean.

nas
shouldn't that be `controller.stub!`?
zetetic
yes you are right, we use mocha with rspec and I basically wrote the mocha stub syntax. Thanks for pointing that out, I corrected the answer as well.
nas