A couple of days ago I switched from RVM to rbenv. I now have issues with rspec for a rails project. I'm getting this message:
You have already activated rspec-core 3.0.3, but your Gemfile requires rspec-core 2.14.8.
I tried to do:
gem install rspec-core '2.14.8'
but then I got this error message:
ERROR: Could not find a valid gem '2.14.8' (>= 0) in any repository
after which rbenv just uses RSpec 3.0.3.
So the only way now to run the test in my Rails project is to use:
bundle exec rspec spec
Is there a way to install a pre-RSpec 3 version of RSpec beside the installed RSpec 3.0.3 so I can again run the test in my Rails project by just typing:
rspec spec
I'm using Rails 4.1.1.
The Rails 4 way to run things under bundler and spring is to run scripts in the bin directory. To generate such a script for rspec, install the spring-commands-rspec gem and run bundle exec spring binstub --all. If your current directory is the root of your rails project, you can then just type bin/rspec.
Side note: RSpec runs the spec directory by default, so you don't need to type spec.
To save typing bin/, either add your Rails project's bin directory to your PATH in the usual way or use direnv.
You probably want rspec-rails, not just RSpec. If so, since you're using Rails 4.1.x, you'll need rspec-rails 2.99, which needs rspec 2.99.x, not 2.14.x. (Documented in rspec-rails' Changelog.)
Related
I am creating an application on ruby on rails:
After creating users, for validating users I am running below commands:
$ bundle exec rake db:migrate
$ bundle exec rake test:prepare
Both command are run properly on the rails commandLine, but when I run the below command:
$ bundle exec rspec spec/models/user_spec.rb
I am getting error below:
Warning: you should require 'minitest/autorun' instead.
Warning: or add 'gem "minitest"' before 'require "minitest/autorun"'
And I am using 4.1.1 version of rails.
I don't understand why it comes.
Kindly suggest me, waiting for your reply.
Thanks.
More a note for posterity than anything, but this issue can also happen if you're using an older version of shoulda-matchers. You can see some discussion around this on their Github repo here, or on the rspec-rails repo here.
Update shoulda-matchers by running bundle update shoulda-matchers. You want the latest version (or at least 2.6.2) and this message should go away.
Include minitest gem in your 'Gemfile' and run bundle install
gem install 'minitest'
and then bundle install
Jonathans-MacBook-Air-2:hw3-rottenpotatoes Jonathan$ cucumber
WARN: Unresolved specs during Gem::Specification.reset:
tzinfo (~> 0.3.37)
WARN: Clearing out unresolved specs.
Please report a bug if this causes problems.
You have already activated activesupport 4.0.0, but your Gemfile requires activesupport 3.2.14. Using bundle exec may solve this. (Gem::LoadError)
/Users/Jonathan/.rvm/gems/ruby-1.9.3-p448/gems/bundler-1.3.5/lib/bundler/runtime.rb:33:in `block in setup'
/Users/Jonathan/.rvm/gems/ruby-1.9.3-p448/gems/bundler-1.3.5/lib/bundler/runtime.rb:19:in `setup'
/Users/Jonathan/.rvm/gems/ruby-1.9.3-p448/gems/bundler-1.3.5/lib/bundler.rb:120:in `setup'
/Users/Jonathan/.rvm/gems/ruby-1.9.3-p448/gems/bundler-1.3.5/lib/bundler/setup.rb:7:in `'
But it seems like I have the right rails version in this directory.
Jonathans-MacBook-Air-2:hw3-rottenpotatoes Jonathan$ rails --version
Rails 3.2.14
I'm kind of new to ruby and am confused as to why "rake cucumber" works but "cucumber" doesn't in the terminal.
I don't know how ruby and gems are set up but I have a hunch is that somehow in my working directory, ruby is told to use rails 3.2.14 but the command "cucumber" is only detecting activtesupport 4.0.0 (which I believe is tied to rails)
Thanks so much!
cucumber is a binstub, while rake cucumber is a rake task that executes the library.
Try bundle install -—binstubs first, then try cucumber.
Perhaps the binstub is somehow out of date?
If that doesn't work, just kill the binstubs by deleting the project/bin dir, and rerun bundle install -—binstubs
You have multiple versions of Rails installed and cucumber doesn't know which to use, so it's trying to load both and erroring out.
To use the one specified in your Gemfile, specify bundle exec before all commands, eg. bundle exec cucumber.
Background:
I get errors whenever I run rake in an older project. (uninitialized constant Rake::DSL).
The rails project in question is an old project that was started with Rails 2.1 (I think), and since then I've updated the OS on my laptop a couple of times, and made updates along the way to make it run.
Right now, the rails app works fine, provided I have RAILS_GEM_VERSION set to 2.3.5. I'm not sure if the app was completely updated to Rails 2.3.5.
There is no Gemfile in my older project.
If I create a brand-new rails project (and unset RAILS_GEM_VERSION), rake runs fine.
My question: To troubleshoot, I'd like to try newer versions of rake. I'd like to know how to force one specific version to be used, since it appears I have multiple versions installed.
Info on my environment:
$ gem list rake
*** LOCAL GEMS ***
rake (0.9.2.2, 0.9.2, 0.8.7, 0.8.3)
$ rake --version
rake, version 0.8.7
So it looks like it's picking up the 0.8.7 version.
All the help files online seem to tell me to specify the rake version in the Gemfile, but there isn't one in this project. (Maybe it predates gemfiles?)
If I unset the RAILS_GEM_ENVIRONMENT variable altogether, and try to run rake, I get:
rake aborted!
can't activate rails (= 2.3.5, runtime) for [], already activated rails-3.2.8 for []
None of the environment config files in my older project set that variable either.
This may be of help. Have you tried the underscore solution?
Example:
rake _0.9.2_
you can run rake specific version by using this
bundle exec rake ...
more detail see this - bundle exec, rake
You can uninstall the current version of rake and install another desired version using commands similar to the following:
gem uninstall rake 12.3.1
gem install rake 10.5.0
(Note: you might need to run as sudo for permissions)
I had a problem where I received the following error while trying to install rake 10.5.0:
Could not find a valid gem '0.8.7' (>= 0) in any repository
I resolved this problem by adding the following line to my Gemfile:
gem 'rake', ' <11.0'
After editing Gemfile I was able to successfully downgrade rake by updating my gems:
bundle update
I have a rails project that runs fine in development and production and the tests pass when I do a rake test but when I try to autotest it it fails with:
Missing the Rails 2.3.3 gem. Please `gem install -v=2.3.3 rails`, blah blah
Of course the rails gem is not missing and if I comment this line out, it complains about the rest of the gems.
Trying to debug the problem, I initiated a new rails project and started copying code from the problematic one and running autotest every now and then. After a couple of minutes I had copied all the files (even the tmp folder) and autotest was not complaining at all.
The only difference between the projects is their RAILS_ROOT, one is ~/Sites/market and the other ~/Code/tempora and their .git folders though I seriously doubt it should make much of a difference.
Also I have a ~/.autotest with the following inside (which should also make no difference):
require 'autotest/growl'
require 'autotest/timestamp'
I really have no idea on where to look for debugging this anymore....
LOCAL GEMS
rails (2.3.3, 2.3.2, 2.2.2, 2.1.1, 2.1.0)
ZenTest (4.1.3, 4.1.1) - also tried with 4.1.4 yielding the same results
autotest-fsevent (0.1.1)
autotest-growl (0.1.6, 0.1.2)
autotest-rails (4.1.0)
The only thing I can think of is that autotest is looking for Rails in your ~/.gem folder in one instance and in your /Library/Ruby/Gems in another. What might sort it out is just to install RVM. Then, create an RVM environment with just the gems you need and try running in that. Learn more about RVM here: http://rvm.beginrescueend.com/
I have been following an RSpec tutorial on one of my machines, in the hope of learning more about BDD and TDD. My setup was with Rails 2.2.2 and Rspec 1.1.12
Tonight I decided to continue on my primary machine and moved my code from my portable to my desktop. Not having RSpec, i installed the gem . . .
sudo gem install rspec
sudo gem install rspec-rails
Strife and Calumny! The new version of Rspec installed! 1.2.0! And now my tests are failing all over the place! While I fully intend to follow up and learn the most up to date version, I would really like to complete what's left of the tutorial without having to start over. I am wondering. Is there a way to install and specify that I would like to run my code against the previous Rspec, 1.2.12?
You could uninstall and reinstall with VERSION specified. Explained here.
If you want to have more than one version on your computer, for if maybe you should have a 2.2 rails app and a 2.3 rails app then in your environment.rb file specify:
config.gem, 'rspec', :lib => 'spec', :version => '1.1.12'
and your application will use that gem spec and the rspec-rails gem that goes with it. This will enable you to use the appropriate gem for each appliction.
In addition to specifying the rspec and rspec-rails versions in my environments/test.rb file, I added script/ in front of spec, e.g.:
script/spec spec/controllers/treasury_accounts_controller.rb
to get past this error:
/opt/ror/ruby-ee-1.8.7-2011-03/lib/ruby/site_ruby/1.8/rubygems.rb:335:in `bin_path': can't find executable spec for rspec-2.1.0 (Gem::Exception)
from /opt/ror/ruby/bin/spec:19