Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RSpec LoadError

Tags:

ruby

rspec

I'm trying to practice writing tests for challenges on CodeEval. Each challenge I'm creating a folder, inside the project folder I create 'lib' & 'spec' folder. From the command line I run:

rspec --init

it tells me that 'spec/spec_helper.rb' & '.rspec' are created. I put the source file in the 'lib' folder & the spec file in the 'spec/lib' folder & name them accordingly. Here's an example of a spec:

require 'spec_helper'
require 'file_name'

describe '#swap_elements' do
  it 'should swap 1 pair of numbers' do
    swap_elements('1 2 3 4 5 6 7 8 9',0,8).should == '9 2 3 4 5 6 7 8 1'
  end
end

from the project's root directory I run:

rspec /spec/lib/file_name_spec.rb

and the result is the following:

/Users/username/.rvm/gems/ruby-2.0.0-p195/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load': cannot load such file -- /spec/lib/swap_elements_spec.rb (LoadError)
from /Users/username/.rvm/gems/ruby-2.0.0-p195/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `block in load_spec_files'
from /Users/username/.rvm/gems/ruby-2.0.0-p195/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `each'
from /Users/username/.rvm/gems/ruby-2.0.0-p195/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load_spec_files'
from /Users/username/.rvm/gems/ruby-2.0.0-p195/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:22:in `run'
from /Users/username/.rvm/gems/ruby-2.0.0-p195/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:80:in `run'
from /Users/username/.rvm/gems/ruby-2.0.0-p195/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:17:in `block in autorun'

This is a recent problem & I haven't installed any updated rspec gems. Any idea why this is happening?

like image 589
evkline Avatar asked May 25 '26 21:05

evkline


1 Answers

Using a slash at the start of a path means the root.

You want to do

rspec spec/lib/file_name_spec.rb

So it will search on the current directory

like image 159
Ismael Avatar answered May 28 '26 15:05

Ismael



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!