Ruby on rails Rake测试未在minitest中拾取水豚测试
我正在为rails应用程序中的capybara特性测试设置一个基本模板。我还使用MiniTest而不是RSPEC 运行Rake测试似乎并没有获得我的特性测试。我在文件中有一个测试,运行rake测试不会改变断言的数量。当我运行rake测试时,跳过测试也不会出现 以下是指向存储库的链接: 以下是我遵循的步骤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
group :development, :test do
gem 'capybara'
gem 'capybara_minitest_spec'
gem 'launchy'
end
require 'capybara/rails'
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