1
votes

I am new to Rails development. I am following Michael Hartl's video tutorials. However I am not able to run the tests using Capybara/RSpec. I am getting some errors. My setup is as follows:

I am using Ruby 2.0.0p353. Rails - 4.1.1 and RSpec - 3.0.1 Capybara - 2.3.0

Below is my GemFile.

source 'https://rubygems.org'


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
ruby '2.0.0'
gem 'rails', '4.1.1'
gem 'bootstrap-sass'
gem 'bcrypt'
gem 'faker'
gem 'will_paginate'
gem 'bootstrap-will_paginate'
gem 'rails_12factor'

# Use sqlite3 as the database for Active Record
group :development, :test do
   gem 'sqlite3'
   gem 'rspec-rails'
   gem 'guard-rspec'
   gem 'guard-spork'
   gem 'childprocess'
   gem 'spork'
end

#Gems used only for assets and not used in production enviornment by default
group :assets do
   # Use SCSS for stylesheets
   gem 'sass-rails', '~> 4.0.3'
   # Use Uglifier as compressor for JavaScript assets
   gem 'uglifier', '>= 1.3.0'
   # Use CoffeeScript for .js.coffee assets and views
   gem 'coffee-rails', '~> 4.0.0'
end


group :test do
   gem 'capybara'
   gem 'factory_girl_rails'
   gem 'cucumber-rails'
   gem 'database_cleaner'
   #gem 'launchy'
   #gem 'rb-fsevent'
   #gem 'growl'
end

group :production do
   gem 'pg'
end


# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer',  platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0',          group: :doc

# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring',        group: :development

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

# Use debugger
# gem 'debugger', group: [:development, :test]

Below is my spec/spec_helper.rb:

    require 'capybara/rspec'

    RSpec.configure do |config|

       config.include Capybara::DSL
    end

And, here is my spec. test - spec/features/static_pages_spec.rb

    require 'spec_helper'

describe "Static pages" do

   describe "Home page" do


      it "should have the content  'Sample App'" do

     visit '/static_pages/home'
     page.should have_content('Sample App')
      end

   end

end

If I run the command rspec/featues/static_pages_spec.rb I get a long stack trace. It shows two main issues:

/usr/local/share/ruby/site_ruby/rubygems/core_ext/kernel_require.rb:73:
warning: loading in progress, **circular require considered harmful - 

/home/MAC/.gem/ruby/gems/capybara-2.3.0/lib/capybara.rb**

and

  An error occurred in an after hook
    **ArgumentError: rack-test requires a rack application, but none was given**
    occurred at /home/MAC/.gem/ruby/gems/capybara-2.3.0/lib/capybara/rack_test/driver.rb:16:in `initialize'

F

Failures:

  1) Static pages Home page should have the content  'Sample App'
     Failure/Error: visit '/static_pages/home'
     ArgumentError:
       **rack-test requires a rack application, but none was given**
     # ./spec/features/static_pages_spec.rb:10:in `block (3 levels) in <top (required)>'

Finished in 0.00062 seconds (files took 0.58874 seconds to load)
1 example, 1 failure

Failed examples:

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

I have tried googling for this issue. It seems Capybara 2.3.0 and RSpec 3.0.1 do not play nicely. However I haven't found any solution which solves the issue. Has anyone encountered and solved such an issue? Please let me know. Thanks in advance.

1
Try require 'rspec/rails' in spec_helper.rb.Dave Schweisguth

1 Answers

0
votes

rspec-rails 3 no longer defaults to setting the spec type based on the location, so your spec isn't being setup as a feature spec

You can either tag the feature specs individually or add

config.infer_spec_type_from_file_location!

To your spec helper to restore the old behaviour