2

When running through the rspec course in codeschool I keep running into the same problem. I will set up as requested and after creating zombie_spec.rb and running rspec I get the proper output listed below:

Justins-MacBook-Pro:rubyproject Justin$ rspec spec/lib/zombie_spec.rb 
Run options: include {:focus=>true}

All examples were filtered out; ignoring {:focus=>true} 
*

Pending: 
  A Zombie is named Ash 
    # Not yet implemented 
    # ./spec/lib/zombie_spec.rb:3

Finished in 0.00929 seconds 
1 example, 0 failures, 1 pending

Randomized with seed 7259

As I continue on with the first video and create the class Zombie as mentioned I receive this error when running rspec again:

Justins-MacBook-Pro:rubyproject Justin$ rspec spec/lib/zombie_spec.rb 
/usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- zombie (LoadError) 
from /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require' 
from /Users/Justin/rubyproject/spec/lib/zombie_spec.rb:2:in `<top (required)>' 
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load' 
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `block in load_spec_files' 
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `each' 
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load_spec_files' 
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:22:in `run' 
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:80:in `run' 
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:17:in `block in autorun'

After this I removed everything and uninstalled and reinstalled rspec. Retried it again and returned the same results.

Any clue what is going on?

Thank you in advance for your help!

4 Answers 4

3

require_relative will load the file from the same directory as the rspec file

2

I had pretty much the same issue, though mine never worked even once at first. Updating the zombie_spec.rb file to show the full path of my zombie.rb file seemed to get it working properly.

Eg:require "/home/me/ruby/spec/lib/zombie"

1
  • Thanks, should haven noticed this!
    – Jtanacredi
    Jul 5, 2013 at 20:04
1

I use this and it worked

require_relative "zombie.rb"

0

Well if this still a problem I got into the same issue so I created a folder under spec/lib where I put all the codes and another spec/test where goes all the tests then it worked. and I also added require_relative here is the code snippet

zombie_spec.rb

require 'spec_helper'
require_relative '../lib/zombie'

describe Zombie do

  it "has a name called'Jack'" do
    zb = Zombie.new
    zb.name.should == "Jack"
  end

  it "has no brains" do
    zb = Zombie.new
    zb.should be_intelligent == false
  end

end

zombie.rb

class Zombie
  attr_accessor :name

  def initialize
    @name = "Jack"
  end

  def intelligent?
    false
  end
end

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.