OK, I can''t figure this out. RSpec 1.1.8 RSpecRails 1.1.8 Rails 2.1.1 I have a model #app/models/person.rb class Person < ActiveRecord::Base # The model has a lot of code in it, but even deleting # all the contents down to an empty model like this # still produces the error end #app/observers/person_observer.rb class PersonObserver < ActiveRecord::Observer def before_save(person) Note.update_associated(person) end end #config/environment.rb ... config.activerecord.observers = [:person_observer, ...] The observer is not being called using #spec/observers/person_observer_spec.rb describe PersonObserver do it "should call the observer" person = Person.generate Note.should_receive(:update_associated) person.save end it "should not call the observer" person = Person.generate Note.should_receive(:update_associated) person.save end end This fails, and I can not figure out why. If I fire up the console and modify a person and save it, the observer fires and the Note class updates what it needs to. But the cracker is.... I have other observers that work fine.... I''m at wits end on this. Any ideas why the observer might not be called? -- http://lindsaar.net/ Rails, RSpec and Life blog.... -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20081126/89619515/attachment.html>
On Wed, Nov 26, 2008 at 4:08 AM, Mikel Lindsaar <raasdnil at gmail.com> wrote:> OK, I can''t figure this out. > RSpec 1.1.8 > RSpecRails 1.1.8 > Rails 2.1.1 > I have a model > #app/models/person.rb > class Person < ActiveRecord::Base > # The model has a lot of code in it, but even deleting > # all the contents down to an empty model like this > # still produces the error > end > #app/observers/person_observer.rb > class PersonObserver < ActiveRecord::Observer > def before_save(person) > Note.update_associated(person) > end > end > #config/environment.rb > ... > config.activerecord.observers = [:person_observer, ...] > The observer is not being called using > #spec/observers/person_observer_spec.rb > describe PersonObserver do > it "should call the observer" > person = Person.generate > Note.should_receive(:update_associated) > person.save > end > it "should not call the observer" > person = Person.generate > Note.should_receive(:update_associated) > person.save > end > end > This fails, and I can not figure out why.I see two examples with identical code. Do they both fail, or just the 2nd one? If so, there was a bug in which mocked inherited class methods were not properly restored after the example. This is fixed in git, but not released. Would you mind building the gem from the latest and see if it resolves your issue? Thanks, David> > If I fire up the console and modify a person and save it, the observer fires > and the Note class updates what it needs to. > But the cracker is.... I have other observers that work fine.... I''m at wits > end on this. > Any ideas why the observer might not be called?> > -- > http://lindsaar.net/ > Rails, RSpec and Life blog.... > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
> I see two examples with identical code. Do they both fail, or just the > 2nd one? If so, there was a bug in which mocked inherited class > methods were not properly restored after the example. This is fixed in > git, but not released. > > Would you mind building the gem from the latest and see if it resolvesSorry David, stupid typo. I am duplicating the text from another screen that is not on the ''net directly. The second spec does not exist. #spec/observers/person_observer_spec.rb describe PersonObserver do it "should call the observer" person = Person.generate Note.should_receive(:update_associated) person.save end end I''ll get the git version anyway and try it out. -- http://lindsaar.net/ Rails, RSpec and Life blog.... -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20081126/d31ae273/attachment.html>
On Wed, Nov 26, 2008 at 4:32 AM, Mikel Lindsaar <raasdnil at gmail.com> wrote:> >> I see two examples with identical code. Do they both fail, or just the >> 2nd one? If so, there was a bug in which mocked inherited class >> methods were not properly restored after the example. This is fixed in >> git, but not released. >> >> Would you mind building the gem from the latest and see if it resolves > > > Sorry David, stupid typo. I am duplicating the text from another screen > that is not on the ''net directly. The second spec does not exist. > #spec/observers/person_observer_spec.rb > describe PersonObserver do > it "should call the observer" > person = Person.generate > Note.should_receive(:update_associated) > person.save > end > end > > > I''ll get the git version anyway and try it out.Feel free, but now that I know there is only one example, I doubt that it will solve your problem. But who knows? Couldn''t hurt to try :)
On Wed, Nov 26, 2008 at 9:41 PM, David Chelimsky <dchelimsky at gmail.com>wrote:> On Wed, Nov 26, 2008 at 4:32 AM, Mikel Lindsaar <raasdnil at gmail.com> > wrote: > > Sorry David, stupid typo. I am duplicating the text from another screen > > that is not on the ''net directly. The second spec does not exist. >You are right... doesn''t make a lick of difference :) Although, the new gem builds and installs nicely :) Any other ideas? Or things you want me to try? It feels like the observer is not getting instantiated within the Person class with the spec. Calling the debugger and putting it inside the Observer class and then running the spec from the command line with ruby-debug enabled confirms this as the spec never drops into the debugger CLI. Am I missing a load path somewhere? Putting the debugger within the specification itself and then calling ActiveRecord::Base.observers returns [:person_observer, .... (other observers)] And the following: (rdb:1) ActiveRecord::Base.observers [:person_observer, .... (other observers)] (rdb:1) Person.observers [] (rdb:1) Person.add_observer(PersonObserver) [#<PersonObserver:0x2322234>, PersonObserver] (rdb:1) Person.observers [] So that lead me to try instantiating the observers in the spec with Person.instantiate_observers.... no joy. Feeling thoroughly clueless at this point. -- http://lindsaar.net/ Rails, RSpec and Life blog.... -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20081126/3f76dd42/attachment.html>
On Wed, Nov 26, 2008 at 10:10 PM, Mikel Lindsaar <raasdnil at gmail.com> wrote:> Am I missing a load path somewhere? >OK, I''ve ruled this out. I did: class PersonObserver < ActiveRecord::Observer raise .... end $ ruby spec/observers/person_observer.rb Throws an exception as expected... so load path is fine. Mikel -- http://lindsaar.net/ Rails, RSpec and Life blog.... -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20081126/a592eb02/attachment.html>
And the weirdness continues... Making a new observer against a different (empty) model works as expected. Deleting the entire person model down to just the class declaration, still does not work.>:|-- http://lindsaar.net/ Rails, RSpec and Life blog.... -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20081126/69a615f0/attachment.html>
OK, in the app I have some name spaced classes under a ''int'' directory. Some of these classes have observers and they have the same name as the top level classes. If I make a new observer in the top level that shares a name with an observer inside the namespace, the specs work. If I create an observer that does not have a shared name, the specs don''t work. Strange... -- http://lindsaar.net/ Rails, RSpec and Life blog.... -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20081126/1b7941f4/attachment.html>