Rspec showing wrong version number - ruby-on-rails

I'm running a Rails 2.3.4 app under ruby 1.8.7 and rvm with a custom gemset.
In trying to get rspec up and running, I've tried several times to uninstall rspec 2 and install rspec and rspec-rails version 1.3.4. However, when I run rspec -v I get 2.10.0 regardless of what I do.
Finally I got this error message:
You are running rspec-2, but it seems as though rspec-1 has been loaded as
well. This is likely due to a statement like this somewhere in the specs:
require 'spec'
Please locate that statement, remove it, and try again.
So it looks like 2.10.0 is actually still loaded. Even if I do a gem uninstall rspec rspec is still loaded. What's going on?

You should use spec (the RSpec 1 executable) instead of rspec, as explained in this answer.

Related

Having issues with gem version when running Cucumber

I originally posted the question: What does this Cucumber error message mean?
Following the suggestion of uninstalling builder and running bundle worked, for a while. Now I am getting a similar error, but this time on rack.
When I run cucumber features I get the following (previously cucumber has worked):
can't activate rack (~> 1.2.1,
runtime) for ["actionpack-3.0.7",
"railties-3.0.7"], already activated
rack-1.3.0 for ["rack-test-0.6.0",
"cucumber-rails-0.5.0"]
(Gem::LoadError)
Deleting rack just to get cucumber to work doesn't sound like a really good idea to me. How can I fix this problem so it doesn't come back again on another dependency?
I think you could put the exact version numbers for your gems (including Cucumber) in your Gemfile and then run using bundle exec
bundle exec cucumber
This will run the Cucumber version in your Gemfile, which should always keep things working even when you upgrade your system version.
The other option is to use RVM gemsets

RSpec: Can I retain the new Rspec (2.0.x) with the old one (1.3.x) and still run autospec on 2.3.x Rails apps?

I gave Rails3 a try and to do so I installed the new gems, like RSpec2. When I went back to my old apps though, autospec stopped working for Rails 2.3.x apps:
$ AUTOFEATURE=true autospec
/usr/local/lib/site_ruby/1.8/rubygems.rb:335:in `bin_path': can't find executable autospec for rspec-2.0.1 (Gem::Exception)
from /usr/bin/autospec:19
When searching for this error on Google all I find are solutions that are for Rails 3. Based on what I've read, it seems that autospec executable has changed/removed.
Is there a way I can keep the new RSpec gems and still use autospec in 2.3.x apps?
I encountered the exact same problem, and i solved this by using rvm and gemsets. I described that in this article.

Rspec not displaying colours

I'm running Rspec 2.0.0rc on Windows 7. I am also running the win32console gem (1.3.0 x86-mingw32).
The colours aren't being displayed - everything is showing up in boring old white/grey.
What am I doing wrong?
Edit: I also tried Rspec 2.0.0. and had the same problem
Under normall installation of rspec gems, you should get the colored output. I am not sure which version of gem you are using.
There is one more solution.
While running rspec give the command like this
spec --color sometestfile.rb
--color options is important here
RSpec 2 has been officially released today, perhaps try upgrading?
Finally sorted this out by uninstalling all the gems relating to RSpec and Win32Console. Reinstalled (and specified 2.0.0 for RSpec) and everything worked.

MissingSourceFile when I run "cucumber features"

I had cucumber 0.6.1 working quite fine... but I ran the gem update cucumber command, and things went smoothly. Then when I decided to run the cucumber features command, I received this error:
Using the default profile...
no such file to load -- cucumber/webrat/element_locator (MissingSourceFile)
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in gem_original_require'
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:inpolyglot_original_require'
So I tried a few things... I did a gem update on webrat, that didn't work. I removed all previous versions of cucumber by doing gem uninstall cucumber then selecting past versions. Same with webrat. No luck. What am I doing wrong?
Have you tried to regenerate cucumber files with script/generate cucumber --webrat? Maybe it solves it. Just take care not to overwrite features/support/paths.rb.
I resolved this issue. There was an old version of the 'freelancing-god-thinking-sphinx' gem on the server i was deploying to. Removing this gem enabled everything to work properly.
I had a similar issue using Bundler where my Gemfile had >= 0.4.3 version of cucumber, so it would always look to install newer versions of cucumber when updating/installing the bundler gems. Cucumber's env file (/features/support/env), however, referenced files that were not part of the future releases. In particular, '/cucumber/rails/world'. Therefore, I got the same MissingSourceFile error you are getting.
I think either want to roll back your version of cucumber, or update your cucumber env file so it's compatible with your version of cucumber.
For me, I commented out the following line in my env.rb file
# require 'cucumber/webrat/element_locator'
# Deprecated in favor of #tableish - remove this line if you don't
# use #element_at or #table_at
As you can see by the comment following it, it has been depreciated anyway.

How do I run my Specs with the previous version of Rspec?

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

Resources