I installed the Mocha 0.9.7 Rails plug-in using:
$ script/plugin install git://github.com/floehopper/mocha.git
(Just followed instruction in http://mocha.rubyforge.org/)
Then, I have the following set-up defined in my functional test
def setup
#controller.expects(:logged_in?).returns(true)
#controller.expects(:admin_user?).returns(true)
end
Running the test generates the ff. error:
NameError: uninitialized constant Mocha::Mockery::ImpersonatingName
/test/functional/xxxx_controller_test.rb:x:in `setup'
Before that, I see the ff. error at the top of the test log:
/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.3/lib/active_support/test_case.rb:12: warning: already initialized constant Mocha
This has led me to believe that I have an old version of Mocha somewhere in Ruby's or Rails' path. The problem is I can't find it.
Is my guess correct? If so, where is this old version of Mocha? Alternatively, how can I found out where it is?
According to http://selfamusementpark.com/blog/2009/07/30/rails233mochaconfusion/, my guess is not correct. The problem really is that Mocha is being loaded before the testing framework which is not what the former expects. The solution is to edit RAILS_ROOT/vendor/plugin/mocha/init.rb to comment out the ff. line:
require 'mocha'
Then, Mocha will have to be explicitly required in the test files or helpers to ensure that the testing framework will have been loaded beforehand.
Related
I am upgrading rails from 4.1 to 4.2.x. I am facing multiple issues while upgrading it. As of now rspec is failing with following error :
Warning: you should require 'minitest/autorun' instead.
Warning: or add 'gem "minitest"' before 'require "minitest/autorun"'
I have also added minitest in my Gemfile.
Can you please help me in figuring out on how this can be removed?
Update:
My rspec_helper.rb has require 'rspec/autorun'. I replaced it with require 'minitest/autorun'. I still run into same error.
require "rspec/autorun" was deprecated in RSpec 3, so is not the solution to your problem. You should remove it. You should also remove minitest from your Gemfile. It's likely being pulled in by a dependency, having you explicitly specify it won't change anything.
minitest and rspec are two separate libraries. The warning is not coming from rspec. I'm guessing you're just seeing it when you run your test suite. My best guess is that one of your test libraries is loading minitest some how. It's a big hammer, but you can try installing all your gems to a local cache bundle install --vendor and then grepping for minitest: grep minitest/autorun -R . to try and locate.
I'm using Ruby 2.2.0p0, and Rails 4.2.0. The Rails application is currently defaulting to using minitest, even though there's no testing gems mentioned in the Gemfile. For example, I have rake test in my rake tasks, and a test folder.
I can see how to install RSpec-rails. But what, if anything, do I need to do to uninstall minitest?
The only thing the RSpec-Rails README has is
Once installed, RSpec will generate spec files instead of Test::Unit
test files when commands like rails generate model and rails generate
controller are used.
It seems to me that in your case it not necessary to uninstall minitest, just add rspec to your Gemfile and start using it. However I recommend you to make RSpec as your default test framework.
Just add to config/application.rb next line:
config.generators.test_framework :rspec
That's it. Now Rails knows that you use RSpec and when you use Rails generators, it will add appropriate RSpec templete files, not Minitest ones. If you have test folder in your application (it's used by Minitest and Test::Unit) you can delete it now.
Im using spork 0.9.2 and rspec 3.0.0. When trying to run test rspec --drb I have an exception
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/spork-0.9.2/lib/spork/test_framework/rspec.rb:11:in run_tests: uninitialized constant RSpec::Core::CommandLine (NameError)
But when changing rspec version back to 2.6 - everything is OK.
Has anyone faced the same issue? Is it possible to work around?
The reason is that RSpec::Core::CommandLine was removed in Rspec3
https://github.com/rspec/rspec-core/blob/master/Changelog.md
Merge RSpec::Core::CommandLine (never formally declared public) into RSpec::Core::Runner. (Myron Marston)
But spork depends on this code.
There is already an issue on spork's github and a solution can be found in a following spork's fork:
https://github.com/codecarson/spork/commit/38c79dcedb246daacbadb9f18d09f50cc837de51#diff-937afaa19ccfee172d722a05112a7c6fL6
In general - replace
::RSpec::Core::CommandLine.new(argv).run(stderr, stdout)
with
::RSpec::Core::Runner.run(argv,stderr, stdout)
in the soprks source code
Like #lx00st said:
The reason is that RSpec::Core::CommandLine was removed in Rspec3
The spork gem hasn't been updated in rubygems.org. However, the fix has been merged into spork's master branch on github. You can grab it by telling bundler that you'd like to get spork from github (master) instead of rubygems.org. So do this:
This has been fixed on spork's master branch. Simple solution:
gem 'spork', github: 'sporkrb/spork', branch: 'master'
If you're using spork-rails, just require spork via github before requiring spork-rails in your gemfile. For more info on this, see my comment here:
https://github.com/sporkrb/spork-rails/issues/26
Edit: added branch: 'master'
Same thing here. Just remove the "--drb" line from .spec file and remove the cli: '--drb' parameter on the guard :rspec... line within the Guardfile. This does not turn off spork. It just turn off the "distributed ruby" (--drb) Rspec option. As guard knows you are running Rspec through Spork, it is not needed.
I started using Spring instead of Spork and that solved it.
It seems to be the new Rails way:
http://edgeguides.rubyonrails.org/4_1_release_notes.html#spring-application-preloader
I had this same problem. Sans digging into the rspec3 source code, removing the --drb line from my .rspec file fixed the problem for me. Some Guardfile examples also have use of the --drb which causes issues for me. Once removed all tests work fine.
Anyone have any idea what is causing this error when running cucumber features?
uninitialized constant DatabaseCleaner (NameError)
Add this line to your Gemfile:
gem 'database_cleaner'
This is because cucumber-rails doesn't automatically depend on database_cleaner because you may be building a Rails application without a database, and so you must explicitly require it.
DatabaseCleaner is a library for 'cleaning' your db. Cucumber will use it between running features to ensure your db is in a testable state (ie. empty).
The idea is that you build up the proper data in your Given clauses for each test
This error just means that DatabaseCleaner hasn't been required properly.
Different versions of Rails/Cucumber have different ways of configuring everything and provide different functionality with this regard so it's hard to actually give you the right solution without knowing your setup.
A couple of tips though:
Look at the cucumber-rails gem. It gives you lots of nice stuff such as generators and also rake tasks so you can run rake cucumber instead of using cucumber directly. Often times the generators will build a config file that requires database_cleaner for you.
Otherwise, add database_cleaner to your list of dependencies and put a require 'database_cleaner' somewhere in your test suite code.
I just experienced the problem. I downgraded my cucumber gems to version 1.0.6, and I got this message:
uninitialized constant Cucumber::Rails::Database (NameError)
when I use cucumber 1.0.6 (not the latest version) and database_cleaner v. 1.7.0. For fixing the error, I just run this command (on Rails 3.1.3):
rails g cucumber:install
It will prompt you to replace file features/support/env.rb. Just answer with Y and you can run rake cucumber:ok again.
I am using spring, and spring stop work for me
I am trying to implement a gem called stanfordparser which can be found here: http://stanfordparser.rubyforge.org/
It is a ruby wrapper for a java natural language parser
I am developing in netbeans using ruby on rails / jruby on a windows 7 machine. My web app works fine otherwise, but when I try to add the parser wrapper it breaks.
Here is the code that is causing a problem:
gem 'stanfordparser'
def show
parser = StanfordParser::LexicalizedParser.new
#words = parser.apply("This is a sentence.")
end
this is in the taskscontroller
and when I go to tasks/show (which, if i remove this code, works fine) I get the following error
uninitialized constant TasksController::StanfordParser
I have made sure the gem is installed in netbeans
I am very new to ruby on rails, and teaching myself, so it may be something obvious
Thanks!
EDIT: I checked my glassfish server logs and it says
SEVERE: Missing these required gems:
stanfordparser
which is weird because I've installed the gem using netbeans, I've done rake gems:install and netbeans says the gem is installed. I've checked in netbeans gems folder and the gem is installed there.
EDIT 2:
So, after a lot of research and head banging, I've decided to simplify things a bit by just trying to use jruby to implement the java classes, now I need to figure out how to import the stanfordparser java classes (there are at least 50), I think I need to compress all the classes into a jar so that jruby can load it. maybe.
If you are using Rails 3 then the gem 'stanfordparser' statement needs to be specified in Bundler's Gemfile within the project's root. Otherwise, for Rails 2.x you need a config.gem 'stanfordparser' statement within config/environment.rb.
I was able to solve my problem the following way:
instead of using the stanfordparser ruby wrapper (which implements java ruby bridge to connect the java stanford parser to pure ruby), I use jruby to just implement the java from the stanford parser.
the code that ended up working:
include Java
require 'C:\\Stanford-Parser\\Current\\stanford-parser.jar'
require 'rubygems'
include_class 'edu.stanford.nlp.parser.lexparser.LexicalizedParser'
lp = LexicalizedParser.new(args) #args is the arguments, not copied here