耙子测试没有在最小的时候进行水豚测试

cca*_*duc 4 ruby-on-rails minitest capybara

我正在设置一个基本模板,用于在rails应用程序中进行水豚功能测试.我也使用MiniTest而不是RSPEC.

运行Rake测试似乎没有进行我的功能测试.我在文件中有一个测试,运行rake测试不会改变断言的数量.当我运行rake测试时,跳过测试也不会显示.

以下是存储库的链接:https://github.com/rrgayhart/rails_template

以下是我遵循的步骤

  1. 我将它添加到Gemfile并运行bundle

    group :development, :test do
      gem 'capybara'
      gem 'capybara_minitest_spec'
      gem 'launchy'
    end
    
    Run Code Online (Sandbox Code Playgroud)
  2. 我将其添加到test_helper中

    require 'capybara/rails'
    
    Run Code Online (Sandbox Code Playgroud)
  3. 我创建了一个文件夹测试/功能

  4. 我创建了一个名为drink_creation_test.rb的文件

  5. 以下是该功能测试文件的代码

    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
    
    Run Code Online (Sandbox Code Playgroud)

我想我没有正确连接的问题.如果我还能提供其他任何可能有助于诊断此问题的信息,请告知我们.

blo*_*age 5

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

由于您使用的是capybara_minitest_spec,因此需要包含Capybara::DSLCapybara::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
Run Code Online (Sandbox Code Playgroud)

或者,您可以使用minitest-railsminitest-rails-capybara生成运行这些测试.

$ rails generate mini_test:feature DrinkCreation
$ rake minitest:features
Run Code Online (Sandbox Code Playgroud)