Stub Request not working

I am trying elasticsearch with the tire gem. But when adding the callbacks to my model it breaks rspec.

Here is a gist of my model(concern) and the error its producing.

I have put the stub_request in a file under spec/support called tire_webmock.rb

Whatever I do I can get past this error. Any advise on what I can do next?

I think it’s webmock which is not picking up the stub. But looking at webmock it looks like what I have done is correct.

I have fixed it by adding changing the spec_helper.rb,

Basically I moved the require ‘webmock/rspec’ to the top then using the stub before anything else.

All sorted.

Wrong, I still got issues running rspec.

Any ideas would be welcome.

Are you saying that its now failing intermittently or is still fails all the time?

Will I got it working when running rspec. But then when using Guard with Spork it still continued to be a problem. But I have just added the moc to the Spork.each_run area and looks to be resolved.

I may move to zeus instead of Spork.

So for now it looks like im working again.

Thanks to a lengthy chat with Joe the problem has been resolved. the following steps were done.

1, Remove Spork
2, Update Spec Helper

ENV["RAILS_ENV"] ||= 'test'
# change to
ENV['RAILS_ENV'] = 'test'

# moved require statement to top and add webmock
require 'webmock/rspec'
WebMock.disable_net_connect!(:allow_localhost => true)

# removed line
require 'rspec/autorun'

3, Added my vcr_helper.rb to autoload path. /spec/support

Seems so little in the ned but we went through many steps to get there.

Thank You Joe!!


Thanks for following up and posting the solution! Nice forum etiquette :slight_smile: