Hi, How are people specifying models which act_as_list? I''m thinking that it would be possible to check that acts_as_list instance methods have been added to a class using something like this: describe Page, "acts_as_list" do it "should act as a list" do Page.ancestors.should be_include(ActiveRecord::Acts::List::InstanceMethods) end it "should use page_index as position_column" do Page.new.position_column.should == "page_index" end it "should have scope of book_id" do Page.new.scope_condition.should == "book_id IS NULL" end end it at least lets you drive adding acts_as_list? Any thoughts on how I can improve this? How anyone else has done this? Cheers, Steve
On 8/15/07, Steve Tooke <steve.tooke at gmail.com> wrote:> Hi, > > How are people specifying models which act_as_list? > > I''m thinking that it would be possible to check that acts_as_list > instance methods have been added to a class using something like this:You''re specing the code not the behavior. This will make double-work if you want to change anything.
Hmm that''s true. If the acts_as_list implementation changed, or is removed then this isn''t going to work. But you don''t really want to go down the rabbit warren of checking that the whole of the acts_as_list implementation works as expected, as presumably that''s already tested. Perhaps I''m just being over complicated, and you could just mock the call to acts_as_list? Of course that still wouldn''t guard against the acts_as_list behaviour changing to something that doesn''t match what you were trying to achieve. Thanks, more to think about! On 8/15/07, Courtenay <court3nay at gmail.com> wrote:> On 8/15/07, Steve Tooke <steve.tooke at gmail.com> wrote: > > Hi, > > > > How are people specifying models which act_as_list? > > > > I''m thinking that it would be possible to check that acts_as_list > > instance methods have been added to a class using something like this: > > You''re specing the code not the behavior. > This will make double-work if you want to change anything. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
On 8/16/07, Steve Tooke <steve.tooke at gmail.com> wrote:> Hmm that''s true. > > If the acts_as_list implementation changed, or is removed then this > isn''t going to work. But you don''t really want to go down the rabbit > warren of checking that the whole of the acts_as_list implementation > works as expected, as presumably that''s already tested. > > Perhaps I''m just being over complicated, and you could just mock the > call to acts_as_list? > > Of course that still wouldn''t guard against the acts_as_list behaviour > changing to something that doesn''t match what you were trying to > achieve.Exactly! You should spec the specific behaviour that YOUR application needs. acts_as_list likely provides more than you are using. If you focus your specs on that which your application needs, then you are safe when you update rails, plugins, etc, because if something changes that breaks what your application relies on, then you''ll be alerted by failing specs. If whatever changes appear don''t affect what your application cares about, then no problem.> > Thanks, more to think about! > > On 8/15/07, Courtenay <court3nay at gmail.com> wrote: > > On 8/15/07, Steve Tooke <steve.tooke at gmail.com> wrote: > > > Hi, > > > > > > How are people specifying models which act_as_list? > > > > > > I''m thinking that it would be possible to check that acts_as_list > > > instance methods have been added to a class using something like this: > > > > You''re specing the code not the behavior. > > This will make double-work if you want to change anything. > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >