Skip to content

Instantly share code, notes, and snippets.

@juliocesar
Forked from jamesmartin/invisibility_spec.rb
Created February 17, 2011 23:12
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 juliocesar/832952 to your computer and use it in GitHub Desktop.
Save juliocesar/832952 to your computer and use it in GitHub Desktop.
module Invisibility
def self.included base
base.send :attr_reader, :visible
end
def activate
@visible = false
end
def deactivate
@visible = true
end
def visible?
@visible
end
end
class Person; end
if $0 =~ /spec/
describe "invisibility" do
before do
Person.send :include, Invisibility
@bob = Person.new
end
subject { @bob }
context 'when given to a Person' do
it 'creates a #visible? method' do
@bob.should respond_to :visible?
end
end
context 'activating' do
specify { should respond_to :activate }
it '#activate should make the person invisible' do
subject.activate
subject.should_not be_visible
end
end
context 'deactivating' do
specify { should respond_to :deactivate }
it '#deactivate should make a person visible' do
subject.deactivate
subject.should be_visible
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment