You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I can't figure out how to stub sunspot results in RSpec.
I added require 'sunspot/rails/spec_helper' to my spec/rails_helper.rb file, and call disconnect_sunspot at the top of my test.
My understanding is that running allow_any_instance_of(Sunspot::Rails::StubSessionProxy::Search).to receive(:results).and_return(['the results']) should be all I need to do for a search query to return ['the results'], but no matter what I try, I always end up with an empty array ([]) as results.
require'rails_helper'RSpec.describe'My controller'dodisconnect_sunspotbeforedoallow_any_instance_of(Sunspot::Rails::StubSessionProxy::Search).toreceive(:results).and_return(['the results'])# Code that calls the controller hereendit'returns what I want'doexpect(response.body).toeq(['the results'])endend
I can't figure out how to stub sunspot results in RSpec.
I added
require 'sunspot/rails/spec_helper'
to myspec/rails_helper.rb
file, and calldisconnect_sunspot
at the top of my test.My understanding is that running
allow_any_instance_of(Sunspot::Rails::StubSessionProxy::Search).to receive(:results).and_return(['the results'])
should be all I need to do for a search query to return['the results']
, but no matter what I try, I always end up with an empty array ([]
) as results.Here is a simplified version of my controller:
And my test (simplified) looks like this:
And the RSpec results:
The text was updated successfully, but these errors were encountered: