Fix for “`require’: cannot load such file” Error

Ruby on Rails logo

While working through Chapter 3 of the RailsTutorial for Rails 4.0, I encountered an error when running the first integration test using RSpec.

Upon running the command:

bundle exec rspec spec/requests/static_pages_spec.rb


for the first time, I got the following error:

/Users/davidyoung/.rvm/gems/ruby-2.0.0-p451@railstutorial_rails_4_0/gems/selenium-webdriver-2.0.0/lib/selenium/webdriver/common/zipper.rb:1:in `require': cannot load such file -- zip/zip (LoadError)
	from /Users/davidyoung/.rvm/gems/ruby-2.0.0-p451@railstutorial_rails_4_0/gems/selenium-webdriver-2.0.0/lib/selenium/webdriver/common/zipper.rb:1:in `<top (required)>'
	from /Users/davidyoung/.rvm/gems/ruby-2.0.0-p451@railstutorial_rails_4_0/gems/selenium-webdriver-2.0.0/lib/selenium/webdriver/common.rb:9:in `require'
.
.
.

It appears this is caused by a bug in version 2.0.0 of the ‘selenium-webdriver’ gem. If you change the Gemfile line to use a newer version, this error goes away.

Gemfile:

source 'https://rubygems.org'
ruby '2.0.0'
#ruby-gemset=railstutorial_rails_4_0

gem 'rails', '4.0.0'

group :development, :test do
	gem 'sqlite3', '1.3.7'
	gem 'rspec-rails', '2.13.1'
end

group :test do
	gem 'selenium-webdriver', '~> 2.35.1'
	gem 'capybara', '2.1.0'
end

gem 'sass-rails', '~> 4.0.0'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails', '2.2.1'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'

group :doc do
  gem 'sdoc', '0.3.20', require: false
end 

group :production do
	gem 'pg', '0.15.1'
	gem 'rails_12factor', '0.0.2'
end

Now when the command is run, I get the proper output:

F

Failures:

  1) Static pages Home page should have the content 'Sample App'
     Failure/Error: expect(page).to have_content('Sample App')
       expected #has_content?("Sample App") to return true, got false
     # ./spec/requests/static_pages_spec.rb:7:in `block (3 levels) in <top (required)>'

Finished in 0.86025 seconds
1 example, 1 failure

Failed examples:

rspec ./spec/requests/static_pages_spec.rb:5 # Static pages Home page should have the content 'Sample App'

Randomized with seed 48261

Michael Hartl’s Ruby on Rails 4.0 Tutorial

Ruby on Rails logo

Ruby on Rails, even eight years after its first release, is still recognized as one of the best frameworks for Web applications for many reasons, not the least of which are its cost (it’s free) and its scalability (sites as big as Twitter have used it).

Rails 4.0 was released last year, and soon after, Michael Hartl updated his famous Rails Tutorial.

For those wanting to learn RoR, the Rails Tutorial is (in my opinion) the best way to do it.

I’ve just begun working through the latest release of the tutorial, and have so far been pleased with the small number of typos and various errata that are common in technical instruction manuals.

One error I encountered with the default gemfile configuration file provided in the Rails Tutorial had to do with the versions of sass-rails and coffee-rails. The Tutorial suggests that you use (exactly) version ‘4.0.0’ for both of these gems, but I got an error like this:

Bundler could not find compatible versions for gem "railties":
  In Gemfile:
    rails (= 4.0.0) ruby depends on
      railties (= 4.0.0) ruby

    sass-rails (= 4.0.0) ruby depends on
      railties (4.1.0.rc1)

I set both of these gems to ‘~> 4.0.0’, and both bundle update and bundle install worked fine. My gemfile is below:

source 'https://rubygems.org'
ruby '2.0.0'
#ruby-gemset=railstutorial_rails_4_0

gem 'rails', '4.0.0'

group :development do
	gem 'sqlite3', '1.3.7'
end

group :production do
	gem 'pg', '0.15.1'
	gem 'rails_12factor', '0.0.2'
end

gem 'sass-rails', '~>; 4.0.0'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '~>; 4.0.0'
gem 'jquery-rails', '2.2.1'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'

group :doc do
  gem 'sdoc', '0.3.20', require: false
end

One Year of Blogging at “Deep In The Code”!

cupcake with one year candle

I’ve been writing this blog for just over a year now; my first post was on May 23, 2012. I haven’t written as many articles as I would have liked over the last year, I think due to the fact that I’ve been too selective in what I wrote about (for fear of moving the blog off-topic) and some of the articles have been too long. I will endeavor to write shorter, but more frequent articles for the second year of this blog!

I enjoy the feedback I get (when it’s not spam) as it tells me if I’m writing about something that people care about, so please continue writing back!

My goals from last year never fully materialized, as I intended to learn OS X / iOS / Objective-C programming when I bought my MacBook Pro last year. While I did dip into the pool of Xcode programming, it was only a shallow dip. Instead, I have focused more on learning open source technologies – mostly Python and Ruby on Rails. Once I get a handle on these two, I intend to revisit iOS programming – though I may end up using RubyMotion instead of Objective-C. Only time will tell!

Thanks for reading my blog, and please feel free to make suggestions on what you would like to read about in the future!