How to load a spec_helper.rb automatically in RSpec 2

痞子三分冷 提交于 2019-12-02 16:32:00
Jacob

In RSpec 2, the /spec folder is always automatically on your load path. This means that all you need is:

require 'spec_helper'

at the top of your spec files. This will always load /spec/spec_helper.rb, and is the minimum you'll be able to get away with.

This means you don't need a horrid approach such as:

require File.join(File.dirname(File.dirname(__FILE__)), 'spec_helper.rb')

(which needs to be updated for different nesting levels).

Also you can add to your .rspec file the option: --require spec_helper, which will require this file in each spec file, without the manual require statement at the top.

Doug

The --require spec_helper line is automatically added to the .rspec file for RSpec 3.0 when you do rspec --init.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!