# Error on custom\_require.rb when rspec executed

**URL:** <https://www.ruby-forum.com/t/error-on-custom-require-rb-when-rspec-executed/171935>\
**Category:** Rails\
**Created:** [July 11, 2009, 7:51pm UTC](https://www.ruby-forum.com/t/error-on-custom-require-rb-when-rspec-executed/171935 "2009-07-11T19:51:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bekkou68](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/4bbf92/32.png) [@bekkou68](https://www.ruby-forum.com/u/bekkou68)\
**Post date:** [July 11, 2009, 7:51pm UTC](https://www.ruby-forum.com/t/error-on-custom-require-rb-when-rspec-executed/171935/1 "2009-07-11T19:51:58Z")

</div>

Hello all,

I’m bekkou68.  
I have a error on custom\_require.rb, which occurred when I execute  
rspec.

I executed the following command.  
$ script/spec spec/models/

Then, I got the following result.

# /usr/local/lib/site\_ruby/1.8/rubygems/custom\_require.rb:31:in

`gem\_original\_require’: no such file to load – application  
(MissingSourceFile)

# from /usr/local/lib/site\_ruby/1.8/rubygems/custom\_require.rb:

31:in `require’

# from /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/

active\_support/dependencies.rb:158:in `require’

# from /home/project/vendor/plugins/rspec\_on\_rails/lib/spec/

rails.rb:3

# from /usr/local/lib/site\_ruby/1.8/rubygems/custom\_require.rb:

31:in `gem\_original\_require’

# from /usr/local/lib/site\_ruby/1.8/rubygems/custom\_require.rb:

31:in `require’

# from /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/

active\_support/dependencies.rb:158:in `require’

# from /home/project/spec/models/…/spec\_helper.rb:6

# from /home/project/spec/models/eng\_word\_spec.rb:1:in `require’

# from /home/project/spec/models/eng\_word\_spec.rb:1

# from /home/project/vendor/plugins/rspec/lib/spec/runner/

example\_group\_runner.rb:14:in `load’

# from /home/project/vendor/plugins/rspec/lib/spec/runner/

example\_group\_runner.rb:14:in `load\_files’

# from /home/project/vendor/plugins/rspec/lib/spec/runner/

example\_group\_runner.rb:13:in `each’

# from /home/project/vendor/plugins/rspec/lib/spec/runner/

example\_group\_runner.rb:13:in `load\_files’

# from /home/project/vendor/plugins/rspec/lib/spec/runner/

options.rb:85:in `run\_examples’

# from /home/project/vendor/plugins/rspec/lib/spec/runner/

command\_line.rb:19:in `run’

# from script/spec:4

Here is the contents of custom\_require.rb.

# ============================== from here

==============================  
#–

# Copyright 2006 by Chad F., Rich Kilmer, Jim W. and others.

# All rights reserved.

# See LICENSE.txt for permissions.

#++

require ‘rubygems’

module Kernel  
alias gem\_original\_require require # :nodoc:

# 

# We replace Ruby’s require with our own, which is capable of

# loading gems on demand.

# 

# When you call require ‘x’, this is what happens:

# \* If the file can be loaded from the existing Ruby loadpath, it

# is.

# \* Otherwise, installed gems are searched for a file that matches.

# If it’s found in gem ‘y’, that gem is activated (added to the

# loadpath).

# 

# The normal require functionality of returning false if

# that file has already been loaded is preserved.

# 

def require(path) # :nodoc:  
gem\_original\_require path  
rescue LoadError =\> load\_error  
if load\_error.message =~ /#{Regexp.escape path}\z/ and  
spec = Gem.searcher.find(path) then  
Gem.activate(spec.name, “= #{spec.version}”)  
gem\_original\_require path  
else  
raise load\_error  
end  
end  
end # module Kernel

# ============================== to here

==============================

Should I add ‘require xxx’ ?  
Are they some wrong codes on custom\_require.rb?  
Should I update RubyGems?

I’m really happy if you help me.

Sincerely,  
bekkou68

---

<div class="post-metadata">

**Author:** ![bekkou68](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/4bbf92/32.png) [@bekkou68](https://www.ruby-forum.com/u/bekkou68)\
**Post date:** [July 12, 2009, 8:00pm UTC](https://www.ruby-forum.com/t/error-on-custom-require-rb-when-rspec-executed/171935/2 "2009-07-12T20:00:09Z")

</div>

The error is a couple steps back up the trace, in rspec’s rails.rb.  
The problem is that you’re running an old version of rspec\_on\_rails,  
which expects ApplicationController to be defined in app/controllers/  
application.rb, which it isn’t anymore. Upgrading to the new version  
of rspec\_on\_rails will fix this.

–Matt J.

---

<div class="post-metadata">

**Author:** ![bekkou68](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/4bbf92/32.png) [@bekkou68](https://www.ruby-forum.com/u/bekkou68)\
**Post date:** [July 17, 2009, 10:15am UTC](https://www.ruby-forum.com/t/error-on-custom-require-rb-when-rspec-executed/171935/3 "2009-07-17T10:15:16Z")

</div>

Dear Mr.Matt,

Thanks for your message, and I’m sorry that I reply late.

> Upgrading to the new version of rspec\_on\_rails will fix this.  
> I tried to update rspec with the following command.  
> $ ruby script/plugin install git://github.com/dchelimsky/rspec.git -r  
> ‘refs/tags/1.2.7’ --force  
> $ ruby script/plugin install git://github.com/dchelimsky/rspec-rails.git  
> -r ‘refs/tags/1.2.7.1’ --force  
> $ ruby script/generate rspec  
> ([http://wiki.github.com/dchelimsky/rspec/rails](http://wiki.github.com/dchelimsky/rspec/rails))

Then I can’t execute spec,  
$ script/spec -v

# script/spec:3:in `require’: no such file to load – spec (LoadError)

# from script/spec:3

The contents of spec is following,  
$ more spec

# #!/usr/bin/env ruby

# $LOAD\_PATH.unshift(File.expand\_path(File.dirname( **FILE** ) + "/…/

vendor/plugins/rspec/lib"))

# require ‘spec’

Now I can’t solve this problem.  
I’m happy when you help me.

Thanks,  
bekkou68

---

<div class="post-metadata">

**Author:** ![bekkou68](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/4bbf92/32.png) [@bekkou68](https://www.ruby-forum.com/u/bekkou68)\
**Post date:** [July 27, 2009, 10:36am UTC](https://www.ruby-forum.com/t/error-on-custom-require-rb-when-rspec-executed/171935/4 "2009-07-27T10:36:39Z")

</div>

rspec-rails 1.2.7.1 is surely working for me.  
Your script/spec file seems like broken, though, I think you’d better  
recreate your whole project and try again from scratch.  
I recommend you not to edit the generated script/spec file unless  
you’re writing a patch for the RSpec project to fix a bug within  
RSpec.

If you’re not sticking on vendorizing plugins, config.gem feature  
might be an easier way for you.  
Put the following lines in your config/environments/test.rb file:

config.gem ‘rspec’, :lib =\> false, :version =\> ‘1.2.8’  
config.gem ‘rspec-rails’, :lib =\> false, :version =\> ‘1.2.7.1’

and run:

% ruby script/generate rspec

–  
Akira M.
