Mocha::Integration uninitialized constant - ruby-on-rails

I am trying to re-write a unit test cases for a web application for the test cases is not updated for long. The following is the error that I get when I run 'rake test'.
Note: the web application is upgraded from 2.3.1 to 2.3.8 in mean while.
And the following is the stacktrace:
Loaded suite /apps/rails/website/install/local/ruby-1.8.7-p299/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader
Started
/apps/rails/website/install/local/ruby-1.8.7-p299/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:440:in `load_missing_constant': uninitialized constant Mocha::Integration (NameError)
from /apps/rails/website/install/local/ruby-1.8.7-p299/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:80:in `const_missing'
from /apps/rails/website/install/local/ruby-1.8.7-p299/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/testing/setup_and_teardown.rb:51:in `run'
from /apps/rails/website/install/local/ruby-1.8.7-p299/lib/ruby/1.8/test/unit/testsuite.rb:34:in `run'
from /apps/rails/website/install/local/ruby-1.8.7-p299/lib/ruby/1.8/test/unit/testsuite.rb:33:in `each'
from /apps/rails/website/install/local/ruby-1.8.7-p299/lib/ruby/1.8/test/unit/testsuite.rb:33:in `run'
from /apps/rails/website/install/local/ruby-1.8.7-p299/lib/ruby/1.8/test/unit/testsuite.rb:34:in `run'
from /apps/rails/website/install/local/ruby-1.8.7-p299/lib/ruby/1.8/test/unit/testsuite.rb:33:in `each'
from /apps/rails/website/install/local/ruby-1.8.7-p299/lib/ruby/1.8/test/unit/testsuite.rb:33:in `run'
from /apps/rails/website/install/local/ruby-1.8.7-p299/lib/ruby/1.8/test/unit/ui/testrunnermediator.rb:46:in `run_suite'
from /apps/rails/website/install/local/ruby-1.8.7-p299/lib/ruby/1.8/test/unit/ui/console/testrunner.rb:67:in `start_mediator'
from /apps/rails/website/install/local/ruby-1.8.7-p299/lib/ruby/1.8/test/unit/ui/console/testrunner.rb:41:in `start'
from /apps/rails/website/install/local/ruby-1.8.7-p299/lib/ruby/1.8/test/unit/ui/testrunnerutilities.rb:29:in `run'
from /apps/rails/website/install/local/ruby-1.8.7-p299/lib/ruby/1.8/test/unit/autorunner.rb:216:in `run'
from /apps/rails/website/install/local/ruby-1.8.7-p299/lib/ruby/1.8/test/unit/autorunner.rb:12:in `run'
from /apps/rails/website/install/local/ruby-1.8.7-p299/lib/ruby/1.8/test/unit.rb:279
from /apps/rails/website/install/local/ruby-1.8.7-p299/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5
please help me in this regard.

This helped me in this regard:
require 'mocha'
require 'mocha/integration/test_unit'
To be done in the test file, or in a helper if you are including one.

I had the same error, and re-installing of all gems helped me.

Related

undefined local variable or method `count_notification' for #Spec::Runner::TeamcityFormatter

Upgraded to latest rubymine 6.3 and while trying to run all the specs using spec configuration coming across the issue. Looking at the logs looks like a rubymine issue. Any idea how to fix this issue?
/Applications/RubyMine.app/rb/testing/patch/bdd/teamcity/spec/runner/formatter/teamcity/rspec3_formatter.rb:250:in `dump_summary': undefined local variable or method `count_notification' for #<Spec::Runner::Formatter::TeamcityFormatter:0x007f8d338fd3e8> (NameError)
from /Users/xxxxx/.rvm/gems/ruby-2.1.3/gems/rspec-core-3.1.7/lib/rspec/core/reporter.rb:134:in `block in notify'
from /Users/xxxxx/.rvm/gems/ruby-2.1.3/gems/rspec-core-3.1.7/lib/rspec/core/reporter.rb:133:in `each'
from /Users/xxxxx/.rvm/gems/ruby-2.1.3/gems/rspec-core-3.1.7/lib/rspec/core/reporter.rb:133:in `notify'
from /Users/xxxxx/.rvm/gems/ruby-2.1.3/gems/rspec-core-3.1.7/lib/rspec/core/reporter.rb:116:in `finish'
from /Users/xxxxx/.rvm/gems/ruby-2.1.3/gems/rspec-core-3.1.7/lib/rspec/core/reporter.rb:55:in `ensure in report'
from /Users/xxxxx/.rvm/gems/ruby-2.1.3/gems/rspec-core-3.1.7/lib/rspec/core/reporter.rb:55:in `report'
from /Users/xxxxx/.rvm/gems/ruby-2.1.3/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:107:in `run_specs'
from /Users/xxxxx/.rvm/gems/ruby-2.1.3/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:85:in `run'
from /Users/xxxxx/.rvm/gems/ruby-2.1.3/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:69:in `run'
from /Users/xxxxx/.rvm/gems/ruby-2.1.3/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:37:in `invoke'
from /Users/ac027466/.rvm/gems/ruby-2.1.3/gems/rspec-core-3.1.7/exe/rspec:4:in `<main>'
/Users/xxxxx/.rvm/rubies/ruby-2.1.3/bin/ruby -I/Users/xxxxx/.rvm/gems/ruby-2.1.3/gems/rspec-core-3.1.7/lib:/Users/xxxxx/.rvm/gems/ruby-2.1.3/gems/rspec-support-3.1.2/lib /Users/xxxxx/.rvm/gems/ruby-2.1.3/gems/rspec-core-3.1.7/exe/rspec --pattern spec/\*\*\{,/\*/\*\*\}/\*_spec.rb failed
Updating to rubymine 6.3.3 fixed the issue for me.

Why Can't I Execute RSpec?

Working through Michael Hartle's tutorial and I cannot execute RSpec; terminal is presenting with the following error:
/Users/coreymkimball/Canvi/Tutorials/sample_app/spec/requests/static_pages_spec.rb:1:in `require': cannot load such file -- spec-helper (LoadError)
from /Users/coreymkimball/Canvi/Tutorials/sample_app/spec/requests/static_pages_spec.rb:1:in `<top (required)>'
from /Users/coreymkimball/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load'
from /Users/coreymkimball/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `block in load_spec_files'
from /Users/coreymkimball/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `each'
from /Users/coreymkimball/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load_spec_files'
from /Users/coreymkimball/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:22:in `run'
from /Users/coreymkimball/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:80:in `run'
from /Users/coreymkimball/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:17:in `block in autorun'
It states that there has been a load error in the particular file; not sure how to go about creating a new one, or getting over this troubleshooting hurdle. Any help would be great.
You'll likely find that the file you made in your spec directory is called spec_helper, not spec-helper. Change the require at the top of your static_pages_spec.rb to reflect this.

NoMethodError on Rails Vulcanize with Rubber

I am very new to rails and am trying to get my app setup via rubber. I was able to get a test app up without issue but am running into some sort of error when actually trying to vulcanize my built app. Tried to search high and low to no avail. Anyone have any idea what I need to do to get rid of the issue? Much appreciated.
localhost:thiswins markhayden$ rubber vulcanize complete_passenger_nginx_mysql
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rubber-2.2.4/lib/rubber/commands/vulcanize.rb:53:in `block in <class:Vulcanize>': undefined method `-' for "complete_passenger_nginx_mysql":String (NoMethodError)
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/clamp-0.6.0/lib/clamp/attribute/declaration.rb:33:in `instance_exec'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/clamp-0.6.0/lib/clamp/attribute/declaration.rb:33:in `block in define_writer_for'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/clamp-0.6.0/lib/clamp/parameter/parsing.rb:13:in `block (2 levels) in parse_parameters'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/clamp-0.6.0/lib/clamp/parameter/parsing.rb:12:in `each'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/clamp-0.6.0/lib/clamp/parameter/parsing.rb:12:in `block in parse_parameters'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/clamp-0.6.0/lib/clamp/parameter/parsing.rb:10:in `each'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/clamp-0.6.0/lib/clamp/parameter/parsing.rb:10:in `parse_parameters'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/clamp-0.6.0/lib/clamp/command.rb:55:in `parse'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/clamp-0.6.0/lib/clamp/command.rb:68:in `run'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/clamp-0.6.0/lib/clamp/subcommand/execution.rb:11:in `execute'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/clamp-0.6.0/lib/clamp/command.rb:69:in `run'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/clamp-0.6.0/lib/clamp/command.rb:127:in `run'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/rubber-2.2.4/bin/rubber:17:in `<top (required)>'
from /usr/local/rvm/gems/ruby-1.9.3-p392/bin/rubber:19:in `load'
from /usr/local/rvm/gems/ruby-1.9.3-p392/bin/rubber:19:in `<main>'
from /usr/local/rvm/gems/ruby-1.9.3-p392/bin/ruby_noexec_wrapper:14:in `eval'
from /usr/local/rvm/gems/ruby-1.9.3-p392/bin/ruby_noexec_wrapper:14:in `<main>'
We had this same problem with:
rubber vulcanize complete_passenger_postgresql
It seems to be an error in the gem at rubber/commands/vulcanize.rb on Line 53 because it tries to subtract an array from a string which is illegal. I changed it to (as sudo):
invalid = (arg.kind_of?(String) ? [arg] : arg) - VulcanizeThor.valid_templates
This allowed setup however I am not sure if the vulcanization did more than it was supposed to have because I am also new to Rubber. This was a drastic measure so be careful by trying it on a non-production environment first!

uninitialized constant when migrating rails from ubuntu to osx

i'm trying to move my rails app from ubuntu to osx. when running rspec, i get the following obscure error:
/Users/josh/dev/myproject/spec/support/devise.rb:3:in `block in <top (required)>': uninitialized constant RequestHelpers (NameError)
from /Users/josh/.rvm/gems/ruby-1.9.3-p286#myproject/gems/rspec-core-2.11.1/lib/rspec/core.rb:92:in `configure'
from /Users/josh/dev/myproject/spec/support/devise.rb:1:in `<top (required)>'
from /Users/josh/dev/myproject/spec/spec_helper.rb:21:in `block (2 levels) in <top (required)>'
from /Users/josh/dev/myproject/spec/spec_helper.rb:21:in `each'
from /Users/josh/dev/myproject/spec/spec_helper.rb:21:in `block in <top (required)>'
from /Users/josh/.rvm/gems/ruby-1.9.3-p286#myproject/gems/spork-0.9.2/lib/spork.rb:24:in `prefork'
from /Users/josh/dev/myproject/spec/spec_helper.rb:4:in `<top (required)>'
from /Users/josh/dev/myproject/spec/controllers/comments_controller_spec.rb:1:in `require'
from /Users/josh/dev/myproject/spec/controllers/comments_controller_spec.rb:1:in `<top (required)>'
from /Users/josh/.rvm/gems/ruby-1.9.3-p286#myproject/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `load'
from /Users/josh/.rvm/gems/ruby-1.9.3-p286#myproject/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `block in load_spec_files'
from /Users/josh/.rvm/gems/ruby-1.9.3-p286#myproject/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `map'
from /Users/josh/.rvm/gems/ruby-1.9.3-p286#myproject/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `load_spec_files'
from /Users/josh/.rvm/gems/ruby-1.9.3-p286#myproject/gems/rspec-core-2.11.1/lib/rspec/core/command_line.rb:22:in `run'
from /Users/josh/.rvm/gems/ruby-1.9.3-p286#myproject/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:66:in `rescue in run'
from /Users/josh/.rvm/gems/ruby-1.9.3-p286#myproject/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:62:in `run'
from /Users/josh/.rvm/gems/ruby-1.9.3-p286#myproject/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:8:in `block in autorun'
everything works nicely in Ubuntu, so i guess it must be environmental. Any ideas where to start digging?
thanks
- Josh
EDIT: no idea why, but the file request_helpers.rb could not be found by rake. moving it elsewhere resolved the issue.
This hardly seems an operating system problem, much rather a matter of configuration. Make sure your environemnt is the same in terms of:
using rvm installed the same way
having all the needed gems in the Gemfile
using bundle to execute rspec
using the same version of everything.
By te way this is not an obscure message, it's in fact pretty clear:
uninitialized constant RequestHelpers (NameError)
so the spec/support/devise.rb file can't find the needed class.
Have you written that file? If not, how did you generate it? Repeat the procedure to generate it (probably rake something or rails generate something) and it will be OK.

Rspec not running on an application

Ok so I am a ruby on rails developer and I am about to start trying to use the TDD (test driven development) approach and I am not sure what I am doing wrong. I have an existing app that has some rpec tests already and I am trying to figure how to run them but when i do
rake spec
(in /Users/tamer/Sites/preview)
/Users/tamer/.rvm/gems/ruby-1.9.2-p290#my_app/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb:206:in `const_missing_from_s3_library': uninitialized constant PreviewsController (NameError)
from /Users/tamer/.rvm/gems/ruby-1.9.2-p290#my_app/gems/rspec-core-2.5.1/lib/rspec/core/backward_compatibility.rb:20:in `const_missing'
from /Users/tamer/Sites/preview/spec/controllers/previews_controller_spec.rb:3:in `<top (required)>'
from /Users/tamer/.rvm/gems/ruby-1.9.2-p290#my_app/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `block in load_spec_files'
from /Users/tamer/.rvm/gems/ruby-1.9.2-p290#my_app/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `map'
from /Users/tamer/.rvm/gems/ruby-1.9.2-p290#my_app/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `load_spec_files'
from /Users/tamer/.rvm/gems/ruby-1.9.2-p290#my_app/gems/rspec-core-2.5.1/lib/rspec/core/command_line.rb:18:in `run'
from /Users/tamer/.rvm/gems/ruby-1.9.2-p290#my_app/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:55:in `run_in_process'
from /Users/tamer/.rvm/gems/ruby-1.9.2-p290#my_app/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:46:in `run'
from /Users/tamer/.rvm/gems/ruby-1.9.2-p290#my_app/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:10:in `block in autorun'
rake aborted!
(See full trace by running task with --trace)
Is there something that i am missing and what I need to do to get the previous tests to run
The error is pretty self-explanatory.
uninitialized constant PreviewsController (NameError)
Chances are the PreviewsController class referenced by ./spec/controllers/previews_controller_spec.rb no longer exists in /app/controllers.
Either update the spec or remove it if the corresponding controller has been removed.

Resources