加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 耙子测试没有在最小的时候进行水豚测试

发布时间:2020-12-17 02:46:22 所属栏目:百科 来源:网络整理
导读:我正在设置一个基本模板,用于在rails应用程序中进行水豚功能测试.我也使用MiniTest而不是RSPEC. 运行Rake测试似乎没有进行我的功能测试.我在文件中有一个测试,运行rake测试不会改变断言的数量.当我运行rake测试时,跳过测试也不会显示. 这是存储库的链接:htt
我正在设置一个基本模板,用于在rails应用程序中进行水豚功能测试.我也使用MiniTest而不是RSPEC.

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

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

以下是我遵循的步骤

>我将此添加到Gemfile并运行bundle

group :development,:test do
  gem 'capybara'
  gem 'capybara_minitest_spec'
  gem 'launchy'
end

>我将此添加到test_helper

require 'capybara/rails'

>我创建了一个文件夹测试/功能
>我创建了一个名为drink_creation_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

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

解决方法

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

由于您使用的是capybara_minitest_spec,因此您需要将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',text: "This is a great beer")
      end
  end

end

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

$rails generate mini_test:feature DrinkCreation
$rake minitest:features

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读