How do I run my Specs with the previous version of

2019-07-11 14:22发布

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?

3条回答
我想做一个坏孩纸
2楼-- · 2019-07-11 14:49

You could uninstall and reinstall with VERSION specified. Explained here.

查看更多
叼着烟拽天下
3楼-- · 2019-07-11 14:56

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.

查看更多
【Aperson】
4楼-- · 2019-07-11 14:58

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
查看更多
登录 后发表回答