# Set only one observer to be active in a test

**URL:** <https://www.ruby-forum.com/t/set-only-one-observer-to-be-active-in-a-test/173432>\
**Category:** Rails\
**Created:** [August 8, 2009, 5:00pm UTC](https://www.ruby-forum.com/t/set-only-one-observer-to-be-active-in-a-test/173432 "2009-08-08T17:00:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![captaffy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f04885/32.png) [@captaffy](https://www.ruby-forum.com/u/captaffy)\
**Post date:** [August 8, 2009, 5:00pm UTC](https://www.ruby-forum.com/t/set-only-one-observer-to-be-active-in-a-test/173432/1 "2009-08-08T17:00:22Z")

</div>

In my environment.rb I set a whole bunch of observers to be active by  
default. In testing I don’t want to do that, I want to turn observers on  
and off as required so that I can isolate the things I’m testing.

How do I do it?

Ta

John S.

---

<div class="post-metadata">

**Author:** ![captaffy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f04885/32.png) [@captaffy](https://www.ruby-forum.com/u/captaffy)\
**Post date:** [August 8, 2009, 6:05pm UTC](https://www.ruby-forum.com/t/set-only-one-observer-to-be-active-in-a-test/173432/2 "2009-08-08T18:05:35Z")

</div>

Hi John,

On Sat, 2009-08-08 at 17:00 +0200, John S. wrote:

> In my environment.rb I set a whole bunch of observers to be active by  
> default. In testing I don’t want to do that, I want to turn observers on  
> and off as required so that I can isolate the things I’m testing.
> 
> How do I do it?

The settings in environment.rb are over-ridden by the settings in the  
environment-specific configs. Surest way to make this happen is to not  
put them in environment.rb but rather to specify the ones you want to  
run in each mode in the appropriate file in config/environments

HTH,  
Bill

---

<div class="post-metadata">

**Author:** ![captaffy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f04885/32.png) [@captaffy](https://www.ruby-forum.com/u/captaffy)\
**Post date:** [August 8, 2009, 6:14pm UTC](https://www.ruby-forum.com/t/set-only-one-observer-to-be-active-in-a-test/173432/3 "2009-08-08T18:14:16Z")

</div>

bill walton wrote:

> Hi John,
> 
> On Sat, 2009-08-08 at 17:00 +0200, John S. wrote:
> 
> > In my environment.rb I set a whole bunch of observers to be active by  
> > default. In testing I don’t want to do that, I want to turn observers on  
> > and off as required so that I can isolate the things I’m testing.
> > 
> > How do I do it?
> 
> The settings in environment.rb are over-ridden by the settings in the  
> environment-specific configs. Surest way to make this happen is to not  
> put them in environment.rb but rather to specify the ones you want to  
> run in each mode in the appropriate file in config/environments
> 
> HTH,  
> Bill  
> well yes, but what I really need is test specific settings for my  
> observers. What I don’t want is to be testing the observers for a model,  
> when I should be testing the model on its own and testing the observers  
> separately. If I start the observers running in the appropriate file in  
> config/environments then they’ll be running for all my tests. How do I  
> stop and start them inside my tests?

Ta

John S.
