How do I run my Specs with the previous version of Rspec? - ruby-on-rails

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

Related

Geokit issue - "could not find generator"

I am trying to get started with Geokit, and I ran the install command and was greeted with the following:
rails g geokit_rails:install
Could not find generator geokit_rails:install.
Any idea what's going on? I am so confused. bundle install works just fine. I run bundle exec rake db:migrate. but when I go into the console, when I try require 'geokit', I get false. I assume it's because the config file is missing? But how do I generate a sample config file to modify if the install script is failing??
The problem is that your version of the geokit-rails gem does not contain the generator. It was added with https://github.com/geokit/geokit-rails/commit/bb4261acef62a26de823c4b7306634ffb7c3381f. The latest version of the gem is 2.1.0, and as you can see here, the generators were not part of that release.
If you want to use the head version of the gem, then you can change your Gemfile to match gem 'geokit-rails', github: 'geokit/geokit-rails'.

Rspec showing wrong version number

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.

In Ruby on Rails, what's the difference between installing something as a gem or as a plugin?

On http://github.com/collectiveidea/delayed_job
it says:
To install as a gem, add the following to config/environment.rb:
config.gem 'delayed_job'
Run rake gems:install
versus
To install as a plugin:
script/plugin install git://github.com/collectiveidea/delayed_job.git
What is the difference between installing it as a gem or as a plugin?
Also, the first method just install gem 2.0.3 which might be the tobi's version? (rake gems:install installs the version by gem list -r delayed_job) Is it http://github.com/tobi/delayed_job ?
The "plugin" method specifically says it is the collectiveidea version? Doesn't it matter which one you install?
Both the Gem and the vendored plugin refers to the collectiveidea's fork. In fact, collectiveidea is the current maintainer for the delayed_job Gem on RubyGems.
That said, generally speaking installing a plugins as a Gem has many advantages.
You can install it once and use it in many different projects
You can take advantage of dependency resolution
You can upgrade just changing version number
You don't need to store the entire plugin code in your SCM
So, why you can install a plugin "as a plugin"?
There are many different answers.
At the very beginning, Rails plugins came as simple libraries. Time passes and developers started to notice the advantage of packaging plugins as Gem.
Also, before Rails 3, some plugin features were only reserved to plugins and not to Gems. For instance, before Rails 3, plugins could bundle rake tasks while there wasn't a way to inject new rake tasks or new routes into the main application.
In the last two years, the most part of Rails plugins offers the ability to be installed as a plugin or as a Gem. With Rails 3 and the arrival of Bundler, I'm sure plugins are going to be deprecated in favor of Gems.
That are 2 different repositorys,
maybe you shoult try
config.gem 'delayed_job', :source => http://github.com/collectiveidea/delayed_job.git
Look at: http://ryandaigle.com/articles/2008/4/1/what-s-new-in-edge-rails-gem-dependencies
Btw. maybe you want to look at a maybe better solution: resque - see http://ruby-toolbox.com/categories/queueing.html for a comparison of used queing gems
When you install a gem it will be available for all apps, in case you use a plugin - just for an app it's installed into.
The basic difference is a gem is something that gets installed on the system running your Rails application, whereas a plugin is installed along with your application, plugin does not get installed on the system level.
suppose you are using rvm and let us take this example.
we have two applications app1 and app2
both are running on a common rvm gemset named gemset1
when you add a gem in the gemfile of app1 and run bundle install and then being in the same rvm gemset which is gemset1, if you run the second app app2 the gem will be available in the second application as well
Whereas with the plugin it will not be the case because plugins get installed on application level and not at the system level

How can my Rails app accept RAILS_GEM_VERSION minor version bumps

My rails project has this line in /config/environment.rb
# Specifies gem version of Rails to use when vendor/rails is not present
RAILS_GEM_VERSION = '2.3.2' unless defined? RAILS_GEM_VERSION
As we now have 2.3.5 as the most recent upgrade, is there a way to make my environment.rb accept minor version bumps?
(without I have to explicitly change 2.3.2 to 2.3.5)
No, there isn't.
You application needs to use a specific Rails version mostly because different tiny releases might require additional steps to upgrade the framework such as changes to boot.rb.
$ rake rails:update
Things have evolved a bit since Rails 2, so Ill share what I had to do to get from 5.0.0 to 5.0.0.1 today.
My Gemfile read gem 'rails', '~> 5.0.0'. I figured that was enough, but bundle install was not updating anything new. So I tried to force it with gem 'rails', '~> 5.0' which also did nothing new when I ran update (note: this is for an experimental app of my own, and not someone else's app I am working on - don't just default to allowing minor version updates to solve problems like this ;) ). So I had to try a few other ways to force this security patch/hotfix.
First, I had to install the package locally:
gem install rails --version 5.0.0.1
Next, I updated bundler:
bundle install
...and I saw this in the output: Using rails 5.0.0.1 (was 5.0.0)
When I ran ./bin/rake rails:update, it wiped the contents of my config/routes.rb file, changed many of my settings in various config files (some of which were dangerous security settings to change), among a few other seemingly benign changes. While this is the expected behavior, I am pointing this out as not exactly a desirable method for updating a minor patch/hotfix for rails.
Firstly, you need to change the version to 2.3.5 from 2.3.5 and then run
rake rails:update

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.

Resources