mocha_rails icon indicating copy to clipboard operation
mocha_rails copied to clipboard

uninitialized constant MochaRails (NameError)

Open ColemanGariety opened this issue 12 years ago • 7 comments

This is the error I get when I try to start my app with mocha_rails:

routes.rb:2:in `block in <top (required)>': uninitialized constant MochaRails (NameError)

Reproduce:

  1. Add gem 'mocha_rails' to the :test, :development group in Gemfile.
  2. Run bundle install
  3. Run rails g mocha_rails:install
  4. Run rails server

ColemanGariety avatar Sep 27 '13 21:09 ColemanGariety

Thanks for submitting this. Can you please give me some environment info? Bundler, Ruby, and Rails versions?

And just in case: Does "bundle exec rails server" help by any chance?

quartzmo avatar Sep 27 '13 22:09 quartzmo

Ruby: 1.9.3p448 Bundler: 1.3.5 Rails: 3.2.11

bundle_exec does not help

ColemanGariety avatar Sep 27 '13 23:09 ColemanGariety

I'm sorry, I tried to reproduce this by following your steps in a new Rails project, using nearly the same versions, but I could not.

Here is my bundle list output:

mocha_rails_test quartzmo$ bundle list Gems included by the bundle:

  • actionmailer (3.2.13)
  • actionpack (3.2.13)
  • activemodel (3.2.13)
  • activerecord (3.2.13)
  • activeresource (3.2.13)
  • activesupport (3.2.13)
  • arel (3.0.2)
  • builder (3.0.4)
  • bundler (1.3.5)
  • coffee-rails (3.2.2)
  • coffee-script (2.2.0)
  • coffee-script-source (1.6.3)
  • erubis (2.7.0)
  • execjs (2.0.2)
  • hike (1.2.3)
  • i18n (0.6.1)
  • journey (1.0.4)
  • jquery-rails (3.0.4)
  • json (1.8.0)
  • mail (2.5.4)
  • mime-types (1.25)
  • mocha_rails (0.0.5)
  • multi_json (1.8.0)
  • polyglot (0.3.3)
  • rack (1.4.5)
  • rack-cache (1.2)
  • rack-ssl (1.3.3)
  • rack-test (0.6.2)
  • rails (3.2.13)
  • railties (3.2.13)
  • rake (10.1.0)
  • rdoc (3.12.2)
  • sass (3.2.11)
  • sass-rails (3.2.6)
  • sprockets (2.2.2)
  • sqlite3 (1.3.8)
  • thor (0.18.1)
  • tilt (1.4.1)
  • treetop (1.4.15)
  • tzinfo (0.3.37)
  • uglifier (2.2.1)

quartzmo avatar Sep 28 '13 15:09 quartzmo

@quartzmo

The issue is nonexistant if I require the gem first:

unless Rails.env.production?
  require "mocha_rails"
  mount MochaRails::Engine => 'mocha' 
end

Any idea why that might be?

ColemanGariety avatar Sep 30 '13 19:09 ColemanGariety

@quartzmo however, the localhost:3000/mocha route still gives

Routing Error
No route matches [GET] "/mocha"

As if nothing is loaded. I feel I missed a step.

ColemanGariety avatar Sep 30 '13 20:09 ColemanGariety

Afaik, you should never have to manually require a Rails Engine. So I think the require solution is going down the wrong path. I still can't reproduce this issue myself, so hard for me to help.

quartzmo avatar Oct 03 '13 19:10 quartzmo

For what it's worth, I'm still seeing this error after following the installation steps outlined in the original post.

@JacksonGariety's require 'mocha_rails' fix resolves the issue but Rails then returns:

Routing Error
No route matches [GET] "/mocha"

mmwtsn avatar Jul 01 '14 14:07 mmwtsn