1

I want to get json from some url in rake task. how I can achive that?

I used this code

require 'open-uri'
content = open(my_url).read
logger.info content

but it throw WebMock::NetConnectNotAllowedError it saying stub this request but how I can get responce from stub_request dont know

from controller it works fine

Guru
  • 1,303
  • 18
  • 32
  • follow this link : http://stackoverflow.com/questions/5980856/trying-to-get-selenium-working-in-rails-3-webmocknetconnectnotallowederror – Kanna Feb 25 '16 at 11:57

1 Answers1

2

You need to place the webmock gem in the test group:

# Gemfile
# ...
group :test do
  gem 'webmock'
end

Or allow webmock to connect to the net if you are invoking the rake task in a test:

WebMock.allow_net_connect!

https://github.com/bblimke/webmock

max
  • 96,212
  • 14
  • 104
  • 165
  • I need webmock in production/development. one service is giving json api and I want to fetch that json and save my objects to DB – Guru Feb 25 '16 at 11:56
  • I added require 'webmock' include WebMock::API but how to get response that I not figured out yet – Guru Feb 25 '16 at 11:57
  • but yes Added WebMock.allow_net_connect! and now I able to get response...thanks bro.. – Guru Feb 25 '16 at 12:04