Sha256: 8f184127ca1d3904909ea46a749420f85f1b4038a8876850634f94a59e69d609
Contents?: true
Size: 922 Bytes
Versions: 1
Compression:
Stored size: 922 Bytes
Contents
require 'net/http' require 'uri' require 'json' require 'webmock-rspec-helper' require 'webmock/rspec' WebMock.disable_net_connect! class WebMock::RSpec::Helper::Rails def self.root Pathname.new File.expand_path('../..', __FILE__) end end describe '#webmock' do it 'mocks GET google using default response 200' do webmock :get, %r[google.com] => 'GET_google.json' response = GET('http://google.com') expect(response.status).to eq 200 expect(response.body['google']).to eq true end it 'mocks GET google with custom response code' do webmock :get, %r[google.com] => 'GET_google.999.json' response = GET('http://google.com') expect(response.status).to eq 999 expect(response.body['google']).to eq true end end def GET(url) response = Net::HTTP.get_response URI.parse('http://google.com') OpenStruct.new status: response.code.to_i, body: JSON.parse(response.body) end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
webmock-rspec-helper-0.0.1 | spec/webmock-rspec-helper_spec.rb |