rspec's new support/ directory, alternative machinist installation possibility

Skip to first unread message


Feb 3, 2010, 2:03:58 PM2/3/10
to Machinist Users
Hi all

Thought this may be of interest to some, as it means not editing the
generated spec_helper anymore.

With rspec 1.3.0 and rspec-rails 1.3.2 spec_helper now contains the

> Requires supporting files with custom matchers and macros, etc,
> in ./support/ and its subdirectories.
>ir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}

Which means you can do this:

>require 'machinist/active_record'
>require 'sham'
>require 'faker'
>Spec::Runner.configure do |config|
> config.before(:all) { Sham.reset(:before_all) }
> config.before(:each) { Sham.reset(:before_each) }
># blueprints follow…
and so on, and they will be auto-loaded when you run your specs.

The only snag I hit so far is if you have your blueprints in a
blueprints/ directory which you were requiring in then rspec may beat
you to it, and try to interpret them before machinist has been loaded.
Errors abound.
I expect this is easily fixed by putting require ../blueprints at the
top of said files, but I just stuck them back into the blueprints file
for now as it's a new project with only a couple of models.

I think this is kinda cool, it reminds me of how cucumber does this
now, and although I update rspec less frequently than cucumber it
still seems like a better option than customising the generated files
(which will then clash on update later).

Reply all
Reply to author
0 new messages