Created
October 17, 2012 10:05
-
-
Save kern/3904791 to your computer and use it in GitHub Desktop.
How would you test Person in isolation?
This file contains hidden or 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 "virtus" | |
require "rspec/autorun" | |
class Address < Virtus::Attribute::Object | |
primitive String | |
def coerce(value) | |
# Simulate a slow call to an external service that normalizes the | |
# address's format. | |
sleep 1 | |
"123 Foobar Street, Berkeley, CA 94720" | |
end | |
end | |
class Person | |
include Virtus | |
attribute :name, String | |
attribute :address, Address | |
end | |
describe Person do | |
subject(:person) { described_class.new(:name => "Bob", :address => "Nowhereland") } | |
before do | |
# Somehow stub out the coercion method for the address here so that the | |
# test runs quickly in isolation. | |
end | |
it "has a name" do | |
expect(person.name).to eq("Bob") | |
end | |
it "has an address" do | |
expect(person.address).to eq("123 Foobar Street, Berkeley, CA 94720") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@CapnKernul you could try this:
Alternatively you could also do this: