Last active
August 29, 2015 13:57
-
-
Save namxam/9643560 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FakeService | |
def self.call(env) | |
[200, { 'Content-Type' => 'application/json' }, ['{ "name": "John Doe" }']] | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/http' | |
require 'json' | |
class MyExternalDependency | |
def get_user | |
data = Net::HTTP.get('example.com', '/user.json') | |
JSON.parse(data) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
require 'service' | |
describe MyExternalDependency do | |
describe '#get_user' do | |
it 'contains the user name' do | |
expect(MyExternalDependency.new.get_user['name']).to eq('John Doe') | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# spec_helper.rb | |
require 'webmock' | |
require 'rack' | |
require 'fake_service' | |
RSpec.configure do |config| | |
config.before(:each) { WebMock.stub_request(:any, %r[http://example.com]).to_rack(FakeService) } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment