Trying to use rspec, but getting an error that rsp

2019-03-18 23:25发布

I've update my gems. I've created a sample Rails app and have the following in my Gemfile:

source 'http://rubygems.org'

gem 'rails', '3.0.3'
gem 'sqlite3-ruby', :require => 'sqlite3'

group :development do
  gem 'rspec-rails'
end

group :test do
  gem 'rspec'
  gem 'webrat', '0.7.1'
end

However, when I run 'rspec spec/', I get the following message:

/home/jeff/.rvm/gems/ruby-1.9.2-p0/gems/bundler-1.0.7/lib/bundler/runtime.rb:27:in `block in setup': 
You have already activated rspec-core 2.2.1, but your Gemfile requires rspec-core 2.1.0. 
Consider using bundle exec. (Gem::LoadError)

6条回答
老娘就宠你
2楼-- · 2019-03-18 23:33

try using bundle update rspec and bundle update rspec-rails. your Gemfile.lock file, located in the root directory, is probably specifying a version number for each gem.

查看更多
一夜七次
3楼-- · 2019-03-18 23:39

A combination of Sam Ritchie's and Alexey's solutions helped me here. In the end I had to:

bundle update rspec
bundle update rspec-rails
sudo gem uninstall rspec-mocks
sudo gem uninstall rspec-expectations
sudo gem uninstall rspec-core

(prompts for versions if none are entered)

As Alexey says, use this to see which versions are too high:

gem list rspec

(Would vote for you Alexey, but apparently I don't have enough of a "reputation" on stack.)

查看更多
Viruses.
4楼-- · 2019-03-18 23:39

I got the same issue right now. to fix it try to:

sudo gem uninstall rspec-core -v 2.2.1
bundle update rspec-core

You may need to do that for other dependent gems (like rspec, rspec-rails etc). Use the command to see the candidates:

gem list rspec
查看更多
Explosion°爆炸
5楼-- · 2019-03-18 23:42

This is easily solved:

bundle exec rspec

will force bundler to use the gem version you are requiring for your project, ignoring system-wide settings.

查看更多
在下西门庆
6楼-- · 2019-03-18 23:55

change the version number from 2.1.0 to 2.2.1 in Gemfile.lock

查看更多
我只想做你的唯一
7楼-- · 2019-03-18 23:56

Rails noob here ... I'm following Michael Hartl's brilliant tutorial ... stuck at layouts

Tried changing rspec & webrat versions as mentioned in this post about rspec/webrat errors to no avail.

For rspec v2.1.0 I get the same error as @user338413.

rspec -v returns 2.2.1


dev machine running ubuntu 10.04

resolved....works with rspec 2.2.0 + webrat 0.7.1, although I would still like to know why

查看更多
登录 后发表回答