[rspec-users] Best practices for managing fixtures outside Rails?...

Stu stuart.hungerford at gmail.com
Fri May 14 20:25:36 EDT 2010


Hi,

I have a non-Rails Ruby project that uses RSpec.  It needs a shared
collection of fixture-like objects created, although they have nothing
to do with Rails, AR or database entries:

w1 = Widget.new(10)
w2 = Widget.new(20)
w3 = Widget.new(30)
# ...

g1 = Gadget.new(w1, w2)
g2 = Gadget.new(w3, w1)
g3 = Gadget.new(w2, w3)
#...

Currently these are in a shared examples.rb file and are brought into
various *_spec.rb files in a way that feels like a real hack.  I've
since discovered a fork of Machinist that works with PORO's and allows
those object to have an initializer with arguments, so I should be
able to replace the above with machinist blueprints etc.

I figure I'm not the first person in the world to be using RSpec and
fixture-like objects in this way, so are there any best practices for
doing this outside Rails? I've read this a number of times, but it's
starting to sink in that projects need to manage their specs/tests
with the same agility and care they devote to the code.

Any advice much appreciated,

Stu


More information about the rspec-users mailing list