fakeweb icon indicating copy to clipboard operation
fakeweb copied to clipboard

"FakeWeb.allow_net_connect = true" doesn't work with PORO/ElasticSearch

Open BartlomiejSkwira opened this issue 11 years ago • 0 comments

In my Rails project I have a utility class (plain old ruby object) which does a request to GitHub api and saves Project model. Just a moment ago I have started using ElasticSearch and my Project model has some stuff indexed. Each time I save this model a request to ElasticSearch is made on port 9200. Majority of my tests started to fail (because of the extra requests) with a message:

 FakeWeb::NetConnectNotAllowedError:
       Real HTTP connections are disabled. Unregistered request: PUT http://localhost:9200/karma_tracker_test/project/236

Now when I do

FakeWeb.allow_net_connect = true
#or 
FakeWeb.allow_net_connect = %r[^https?://localhost:9200]

explicitly in a test, or in a before(:each) block in spec_helper the test still fails. But if I put the same line in my utility class just before save, the test passes

Whole code is online at https://github.com/amberbit/KarmaTracker/tree/feature/59079242_elastic_search - failing test spec/model/pivotal_tracker_projects_fetcher_spec.rb:16, failing class app/services/pivotal_tracker_projects_fetcher.rb line 18

Adding a test-related logic inside app logic feels really bad. Any way to make it more clean or is it a bug?

BartlomiejSkwira avatar Nov 01 '13 11:11 BartlomiejSkwira