can cucumber and rspec use the same blueprints.rb file

856 Views Asked by At

I'm using Rails 3, machinist 2, cucumber and rspec all together and have two blueprints.rb files. One in the spec directory and one in the features/support directory.

Is it a good idea to just have one blueprints.rb file?

If it is, what is the preferred way of setting this up?

For the meantime I'm just symlinking my features/support/blueprints.rb file to spec/blueprints.rb which maybe bad, but it works for me.

2

There are 2 best solutions below

1
On BEST ANSWER

i have this inside of features/support

file name machinist.rb

require 'machinist/active_record' 

Dir[ File.dirname(__FILE__) + "/../../spec/blueprints/*"].each {|file| require file }

Before { Sham.reset } # to reset Sham's seed between scenarios so each run has same random sequences
0
On

It certainly sounds sane - we do this for shared fixtures and helpers (but I don't use Machinist).

What you probably need to do is include a line like this in your cucumber env and rspec helper files. What this does is put the directory containing the blueprints.rb file at the top of Ruby's list of paths to look at when including files.

$: << File.expand_path(File.join(File.dirname(__FILE__), "..","..","shared","directory"))
#require 'blueprints' will now look in the above directory first

The "..","..","shared","directory" part being the relative path from the current file to the shared directory where your blueprints.rb file is.