Rspec failing while upgrading RubyGem-rails to 4.2.x - ruby-on-rails

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.

Related

spork 0.9.2 and rspec 3.0.0 = uninitialized constant RSpec::Core::CommandLine (NameError)

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.

rspec spec invalid option: --default_path=spec

I'm getting a very strange error from rspec:
$ rspec spec
invalid option: --default_path=spec
I'm in a rails 4, ruby 2 app and I've updated everything to rspec-rails 3.0.0.beta. I've dumped and re installed rspec, .rspec, and spec_helper.rb.
You're probably using a different version of RSpec. The tests run fine from the balanced-ruby project. Make sure you have this line in the Gemfile:
gem "rspec", '~> 2.10'
Then run bundle install and finally try again with bundle exec rspec spec.
This is old but for whomever Googles this: in addition to checking your Gemfile, take a look at your repo's .rspec config file to see if there is an issue. If that doesn't fix it, check your environment to see if you have a global .rspec config file. Try cat ~/.rspec to see if you have one and if there are any issues with it. The global config caused issues for me.

cucumber / rails error uninitialized constant DatabaseCleaner (NameError)

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

autotest shows blank

I installed the autotest gem and intend to use it with rspec. The problem is, when I run autotest under my rails app, all I see is :
railsapp$ autospec
loading autotest/rails_rspec
And its stuck there until I Ctrl-C out of it. Nothing changes even if I change a rspec test or code.
Here's my ~/.autotest
require "autotest/restart"
require 'redgreen/autotest'
require 'autotest/fsevent'
require "autotest/growl"
I had the same problem. I was eventually able to get everything working by making sure I was on the latest (beta, if necessary) versions of rspec, rspec-rails, autotest, and autotest-rails, and putting the following in autotest/discovery.rb:
Autotest.add_discovery { "rails" }
Autotest.add_discovery { "rspec2" }
Here's the blog post that got me started in the right direction.
I had the same problem, and this fixed it:
"Make sure you have a .rspec file in the project root. That tells RSpec to tell Autotest to load RSpec’s autotest extension."
ref: https://github.com/rspec/rspec/wiki/autotest
It seems as if my .rspec file had gotten deleted when messing around with git.
Cd into app directory and run the command: AUTOFEATURE=true autospec
To stop this process ^C twice
I had the same problem with Rails 2.3.2 except that I'm not using RSpec. In my case, installing the autotest-rails-pure gem got it working for me. Maybe autotest requires the correct plugin in order to detect a test within a file.

Installing Mocha 0.9.7 in a Rails 2.3.3 project

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.

Resources