I've been attempting to make a start on learning Ruby/rspec. I read that rspec is now broken for Windows so an early version (2.14.1) should be installed instead. I started on testfirst's learn Ruby but kept getting errors whenever I attempted the "rake" task. I checked my rspec version and apparently I'm running 2.14.8. I thought maybe that was why I was getting some errors. So I typed into git "gem uninstall rspec" but it then said version 2.14.1 was uninstalled, not .8. So I checked to see if there were any versions of rspec installed on my computer and it says that 2.14.8 is still installed... now it won't let me uninstall it, even though I typed in "gem uninstall rspec -v 2.14.8."
I also tried to check the contents of version 2.14.8, but it couldn't find gem 'rspec' in default gem paths.
It's as if I had two versions of rpec on my laptop... how do I get rid of the .8 version?
If gem uninstall rspec -v 2.14.8 did not work for you. Try cleaning up all the rspec version from your computer first by running:
gem cleanup rspec
Then, install the required version again.
Update:
Try:
gem uninstall -Iax rspec
If doesn't work, then try and remove the executables as well:
gem uninstall rspec-core
Where did you hear that RSpec is broken on Windows? AFAIK the current version (3.3.2) works just fine.
If you are going to learn Ruby and RSpec, you should also learn about using Rubygems and Bundler, since many projects rely on them. Install Bundler with:
gem install bundler
Create a new folder and CD into it, and then:
bundle init
This creates a file named "Gemfile" in the folder. This allows Bundler to manage the versions of gems used within your project. Edit the Gemfile and add this line:
gem 'rspec', '~> 3'
This tells Bundler that your project requires RSpec 3, and to install the latest version. Save the Gemfile, and then do:
bundle install
Bundler will install the RSpec gems and create a Gemfile.lock file that details the gem dependencies. To verify that the right version is installed:
rspec --version # => 3.3.2 (or whatever is the latest)
Related
I have a new Mac computer and installed rails on it, and then I tried out the command
gem outdated
for some reason, it showed one of the gems outdated:
webrick (1.4.2 < 1.6.0)
I wonder why it is outdated on the first installed, and when I did
sudo gem install webrick
it actually installed 1.6.0 onto the system. Doesn't it require gem update instead of install to update something? How come install also updated it?
Not exactly, gem install GEM_NAME will install the last version available if you don't specify a version when installing, and you can have more than 1 version of the same gem on your machine.
you can run gem environment, and check where gems are installed, go to that folder and you will see both version gems folder there.
so when you create a rails project for example and add a specific version of a gem in the gemfile and another version on another project, you can have both without problems
I want to get a Gem's version without running bundle install.
Which is to say I want figure out what version bundle is planning to install without actually installing the gem.
Say read it from the Gemfile.lock(and Gemfile) combined.
Is there a way I can resolve what version bundler plans to install?
I need this because I want to cache the expensive installs while running docker build.
Gems like rails(nokogiri) take a while to install and I would like to do gem install rails -v ... in a previous step before running bundle install.
For this purpose i need to get the rails version before hand
If you add a new gem to your gemfile, but don't do bundle install, it doesn't install yet. Instead, you can run bundle lock, which generates a new lock file. This includes the gem version of the new gem that would be installed.
By running bundle show new_gem, it shows it isn't actually installed.
To be sure maybe get a backup of the original Gemfile.lock before running the command though.
By default if no version is specified in the Gemfile, running bundle install will attempt to install the latest version of the gem which is compatible with the rest of the gems and ruby version in your project. This will create a Gemfile.lock file if one doesn't already exist. If a Gemfile.lock file is already committed to git repo, it should then install the versions specified in Gemfile.lock. The point of bundler is to handle dependencies to insure your stack works correctly.
To see the version of a gem bundler is currently using you can run
bundle show rails
You will probably want to specify the ruby version in the Gemfile for example
ruby '~> 2.5' #
You can specify exact version of a gem in the Gemfile like this which you should be able to rely on to be the version bundler will install so long as it's compatible with the rest of the stack. bundle install will throw errors if there are incompatible gem versions.
gem 'rails', '4.2.11' # this will always install only this version.
You may also use pessimistic operator (~>) to set for only minor updates
gem 'influxdb', '~> 0.6.1' # could go to 0.6.2 but never 0.7.0
You can also set minimum versions like this although it's probably not what you need for your question.
gem 'pg_query', '>= 0.9.0'
If you have a Gemfile.lock already in your repo you can see which version would be installed by running for example:
gem show rails
Which would show you the version and weather it or not it is currently installed.
For more info see bundle --help
Got an error after typing "bundle install" with some sort of issue with the Ruby version. Have been installed many-many gems so far and never got incompabilities with the Ruby version.
What's the best way to upgrade the Ruby version to get back on track with the "bundle install" without putting the app at "risk"?
Here it is what I have done:
1st - Added the twitter omniauth gem to my gemfile.
2nd - Created a omniauth.rb file in the app/config/initializers folder.
3rd - Typed the "bundle install" command and got the following error: "omniauth requires Ruby version >= 2.1.9."
Dependencies can specify a required_ruby_version in their .gemspec file. In this case, one of your sub-dependencies (omniauth - a sub-dependency of omniauth-oauth, which is in turn a sub-dependency of omniauth-twitter) has had such a requirement since v1.5.0.
To get a working install, you've got two options:
Pin to an older version of omniauth, by adding gem "omniauth", "~> 1.4.2" to your Gemfile. This will ensure Bundler uses an older version of omniauth. However, that may cause conflicts with other gems, leaving you with the same problem - indeed, it's probably the reason Bundler didn't automatically try to install an older version.
Update your Ruby version. If you have a .ruby-version file in your application, update the version there to 2.1.9. Similarly if your Gemfile has a ruby "..." line in it, update that too. You'll probably also need to install the new version of Ruby locally - with rbenv you can use $ rbenv install 2.1.9, or if you use RVM try $rvm install 2.1.9.
My recommendation would be option 2 (updating your Ruby version).
I'm using the thumbs_up gem and on github there's a master branch (0.4.6) and an engine branch (0.3.2). When I require the gem in my Gemfile with
gem 'thumbs_up'
I see that version 0.4.6 was installed. I verify this is the right version running in my dev environment by doing bundle exec gem which thumbs_up and when I look at the VERSION file I see it's 0.4.6.
So when I look at the code I'm expecting to find an unvote_for method but it doesn't have one. Instead it has one called clear_votes. Now I'm confused because clear_votes is supposed to be in version 0.3.2 but as far as I can tell, I'm on version 0.4.6.
Any ideas what's going on here?
By default, the gem used is the latest available when running 'bundle install'. You can specify a version (or version constraints) in the Gemfile. To update the version of the gem used, you have to run bundle update <gemname>, and it will do so according to your gemfile.
About your problem : ensure that your server/console command is prefixed with bundle exec. You check also which versions of thumbs_up are installer on your system, and remove the version you don't need anymore.
You use Bundler so you can know which version of you gem is using in your Gemfile.lock. Bundler have and use only one version by gem.
I'm very new to Rails (and Ruby), and am having trouble installing and using gems. I'm trying to use ruby-tmdb (https://github.com/aarongough/ruby-tmdb) and there's very little documentation.
"sudo gem install ruby-tmdb" runs just fine and I can see the gem installed when I run "gem list --local"
But, when I try and run the app, I get the error "no such file to load -- ruby-tmdb".
I'm on Mac OS X Snow Leopard. Ruby 1.8.7. Rails 3.0.3. Gem 1.3.7.
Is the gem listed in your Gemfile? In Rails 3, all gem dependencies should be listed in the Gemfile, so that it is properly loaded when the app runs.
You should have something like the following line:
gem 'ruby-tmdb'
Then, run bundle install to ensure that all gem dependencies are installed, and to have Bundler save the lock file that will ensure that all copies of this application run with the same gem versions. From this point on, you will no longer have to write the require line yourself; Rails will load in all necessary gems as the environment loads.
You might get the same error even after this, but it's always worth going through the standard process to help narrow things down :)
$ sudo which gem
$ which gem
$ sudo ruby -v
$ ruby -v
Sometimes users have different gems and rubys compared to root.
A common problem is that a gem installed for ruby 1.8 by root isn't visible for the users ruby 1.9
gems for ruby 1.8 and gems for 1.9 are NOT compatible.
This probably isn't the issue but is something that may be worth considering.