Capybara不使用迷你测试和导轨。继续"未初始化的恒定Capybara :: Minitest :: Capybara"

时间:2017-11-28 20:37:07

标签: ruby-on-rails ruby testing capybara minitest

我知道这通常意味着通过要求缺少某些东西,但我无法弄明白。这是我的test_helper.rb:

ENV["RAILS_ENV"] = "test"
require File.expand_path("../../config/environment", __FILE__)
require "rails/test_help"
require "minitest/rails"
require 'capybara/rails'
require 'capybara/minitest'

# To add Capybara feature tests add `gem "minitest-rails-capybara"`
# to the test group in the Gemfile and uncomment the following:

require 'minitest/rails/capybara'

和我Gemfile.lock的一部分

minitest-capybara (0.8.2)
  capybara (~> 2.2)
  minitest (~> 5.0)
  rake
minitest-metadata (0.6.0)
  minitest (>= 4.7, < 6.0)
minitest-rails (3.0.0)
  minitest (~> 5.8)
  railties (~> 5.0)
minitest-rails-capybara (3.0.1)
  capybara (~> 2.7)
  minitest-capybara (~> 0.8)
  minitest-metadata (~> 0.6)
  minitest-rails (~> 3.0)

如果我注释掉这一行:

require 'minitest/rails/capybara'

我明白了:

undefined method `feature' for main:Object (NoMethodError)

尝试测试功能时。

有人有什么想法吗?

演出的完整追踪:

ruby test/features/can_access_home_test.rb
/usr/local/bundle/gems/minitest-capybara-0.8.2/lib/capybara/assertions.rb:37:in `<module:Assertions>': uninitialized constant Capybara::Minitest::Capybara (NameError)
    from /usr/local/bundle/gems/minitest-capybara-0.8.2/lib/capybara/assertions.rb:2:in `<module:Capybara>'
    from /usr/local/bundle/gems/minitest-capybara-0.8.2/lib/capybara/assertions.rb:1:in `<top (required)>'
    from /usr/local/bundle/gems/minitest-capybara-0.8.2/lib/minitest/capybara.rb:23:in `<top (required)>'
    from /usr/local/bundle/gems/minitest-capybara-0.8.2/lib/minitest-capybara.rb:2:in `<top (required)>'
    from /usr/local/bundle/gems/minitest-rails-capybara-3.0.1/lib/minitest/rails/capybara.rb:3:in `<top (required)>'
    from /usr/src/app/test/test_helper.rb:11:in `<top (required)>'
    from test/features/can_access_home_test.rb:1:in `require_relative'
    from test/features/can_access_home_test.rb:1:in `<main>'

1 个答案:

答案 0 :(得分:0)

尝试从test_helper.rb中取出这些行:

require "minitest/rails"
require 'capybara/rails'
require 'capybara/minitest'