Skip to content

Instantly share code, notes, and snippets.

@senny
Created January 8, 2012 18:54
Show Gist options
  • Save senny/1579301 to your computer and use it in GitHub Desktop.
Save senny/1579301 to your computer and use it in GitHub Desktop.
example virtus integration spec
require 'integration/spec_helper'
class Article
include Virtus
attribute :title, String
def title
super || '<unknown>'
end
def title=(name)
super unless self.title == "can't be changed"
end
end
describe 'overriding an attribute getter' do
specify 'calls the defined getter' do
Article.new.title.should == '<unknown>'
end
specify 'super can be used to access the getter defined by virtus' do
Article.new(:title => 'example article').author.should == 'example article'
end
end
describe 'overriding an attribute setter' do
specify 'calls the defined setter' do
article = Article.new(:title => "can't be changed")
subject.title = 'this will never be assigned'
subject.title.should == "can't be changed"
end
specify 'super can be used to access the setter defined by virtus' do
article = Article.new(:title => 'example article')
article.title = 'my new title'
article.title.should == 'my new title'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment