O'Reilly logo

Rails 4 Test Prescriptions by Noel Rappin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adapter Tests

The adapter tests work between the adapter and the server, using VCR as a medium:

external/02/gatherer/spec/models/avatar_adapter_spec.rb
 
require ​'rails_helper'
 
 
describe AvatarAdapter ​do
 
it ​"accurately receives image url"​, :vcr ​do
 
user = double(twitter_handle: ​"noelrap"​)
 
adapter = AvatarAdapter.new(user)
 
url = ​"http://pbs.twimg.com/profile_images/40008602/head_shot_bigger.jpg"
 
expect(adapter.image_url).to eq(url)
 
end
 
end

This test has no dependency on the client, which we show by passing in a double rather than an actual User instance. Using a VCR cassette, we create a new adapter and assert that the adapter provides the expected URL when queried. The test also doesn’t have a particular dependency ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required