Skip to content

Instantly share code, notes, and snippets.

@chrismcg
Created May 7, 2011 18:17
Show Gist options
  • Save chrismcg/960707 to your computer and use it in GitHub Desktop.
Save chrismcg/960707 to your computer and use it in GitHub Desktop.
class Name
def initialize(first_name, last_name)
@first_name, @last_name = first_name, last_name
end
def to_s
"#{first_name} #{last_name}"
end
end
describe Name do
subject do
Name.new("Chris", "McGrath")
end
it "returns full name as string" do
subject.to_s.should eq("Chris McGrath")
end
end
class Contact < ActiveRecord::Base
composed_of :name, :mapping => [:first_name, :last_name]
end
describe Contact do
subject do
contact = Contact.new
contact.first_name = "Anthony"
contact.last_name = "Eden"
contact
end
it "has a name" do
subject.name.should be_a_kind_of(Name)
end
end
class Renewable
def initialize(domain)
@domain = domain
end
def auto?
@domain.registry_domain.auto_renew?
rescue e
logger.error e
false
end
# and the rest
end
# some code somewhere
renewable = Renewable.new(@domain)
if renewable.auto?
# ...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment