Rspec failing to find the model

I’m trying to create an instance of a class in a spec file, but I’m failing to do this.

These two files exists:

app/models/street.rb

spec/models/street_spec.rb

Within street_spec.rb, I’m trying to create a new instance of the street class, but it doesn’t

know what street is. That’s acceptable, but when I add require 'streets' and it still fails:

$ rspec spec/models/street_spec.rb

/home/sjouke/streetmap/spec/models/street_spec.rb:2:in `require’: cannot load such file – street (LoadError)

from /home/sjouke/streetmap/spec/models/street_spec.rb:2:in `<top (required)>’

from /home/sjouke/.rvm/gems/ruby-2.1.2@streetmap/gems/rspec-core-3.0.2/lib/rspec/core/configuration.rb:1057:in `load’

from /home/sjouke/.rvm/gems/ruby-2.1.2@streetmap/gems/rspec-core-3.0.2/lib/rspec/core/configuration.rb:1057:in `block in load_spec_files’

from /home/sjouke/.rvm/gems/ruby-2.1.2@streetmap/gems/rspec-core-3.0.2/lib/rspec/core/configuration.rb:1057:in `each’

from /home/sjouke/.rvm/gems/ruby-2.1.2@streetmap/gems/rspec-core-3.0.2/lib/rspec/core/configuration.rb:1057:in `load_spec_files’

from /home/sjouke/.rvm/gems/ruby-2.1.2@streetmap/gems/rspec-core-3.0.2/lib/rspec/core/runner.rb:97:in `setup’

from /home/sjouke/.rvm/gems/ruby-2.1.2@streetmap/gems/rspec-core-3.0.2/lib/rspec/core/runner.rb:85:in `run’

from /home/sjouke/.rvm/gems/ruby-2.1.2@streetmap/gems/rspec-core-3.0.2/lib/rspec/core/runner.rb:70:in `run’

from /home/sjouke/.rvm/gems/ruby-2.1.2@streetmap/gems/rspec-core-3.0.2/lib/rspec/core/runner.rb:38:in `invoke’

from /home/sjouke/.rvm/gems/ruby-2.1.2@streetmap/gems/rspec-core-3.0.2/exe/rspec:4:in `<top (required)>’

from /home/sjouke/.rvm/gems/ruby-2.1.2@streetmap/bin/rspec:23:in `load’

from /home/sjouke/.rvm/gems/ruby-2.1.2@streetmap/bin/rspec:23:in `’

from /home/sjouke/.rvm/gems/ruby-2.1.2@streetmap/bin/ruby_executable_hooks:15:in `eval’

from /home/sjouke/.rvm/gems/ruby-2.1.2@streetmap/bin/ruby_executable_hooks:15:in `’

Any idea why it wouldn’t be loading the file appropriately?

Also, I’m using using rspec-rails after a suggestion from somebody in IRC.

  1. Please, post your street_spec.rb file content.

  2. Did you run rails generate rspec:install ?

Hi Javix, I did run rails generate rspec:install. I forgot to mention that.

Here’s the output of the files I mentioned:

$ cat spec/models/street_spec.rb

require “spec_helper”

require “street”

describe “a street” do

it “can be created” do

Street.new

end

end

$ cat app/models/street.rb

class Street < ActiveRecord::Base

attr_accessor :coordinates

end

You should remove the line ‘require “street”’.

You should have smth liek that in your street_spec.rb:

require 'spec_helper'

describe Street do

describe 'whatever you want' do

before { @street = Street.new}

it 'has something to check' do

end

end

end