Created
June 28, 2011 20:46
-
-
Save ogredude/1052166 to your computer and use it in GitHub Desktop.
TDD class
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 'spec_helper' | |
describe Address do | |
[:street, :city, :zip].each do |attr| | |
it "must have a #{attr}" do | |
address = Factory.build(:address, attr.to_sym => nil) | |
address.should_not be_valid | |
address.errors[attr].should_not be_empty | |
end | |
end | |
it "should store only a 2-character State" do | |
address = Factory.build(:address, :state => "xyz") | |
address.should_not be_valid | |
address.errors[:state].should_not be_empty | |
end | |
describe "When country is missing" do | |
it "defaults to USA" do | |
address = Factory.build(:address, :country => nil) | |
address.save | |
address.country.should == "USA" | |
end | |
end | |
describe "When country is present" do | |
it "should save the chosen country" do | |
address = Factory.build(:address, :country => "England") | |
address.save | |
address.country.should == "England" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment