RSpec - how to stop a controller method

I have a controller that has special authentication, since it is really an API available for a specific remote system.

In RSpec (2.7), I want to bypass this authentication, but I cannot get it to work. From what I read, I should do something like this:
controller.stub!(:restrict_soa_access).and_return(true) 

But if I do this, I just get:

 spec/controllers/soa/user_controller_spec.rb:42: undefined method `stub!' for #<RSpec::Core::Hooks::AfterHooks:0xb673a8dc> (NoMethodError) 

In response to the comments, I also tried using Soa::UserController.stub! which gives an identical error as well as @controller.stub! when I get the undefined method for nil: NilClass.

I do not collect any other things. Is there something I need to do to enable stubbing, or is my stub code just wrong?

+4
source share
1 answer

I had a similar problem, so solve it like this:

 require 'rspec/mocks' require 'rspec/mocks/spec_methods' require 'rspec/mocks/standalone' 

can you report if this works for you?

+3
source

Source: https://habr.com/ru/post/1380267/


All Articles