How can I drown out an HTTP request like this in the twitter api below in the global scope so that it is valid for all tests in the Test :: Unit set?
stub_request(:get, "https://api.twitter.com/1/users/show.json?screen_name=digiberber"). with(:headers => {'Accept'=>'application/json', 'User-Agent'=>'Twitter Ruby Gem 1.1.2'}). to_return(:status => 200, :body => "", :headers => {})
This WebMock stub works in the configuration block of the TestCase () subclass, for example
class MyTest < ActiveSupport::TestCase setup do stub_request(...)... end end
But it is not recognized if I put it in a global setting in TestCase itself:
require 'webmock/test_unit' class ActiveSupport::TestCase setup do stub_request(...) end end
Which gives me an error:
NoMethodError: undefined method `stub_request' for ActiveSupport::TestCase:Class
I also tried fixing the def method myself
def self.setup stub_request(...) end
but it doesnβt work either.
Something similar happens when I use FlexMock instead of WebMock. This seems to be a problem of scale, but I cannot figure out how to get around it. Ideas?
source share