Sha256: 96101a5304eda30da79ba0dc054ff5d46001e42be787c5cf17b8bab274258207

Contents?: true

Size: 1.48 KB

Versions: 16

Compression:

Stored size: 1.48 KB

Contents

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
  
      # By default, don't run any observers
      it "should not register a name change" do
        lambda { @person.update_attribute :name, "Don Juan Demarco" }.should_not change(NameChange, :count)
      end
  
      # Run only a portion of code with certain observers turned on
      it "should register a name change with the person observer turned on" do
        Person.with_observers(:person_observer) do
          lambda { @person.update_attribute :name, "Don Juan Demarco" }.should change(NameChange, :count).by(1)
        end
    
        lambda { @person.update_attribute :name, "Man Without a Name" }.should_not change(NameChange, :count)
      end
    end


Copyright (c) 2007 Pat Maddox, released under the MIT license

Version data entries

16 entries across 16 versions & 3 rubygems

Version Path
adva-0.3.2 test/no_peeping_toms/README
adva-0.3.1 test/no_peeping_toms/README
adva-0.3.0 test/no_peeping_toms/README
adva-0.2.4 test/no_peeping_toms/README
adva-0.2.3 test/no_peeping_toms/README
adva-0.2.2 test/no_peeping_toms/README
adva-0.2.1 test/no_peeping_toms/README
adva-0.2.0 test/no_peeping_toms/README
adva-0.1.4 test/no_peeping_toms/README
adva-0.1.3 test/no_peeping_toms/README
adva-0.1.2 test/no_peeping_toms/README
adva-0.1.1 test/no_peeping_toms/README
adva-0.1.0 test/no_peeping_toms/README
adva-0.0.1 test/no_peeping_toms/README
collectiveidea-no_peeping_toms-1.0.0 README
no_peeping_toms-1.0.0 README