您的位置:首页 > 大数据 > 人工智能

Rails中的测试RSpec升级遇到的问题

2014-08-29 18:22 399 查看
bundle exec rspec spec/
/home/wuxj/Prac/rrprac/sample_app/spec/spec_helper.rb:20:in `block in <top (required)>': uninitialized constant Capybara (NameError)
from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core.rb:79:in `configure'
from /sample_app/spec/spec_helper.rb:17:in `<top (required)>'
from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core/configuration.rb:1025:in `require'
from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core/configuration.rb:1025:in `block in requires='
from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core/configuration.rb:1025:in `each'
from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core/configuration.rb:1025:in `requires='
from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core/configuration_options.rb:101:in `block in process_options_into'
from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core/configuration_options.rb:100:in `each'
from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core/configuration_options.rb:100:in `process_options_into'
from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core/configuration_options.rb:22:in `configure'
from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:96:in `setup'
from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:85:in `run'
from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:70:in `run'
from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:38:in `invoke'
from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/exe/rspec:4:in `<top (required)>'
from /.rvm/gems/ruby-2.1.2/bin/rspec:23:in `load'
from /.rvm/gems/ruby-2.1.2/bin/rspec:23:in `<main>'
from /.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `eval'
from /.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `<main>'
wuxj@P-D5-wuxj:~/Prac/rrprac/sample_app$ bundle exec rspec spec/
/Prac/rrprac/sample_app/spec/spec_helper.rb:20:in `block in <top (required)>': uninitialized constant Capybara (NameError)
from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core.rb:79:in `configure'
from /Prac/rrprac/sample_app/spec/spec_helper.rb:17:in `<top (required)>'
from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core/configuration.rb:1025:in `require'
from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core/configuration.rb:1025:in `block in requires='
from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core/configuration.rb:1025:in `each'
from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core/configuration.rb:1025:in `requires='
from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core/configuration_options.rb:101:in `block in process_options_into'
from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core/configuration_options.rb:100:in `each'
from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core/configuration_options.rb:100:in `process_options_into'
from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core/configuration_options.rb:22:in `configure'
from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:96:in `setup'
from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:85:in `run'
from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:70:in `run'
from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:38:in `invoke'
from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/exe/rspec:4:in `<top (required)>'
from /.rvm/gems/ruby-2.1.2/bin/rspec:23:in `load'
from /.rvm/gems/ruby-2.1.2/bin/rspec:23:in `<main>'
from /.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `eval'
from /.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `<main>'


查来查去都是什么乱说一通,改这地方改那地方,我了个去的,太不靠谱了,后来综合各个老外的说法,思考了下然后试着去改,老天真照顾我,好用了。哈哈~~~

首先查到的是Capybara不在rspec中,所以要添加进去,但是添加的是spec_helper.rb文件中

config.include Capybara::DSL

结果:依然没解决。

其次,因为版本升级,现在rspec已经分为两块,一个spec_helper.rb和一个rails_helper.rb
从生成的测试文件看

require 'rails_helper'

RSpec.describe "StaticPages", :type => :request do
# describe "GET /static_pages" do
#   it "works! (now write some real specs)" do
#     get static_pages_index_path
#     expect(response.status).to be(200)
#   end
# end

describe "Home page" do
it "should have the content 'Sample App'" do
visit '/static_pages/home'
expect(page).to have_content('Sample App')
end
end
end


引用的是rails_helper,所以我试着把这个东西移到rails_helper中,问题解决。

其他小问题一大堆。。。头疼,下班。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: