I was planning on using a fixture within a description that didn''t modify the fixture, so I put it in a before(:all) block: describe "Customer", "xml" do fixtures :customers before(:all) do one = customers(:one) end # ... As a result, I got this message: 1) NoMethodError in ''Customer xml before(:all)'' You have a nil object when you didn''t expect it! You might have expected an instance of Array. The error occurred while evaluating nil.[] ./spec/models/customer_spec.rb:86: script/spec:4: If I convert it to before(:each) or simply before, it works just fine. describe "Customer", "xml" do fixtures :customers before do one = customers(:one) end # ... By design? bug? PEBKAC? Anyone else hit this? - Geoffrey -- Geoffrey Wiseman -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070907/82661968/attachment.html
On 9/7/07, Geoffrey Wiseman <geoffrey.wiseman at gmail.com> wrote:> I was planning on using a fixture within a description that didn''t modify > the fixture, so I put it in a before(:all) block: > describe "Customer", "xml" do > fixtures :customers > > before(:all) do > one = customers(:one) > end > > # ... > As a result, I got this message: > > 1) > NoMethodError in ''Customer xml before(:all)'' > You have a nil object when you didn''t expect it! > You might have expected an instance of Array. > The error occurred while evaluating nil.[] > ./spec/models/customer_spec.rb:86: > script/spec:4: > If I convert it to before(:each) or simply before, it works just fine. > describe "Customer", "xml" do > fixtures :customers > > before do > one = customers(:one) > end > > # ... > By design? bug? PEBKAC? Anyone else hit this? >By design. Fixtures don''t work with before(:all). There has been several discussions about this on the list previously. Aslak> - Geoffrey > -- > Geoffrey Wiseman > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
On Sep 7, 2007, at 3:31 PM, Geoffrey Wiseman wrote:> I was planning on using a fixture within a description that didn''t > modify the fixture, so I put it in a before(:all) block: > describe "Customer", "xml" do > fixtures :customers > > before(:all) do > one = customers(:one) > end > > # ... > As a result, I got this message: > > 1) > NoMethodError in ''Customer xml before(:all)'' > You have a nil object when you didn''t expect it! > You might have expected an instance of Array. > The error occurred while evaluating nil.[] > ./spec/models/customer_spec.rb:86: > script/spec:4: > If I convert it to before(:each) or simply before, it works just fine. > describe "Customer", "xml" do > fixtures :customers > > before do > one = customers(:one) > end > > # ... > By design? bug? PEBKAC? Anyone else hit this? >Looks like a bug to me, although I don''t know why you would want to load a fixture only once, and not before every test. Generally, I don''t find much use for a before(:all) block (they are discouraged in Test::Unit as well, for their unreliable use with more than one test). Scott
On 9/8/07, Scott Taylor <mailing_lists at railsnewbie.com> wrote:> > On Sep 7, 2007, at 3:31 PM, Geoffrey Wiseman wrote: > > > I was planning on using a fixture within a description that didn''t > > modify the fixture, so I put it in a before(:all) block: > > describe "Customer", "xml" do > > fixtures :customers > > > > before(:all) do > > one = customers(:one) > > end > > > > # ... > > As a result, I got this message: > > > > 1) > > NoMethodError in ''Customer xml before(:all)'' > > You have a nil object when you didn''t expect it! > > You might have expected an instance of Array. > > The error occurred while evaluating nil.[] > > ./spec/models/customer_spec.rb:86: > > script/spec:4: > > If I convert it to before(:each) or simply before, it works just fine. > > describe "Customer", "xml" do > > fixtures :customers > > > > before do > > one = customers(:one) > > end > > > > # ... > > By design? bug? PEBKAC? Anyone else hit this? > > > > Looks like a bug to me, although I don''t know why you would want to > load a fixture only once, and not before every test. Generally, I > don''t find much use for a before(:all) block (they are discouraged in > Test::Unit as well, for their unreliable use with more than one test). >Like I said - it''s by design. It''s been discussed in previous mail threads. Aslak> Scott > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
On Sep 8, 2007, at 5:47 PM, aslak hellesoy wrote:> On 9/8/07, Scott Taylor <mailing_lists at railsnewbie.com> wrote: >> >> On Sep 7, 2007, at 3:31 PM, Geoffrey Wiseman wrote: >> >>> I was planning on using a fixture within a description that didn''t >>> modify the fixture, so I put it in a before(:all) block: >>> describe "Customer", "xml" do >>> fixtures :customers >>> >>> before(:all) do >>> one = customers(:one) >>> end >>> >>> # ... >>> As a result, I got this message: >>> >>> 1) >>> NoMethodError in ''Customer xml before(:all)'' >>> You have a nil object when you didn''t expect it! >>> You might have expected an instance of Array. >>> The error occurred while evaluating nil.[] >>> ./spec/models/customer_spec.rb:86: >>> script/spec:4: >>> If I convert it to before(:each) or simply before, it works just >>> fine. >>> describe "Customer", "xml" do >>> fixtures :customers >>> >>> before do >>> one = customers(:one) >>> end >>> >>> # ... >>> By design? bug? PEBKAC? Anyone else hit this? >>> >> >> Looks like a bug to me, although I don''t know why you would want to >> load a fixture only once, and not before every test. Generally, I >> don''t find much use for a before(:all) block (they are discouraged in >> Test::Unit as well, for their unreliable use with more than one >> test). >> > > Like I said - it''s by design. > > It''s been discussed in previous mail threads. > > AslakSorry, didn''t see your post on the thread. Scott