RSpec.configure do |config|
config.before(:each, type: :controller) do |example|
unless example.metadata[:skip_login_mock]
allow_any_instance_of(ApiController).to receive(:restrict_access)
.and_return(true)
end
end
end
This skips the restrict_access
action defined in the ApiController
which serves to render an error unless a valid auth_token is provided along with the request.
So it is good to mock this for most specs, but allow the spec to override skipping (if for example we want to test that auth is happening correctly). So the stubbing can be overridden by defining the spec as follows:
it 'tests somethiing', skip_login_mock: true do
# ...
end