Forum: Nitro Nitro/Og rspec heads-up: any alternative solutions.

Posted by Mark Van De Vyver (mvyver)
on 2007-10-04 11:49
(Received via mailing list)
Hi Devs,

Hope this 'head-up' saves someone some time.  I'd appreciate any
alternative the are better then what I cam up with.
The following is known on the rspec list and I've asked there for
suggestions - will fwd if anything useful comes up.

The essential point is that rspec describe blocks are not isolated name 
spaces.
Consequence: if you're going to define classes then you'll need to
choose different class names for each describe/example block, or else
the spec's will run a good chance of being contaminated.

Any other suggestions?

Example, from the code snippets below, the last describe/example block
will return two attributes for the Person class:

@attrs   # [:name, :age]

:)
module Og
describe DbiAdapter, "field_sql_for_attribute (without :sql annotation)" 
do
    include OgSpecExpectations

    before(:all) do
      class Person
        attr_accessor :name, String, :sql => "some text"
      end
    end

<...>
end

describe DbiAdapter, "field_sql_for_attribute (without :sql annotation)" 
do
    include OgSpecExpectations

    before(:all) do
      class Person
        attr_accessor :age, String
      end
      <...>
      @attrs = @man.store.serializable_attributes_for_class(Person)
  end
<...>
end
end
Posted by Jonathan Buch (Guest)
on 2007-10-09 09:13
(Received via mailing list)
Hi,

> The essential point is that rspec describe blocks are not isolated name spaces.
> Consequence: if you're going to define classes then you'll need to
> choose different class names for each describe/example block, or else
> the spec's will run a good chance of being contaminated.

one more point for the old Test::Unit! ;D

But nah, I guess we just have to adhere to some naming scheme...
Or packing each spec into a module (which is quite unnice with Og where
the generated table name changes)...

Jo
Posted by * William (Guest)
on 2007-10-09 10:37
(Received via mailing list)
Hi

... I often have been know to make names like:

  *  class Class_test_001
         @desc = 'this tests something-K or another"
     end

you use the desc to tell what's IN the test ;)

w.
Posted by Mark Van De Vyver (mvyver)
on 2007-11-23 08:29
(Received via mailing list)
Hi resurrecting this thread with a solution...

On Oct 9, 2007 7:36 PM, * William <william.full.moon@gmail.com> wrote:
>
> > > Consequence: if you're going to define classes then you'll need to
> > > choose different class names for each describe/example block, or else
> > > the spec's will run a good chance of being contaminated.
> >
> > one more point for the old Test::Unit! ;D
> >
> > But nah, I guess we just have to adhere to some naming scheme...
> > Or packing each spec into a module (which is quite unnice with Og where
> > the generated table name changes)...
> >
> >

>From Aslay on the RSpec users mail list, you can clean up classes
'after' each example in the following example shows:

module Example
 describe "A class defined in before" do
   before do
     class Item
       @@var ||= 0
       @@var += 1

       def self.var
         @@var
       end
     end
   end

   it "should be redefined the first time" do
     Item.var.should == 1
   end

   it "should be redefined the second time" do
     Item.var.should == 1
   end

   after do
     Example.send(:remove_const, 'Item')
   end
 end
end


HTH
Mark
This topic is locked and can not be replied to.