ruby-on-rails – 耙子测试没有在最小的时候进行水豚测试
我正在设置一个基本模板,用于在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' >我创建了一个文件夹测试/功能 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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- plproxy 安装日记
- ARM DS-5 Flex网络许可证编译错误“Error: C9933W: Waiting
- ruby-on-rails – 表之间的Rails .joins()和.where()条件
- MSP430F2272 Flash
- 使用alter system set修改参数不生效
- 基于vue-cli创建的项目的目录结构及说明介绍
- 关于IAR的一些总结 -- Flash Loader原理
- React学习之扩展不变的数据(immutability-helper)优化(三
- Cocos2d-html5之TintTo&TintBy
- cocos2d-x 3.3 CC_CALLBACK_0 std::bind与std::function