[rspec-users] using rspec in a non-rails environment

David Chelimsky dchelimsky at gmail.com
Mon Apr 23 17:42:57 UTC 2012


On Mon, Apr 23, 2012 at 12:26 PM, S Ahmed <sahmed1020 at gmail.com> wrote:
> My folder structure is as follows:
>
> /myapp/
> /myapp/lib/class1.rb
>
> /myapp/rspec/spec_helper.rb
> /myapp/rspec/lib/class1_spec.rb
>
> My spec_helper has:
>
> require 'rubygems'

^^ If you've installed rspec as a gem and you're running the rspec
command, you don't need to require 'rubygems'. ^^

> require 'rspec'

^^ This should be 'rspec/autorun'. ^^

>
> RSpec.configure do |config|
> end

This ^^ is not necessary unless you're using it

> My class1_spec.rb has:
>
> require 'spec_helper'
> require '../../lib/class1'
>
> describe Class1 do
>   it "should do something"
> end
>
>
> How do I require my class1 correct, when I run:
>
> rspec spec/lib/class1_spec.rb I am getting:
>
> 1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file --
> ../../lib/class1.rb (LoadError)

RSpec adds 'lib' to the LOAD_PATH, so you can just `require "class1"`,
but it's conventional to do this in spec_helper.rb instead.

HTH,
David


> Also, in a non-rails app, what kind of things do you put in the spec_helper
> normally? any popular config settings that I should know about?
>
> thanks!


More information about the rspec-users mailing list