[rspec-users] How to specify current directory for specs?

Daniel Lidström dlidstrom at gmail.com
Tue Nov 9 13:14:29 EST 2010


Hello,

I'd like to know if it's possible to specify what directory to use as
the current directory when executing the specifications. My specs are
in spec/ and I have some data in spec/data that I want to read from
one of the specs:

spec/book_spec.rb

require 'book'

describe Book do
  it "should read version" do
    book = Book.new "data/JA_s12.book"     # This should open the file
    book.version.should == 1
  end
end

Of course I can prepend spec/ to the path above, but I'd rather not. I
have created a rake task for running my specifications:


desc "Run all specs in the spec directory"
RSpec::Core::RakeTask.new('spec') do |t|
  t.rspec_opts = %w[--color]
end

Can I specify the spec/ directory as the current directory when
running this task? What is the expert recommendation? Is the data for
my specs malplaced, you think?
Thanks in advance!

Daniel


More information about the rspec-users mailing list