[rspec-users] Application-wide spec_helper method

Zach Dennis zach.dennis at gmail.com
Sat Aug 30 11:33:19 EDT 2008

On Fri, Aug 29, 2008 at 11:05 PM, Scott Taylor
<mailing_lists at railsnewbie.com> wrote:
> On Aug 29, 2008, at 10:40 PM, Nick Hoffman wrote:
>> On 2008-08-28, at 13:27, Zach Dennis wrote:
>>> You can put it in a module and include it for model specs in
>>> spec_helper.rb
>>> Spec::Runner.configure do |config|
>>> # ...
>>> config.include DescribeModelAttributeSpecHelper, :type => :model
>>> end
>>> Zach
>> Hi Zach. I put the methods into the module "ModelSpeccer" in
>> lib/ModelSpeccer.rb and then added this to spec_helper.rb :
>>   config.include ModelSpeccer, :type => :model
>> Unfortunately though, when I run my specs, Ruby isn't finding the module:
> This isn't ruby - if you want ruby to include it, you'll need a require
> statement (or a load, or autoload).

I think Scott means to say "this isn't rspec, you need to tell ruby to
load the file using require".

I would keep your spec helpers separate from application code (like
app/ or lib/ directories). I typically put these files in
spec/spec_helpers/ and then in your spec_helper.rb I require all ruby
files like so:

    Dir[File.dirname(__FILE__) + "/spec_helpers/**/*.rb"].each do |f|
       require f

Just a thought,

Zach Dennis

More information about the rspec-users mailing list