Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rake测试未在minitest中拾取水豚测试_Ruby On Rails_Capybara_Minitest - Fatal编程技术网

Ruby on rails Rake测试未在minitest中拾取水豚测试

Ruby on rails Rake测试未在minitest中拾取水豚测试,ruby-on-rails,capybara,minitest,Ruby On Rails,Capybara,Minitest,我正在为rails应用程序中的capybara特性测试设置一个基本模板。我还使用MiniTest而不是RSPEC 运行Rake测试似乎并没有获得我的特性测试。我在文件中有一个测试,运行rake测试不会改变断言的数量。当我运行rake测试时,跳过测试也不会出现 以下是指向存储库的链接: 以下是我遵循的步骤 我将其添加到Gemfile并运行bundle group :development, :test do gem 'capybara' gem 'capybara_minitest_spe

我正在为rails应用程序中的capybara特性测试设置一个基本模板。我还使用MiniTest而不是RSPEC

运行Rake测试似乎并没有获得我的特性测试。我在文件中有一个测试,运行rake测试不会改变断言的数量。当我运行rake测试时,跳过测试也不会出现

以下是指向存储库的链接:

以下是我遵循的步骤

  • 我将其添加到Gemfile并运行bundle

    group :development, :test do
      gem 'capybara'
      gem 'capybara_minitest_spec'
      gem 'launchy'
    end
    
  • 我将此添加到test_助手

    require 'capybara/rails'
    
  • 我创建了一个测试/功能文件夹

  • 我创建了一个名为drink\u creation\u test.rb的文件

  • 下面是该特性测试文件中的代码

    require 'test_helper'
    
    class DrinkCreationTest < MiniTest::Unit::TestCase
    
      def test_it_creates_an_drink_with_a_title_and_body
          visit drinks_path
          click_on 'new-drink'
          fill_in 'name', :with => "PBR"
          fill_in 'description', :with => "This is a great beer."
          fill_in 'price', :with => 7.99
          fill_in 'category_id', :with => 1
          click_on 'save-drink'
          within('#title') do
            assert page.has_content?("PBR")
          end
          within('#description') do
            assert page.has_content?("td", text: "This is a great beer")
          end
      end
    
    end
    
    需要“测试助手”
    类DrinkCreationTest“PBR”
    在“描述”中填写:with=>“这是一种很棒的啤酒。”
    在“价格”中填写:=>7.99
    在“类别id”中填写:=>1
    单击“保存饮料”
    在(“#标题”)内做
    断言页面是否有内容?(“PBR”)
    结束
    在(“#描述”)中做什么
    断言页面。是否有内容?(“td”,文本:“这是一瓶很棒的啤酒”)
    结束
    结束
    结束
    
  • 我想我有一个问题,没有正确连接的东西。
    请让我知道我是否可以提供任何其他帮助来诊断此问题。

    我相信minitest在使用capybara时有自己的rails宝石:


    按照那边的说明可能会有所帮助,但我以前从未使用mini-test设置过水豚。

    这里发生了很多事情。首先,默认的
    rake test
    任务不会拾取不在默认测试目录中的测试。因此,您需要在
    test/features
    中移动测试文件或添加新的rake任务来测试文件

    由于您正在使用,您需要在测试中包括
    Capybara::DSL
    Capybara::RSpecMatchers
    。而且,由于在该测试中没有使用
    ActiveSupport::TestCase
    或其他Rails测试类,您可能会在数据库中看到不一致,因为该测试是在标准Rails测试事务之外执行的

    require 'test_helper'
    
    class DrinkCreationTest < MiniTest::Unit::TestCase
      include Capybara::DSL
      include Capybara::RSpecMatchers
    
      def test_it_creates_an_drink_with_a_title_and_body
          visit drinks_path
          click_on 'new-drink'
          fill_in 'name', :with => "PBR"
          fill_in 'description', :with => "This is a great beer."
          fill_in 'price', :with => 7.99
          fill_in 'category_id', :with => 1
          click_on 'save-drink'
          within('#title') do
            assert page.has_content?("PBR")
          end
          within('#description') do
            assert page.has_content?("td", text: "This is a great beer")
          end
      end
    
    end
    

    杰出的这是一个完美的答案——如果我们将测试转移到集成(这与您的rake任务评论有关),我们就能够获得测试——但最终转移到移动特定于minitest的gem。再次感谢你!
    $ rails generate mini_test:feature DrinkCreation
    $ rake minitest:features