我正在设置一个基本模板,用于在Rails应用程序中进行水豚功能测试。我也在使用MiniTest而不是RSPEC。
运行Rake Test似乎并没有促进我的功能测试。我在文件中有一个测试,运行rake test不会更改断言的数量。运行rake测试时,也不会显示跳过测试。
这是存储库的链接:https : //github.com/rrgayhart/rails_template
这是我遵循的步骤
我将此添加到Gemfile并运行了捆绑包
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 test
任务不会在默认测试目录中不进行测试。因此,您需要移动测试文件或添加新的rake任务来测试中的文件test/features
。
由于您使用的是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', :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
或者,您可以使用minitest-rails和minitest-rails-capybara生成并运行这些测试。
$ rails generate mini_test:feature DrinkCreation
$ rake minitest:features
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句