Help request: failing to create an instance of a class within a spec

Hi everyone, I’m doing my best to get up to speed in ruby and rails.
Within
a test project, 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 the spec, I’m trying to create a new instance of the street
class,
but it doesn’t know what street is. That’s acceptable, I add require 'streets' and it still fails with

$ 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/[email protected]/gems/rspec-core-3.0.2/lib/rspec/core/configuration.rb:1057:in
load' from /home/sjouke/.rvm/gems/[email protected]/gems/rspec-core-3.0.2/lib/rspec/core/configuration.rb:1057:inblock in load_spec_files’
from
/home/sjouke/.rvm/gems/[email protected]/gems/rspec-core-3.0.2/lib/rspec/core/configuration.rb:1057:in
each' from /home/sjouke/.rvm/gems/[email protected]/gems/rspec-core-3.0.2/lib/rspec/core/configuration.rb:1057:inload_spec_files’
from
/home/sjouke/.rvm/gems/[email protected]/gems/rspec-core-3.0.2/lib/rspec/core/runner.rb:97:in
setup' from /home/sjouke/.rvm/gems/[email protected]/gems/rspec-core-3.0.2/lib/rspec/core/runner.rb:85:inrun’
from
/home/sjouke/.rvm/gems/[email protected]/gems/rspec-core-3.0.2/lib/rspec/core/runner.rb:70:in
run' from /home/sjouke/.rvm/gems/[email protected]/gems/rspec-core-3.0.2/lib/rspec/core/runner.rb:38:ininvoke’
from
/home/sjouke/.rvm/gems/[email protected]/gems/rspec-core-3.0.2/exe/rspec:4:in
<top (required)>' from /home/sjouke/.rvm/gems/[email protected]/bin/rspec:23:inload’
from /home/sjouke/.rvm/gems/[email protected]/bin/rspec:23:in
<main>' from /home/sjouke/.rvm/gems/[email protected]/bin/ruby_executable_hooks:15:ineval’
from
/home/sjouke/.rvm/gems/[email protected]/bin/ruby_executable_hooks:15:in
`’

Any idea why it wouldn’t be loading the file appropriately?
I’m also using rspec-rails.

On Jul 21, 2014, at 17:35, Sjouke F. [email protected] wrote:

Hi everyone, I’m doing my best to get up to speed in ruby and rails. Within a
test project, I’m trying to create an instance of a class in a spec file, but I’m
failing to do this.

This is most likely a rails question (or rspec) and is better addressed
to one of their lists/forums.

Excerpts from Sjouke F.'s message of 2014-07-22 02:35:45 +0200:

‘streets’` and it still fails with

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

Any idea why it wouldn’t be loading the file appropriately?
I’m also using rspec-rails.

I think the issue is that you need to tell require where ‘street.rb’
really is.
I never used rails, so I can’t say if rspec is supposed to be able to
determine
it automatically, but otherwise you’d need to either write

require ‘./app/models/street.rb’

or

require_relative ‘…/…/…/app/models/street.rb’

or call rspec adding your application directory to the load path, using
the -I
option: rspec -I app

and use

require ‘models/street’

I hope this helps

Stefano

Strangely, everything works, I don’t know why. I didn’t even need to use
the -I flag or the require statement. I wonder if was because I started
using bundle exec rspec instead of rspec.

On Tue, Jul 22, 2014 at 1:40 AM, Stefano C.
[email protected]

Oh, I’m sorry, I did post this in the Ruby on Rails forum as well. I
honestly had forgotten where I posted it, and it looks like I cross
posted.
I am sorry, thanks for letting me know about the list. I will continue
the
conversation in there (after responding to Stefano).

On Mon, Jul 21, 2014 at 9:38 PM, Ryan D. [email protected]