首页 > 代码库 > Rails中的测试RSpec升级遇到的问题

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

 1 bundle exec rspec spec/ 2 /home/wuxj/Prac/rrprac/sample_app/spec/spec_helper.rb:20:in `block in <top (required)>: uninitialized constant Capybara (NameError) 3     from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core.rb:79:in `configure 4     from /sample_app/spec/spec_helper.rb:17:in `<top (required)> 5     from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core/configuration.rb:1025:in `require 6     from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core/configuration.rb:1025:in `block in requires= 7     from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core/configuration.rb:1025:in `each 8     from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core/configuration.rb:1025:in `requires= 9     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_into10     from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core/configuration_options.rb:100:in `each11     from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core/configuration_options.rb:100:in `process_options_into12     from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core/configuration_options.rb:22:in `configure13     from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:96:in `setup14     from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:85:in `run15     from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:70:in `run16     from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:38:in `invoke17     from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/exe/rspec:4:in `<top (required)>18     from /.rvm/gems/ruby-2.1.2/bin/rspec:23:in `load19     from /.rvm/gems/ruby-2.1.2/bin/rspec:23:in `<main>20     from /.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `eval21     from /.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `<main>22 wuxj@P-D5-wuxj:~/Prac/rrprac/sample_app$ bundle exec rspec spec/23 /Prac/rrprac/sample_app/spec/spec_helper.rb:20:in `block in <top (required)>: uninitialized constant Capybara (NameError)24     from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core.rb:79:in `configure25     from /Prac/rrprac/sample_app/spec/spec_helper.rb:17:in `<top (required)>26     from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core/configuration.rb:1025:in `require27     from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core/configuration.rb:1025:in `block in requires=28     from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core/configuration.rb:1025:in `each29     from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core/configuration.rb:1025:in `requires=30     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_into31     from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core/configuration_options.rb:100:in `each32     from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core/configuration_options.rb:100:in `process_options_into33     from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core/configuration_options.rb:22:in `configure34     from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:96:in `setup35     from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:85:in `run36     from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:70:in `run37     from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:38:in `invoke38     from /.rvm/gems/ruby-2.1.2/gems/rspec-core-3.0.4/exe/rspec:4:in `<top (required)>39     from /.rvm/gems/ruby-2.1.2/bin/rspec:23:in `load40     from /.rvm/gems/ruby-2.1.2/bin/rspec:23:in `<main>41     from /.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `eval42     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
从生成的测试文件看

 1 require rails_helper 2  3 RSpec.describe "StaticPages", :type => :request do 4   # describe "GET /static_pages" do 5   #   it "works! (now write some real specs)" do 6   #     get static_pages_index_path 7   #     expect(response.status).to be(200) 8   #   end 9   # end10 11   describe "Home page" do12       it "should have the content ‘Sample App‘" do13           visit /static_pages/home14           expect(page).to have_content(Sample App)15       end16   end17 end

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

其他小问题一大堆。。。头疼,下班。

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