What does "<top (required)>" mean in a Ruby stack trace?

Viewed 51411

In Ruby 1.9.2 stack trace I frequently see the method given as <top (required)>, as in this section of stack below. What does this mean? Is my Ruby install subtly broken?

Could not find abstract-1.0.0 in any of the sources
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler/spec_set.rb:87:in `block in materialize'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler/spec_set.rb:81:in `map!'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler/spec_set.rb:81:in `materialize'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler/definition.rb:90:in `specs'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler/definition.rb:135:in `specs_for'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler/definition.rb:124:in `requested_specs'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler/environment.rb:23:in `requested_specs'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler/runtime.rb:11:in `setup'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler.rb:107:in `setup'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler/setup.rb:14:in `<top (required)>'
<internal:lib/rubygems/custom_require>:33:in `require'
<internal:lib/rubygems/custom_require>:33:in `rescue in require'
<internal:lib/rubygems/custom_require>:29:in `require'
5 Answers

Ninto's answer makes total sense. It's a stack trace that you get one things fail. I was running my tests by doing:

bundle exec rspec spec

and what I got was:

An error occurred while loading ./spec/foodie_spec.rb.
Failure/Error: require 'foodie/food'

SyntaxError:
  /Users/honey/Dev/foodie/funnex/lib/funnex/food.rb:17: syntax error, unexpected end-of-input, expecting end
# ./lib/foodie.rb:4:in `require'
# ./lib/foodie.rb:4:in `<top (required)>'
# ./spec/foodie_spec.rb:1:in `require'
# ./spec/foodie_spec.rb:1:in `<top (required)>'
No examples found.


Finished in 0.00002 seconds (files took 0.07998 seconds to load)
0 examples, 0 failures, 1 error occurred outside of examples

All I was doing wrong in my case was that I was missing and end.

But to understand the stack trace more, start from bottom of the commented out lines ie this line:

# ./spec/foodie_spec.rb:1:in `<top (required)>'
  • At line 1 of foodie_spec I had require 'foodie'
  • At line 4 of foodie.rb I had require 'foodie/food'
  • I errored out at line 17 of foodie/food

Stack traces in Ruby are also named backtraces or stack traceback

Related