繁体   English   中英

在Rails 4.1中将RSpec 3.0与Capybara 2.3一起使用时,为什么会出现错误?

[英]Why am I getting an error while using RSpec 3.0 with Capybara 2.3 in Rails 4.1?

我是Rails开发的新手。 我正在关注Michael Hartl的视频教程。 但是,我无法使用Capybara / RSpec运行测试。 我遇到一些错误。 我的设置如下:

我正在使用Ruby 2.0.0p353。 Rails-4.1.1和RSpec-3.0.1 Capybara-2.3.0

以下是我的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]

以下是我的spec / spec_helper.rb:

    require 'capybara/rspec'

    RSpec.configure do |config|

       config.include Capybara::DSL
    end

而且,这是我的规格。 测试-规格/功能/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

如果我运行命令rspec / featues / static_pages_spec.rb,则会得到很长的堆栈跟踪。 它显示了两个主要问题:

/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**

  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'

我已经尝试使用Google搜索这个问题。 似乎Capybara 2.3.0和RSpec 3.0.1不能很好地播放。 但是我还没有找到解决问题的解决方案。 有没有人遇到并解决过这样的问题? 请告诉我。 提前致谢。

rspec-rails 3不再默认根据位置设置规范类型,因此不会将您的规范设置为功能规范

您可以单独标记功能规格,也可以添加

config.infer_spec_type_from_file_location!

给您的规范助手以恢复旧的行为

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM