Skip to content

Instantly share code, notes, and snippets.

@ogredude
Created June 28, 2011 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ogredude/1052166 to your computer and use it in GitHub Desktop.
Save ogredude/1052166 to your computer and use it in GitHub Desktop.
TDD class
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