You are here: Browse Railsplugins No Peeping Toms
This plugin disables observers in your specs, so that model specs can run in complete isolation.
You can choose to run some code with observers turned on. This is useful when spec’ing an observer. For example, if you write the following observer:
class PersonObserver < ActiveRecord::Observer
def before_update(person)
old_person = Person.find person.id
if old_person.name != person.name
NameChange.create! :person => person, :old_name => old_person.name, :new_name => person.name
end
end
end
You can spec the Person class in complete isolation.
describe Person, " when changing a name" do
before(:each) do
@person = Person.create! :name => "Pat Maddox"
end
end
lambda { @person.update_attribute :name, “Man Without a Name” }.should_not change(NameChange, :count)
endCopyright© 2007 Pat Maddox, released under the MIT license
NOTE: This description has been extracted from the Plugin README and so the formatting may need updating to make browser friendly