Skip to content

Commit

Permalink
Switched to intentional enabling
Browse files Browse the repository at this point in the history
Plugin used to initialize always in test environment. This can cause
problems with cucumber runs. So, now call
NoPeepingToms.disable_observers
  • Loading branch information
Drew Olson committed Oct 1, 2009
1 parent ae6b66b commit 3be84a2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
4 changes: 4 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ no_peeping_toms

This plugin disables observers in your specs, so that model specs can run in complete isolation.

To disable observers, place the following code in your test.rb, or spec_helper.rb, or wherever:

NoPeepingToms.disable_observers

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
Expand Down
3 changes: 0 additions & 3 deletions init.rb
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
if "test" == RAILS_ENV
ActiveRecord::Observer.send :include, NoPeepingToms
end
4 changes: 4 additions & 0 deletions lib/no_peeping_toms.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
module NoPeepingToms
def self.disable_observers
ActiveRecord::Observer.send :include, NoPeepingToms
end

def self.included(base)
base.send :include, NoPeepingToms::InstanceMethods
base.extend NoPeepingToms::ClassMethods
Expand Down
9 changes: 9 additions & 0 deletions spec/no_peeping_toms_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
require File.dirname(__FILE__) + '/spec_helper'

describe "Configuring NoPeepingToms" do
describe "#disable_observers" do
it "mixes in NoPeepingToms module to ActiveRecord::Observer" do
ActiveRecord::Observer.should_receive(:send).with(:include, NoPeepingToms)
NoPeepingToms.disable_observers
end
end
end

module NoPeepingTomsSpec
class Person < ActiveRecord::Base; end

Expand Down

0 comments on commit 3be84a2

Please sign in to comment.