12. Failures:
!
1) Car Service should retrieve all cars
Failure/Error: response = RestClient.get ‘api.example.com/cars'
SocketError:
getaddrinfo: nodename nor servname provided, or not known
# ./test_spec.rb:12:in `block (2 levels) in <top (required)>'
!
Finished in 0.02436 seconds (files took 0.81924 seconds to load)
1 example, 1 failure
!
Failed examples:
!
rspec ./test_spec.rb:11 # External Service should retrieve all cars
18. require 'webmock/rspec'
require 'rest_client'
!
# WebMock.allow_net_connect!
!
describe 'Car Service' do
before :all do
stub_request(:get, ‘api.example.com/cars')
.to_return(status: 200, headers: {}, body: 'This is a mock.')
end
!
it 'should retrieve all cars' do
response = RestClient.get ‘http://api.example.com/cars'
expect(response).to eq(‘This is a mock.')
end
end
21. describe Car do
...
describe '.all' do
it 'should retrieve all available cars', :vcr, cassette_name: ‘cars/all’ do
cars = Car.all
expect(cars).to be_an_instance_of Array
expect(cars).to have(2).items
end
end
!
...
end
37. describe MyServiceProviderClient, pact: true do
!
before do
# Configure your client to point to the stub service on localhost using the port you have specified
MyServiceProviderClient.base_uri 'localhost:1234'
end
!
subject { MyServiceProviderClient.new }
!
describe "get_something" do
!
before do
my_service_provider.given("something exists").
upon_receiving("a request for something").with(method: :get, path: '/something').
will_respond_with(
status: 200,
headers: {'Content-Type' => 'application/json'},
body: {name: 'A small something'} )
end
!
it "returns a Something" do
expect(subject.get_something).to eq(Something.new('A small something'))
end
!
end
!
end