草庐IT

minitest_helper

全部标签

ruby - MiniTest 的 assert_in_delta 和 assert_in_epsilon 方法有什么区别?

这里是documentationforassert_in_delta:assert_in_delta(exp,act,delta=0.001,msg=nil)publicForcomparingFloats.Failsunlessexpandactarewithindeltaofeachother.assert_in_deltaMath::PI,(22.0/7.0),0.01这里是documentationforassert_in_epsilonassert_in_epsilon(a,b,epsilon=0.001,msg=nil)publicForcomparingFloats.Fa

ruby - Minitest 规范自定义匹配器

我的测试中有一行:page.has_reply?("myreply").must_equaltrue为了使其更具可读性,我想使用自定义匹配器:page.must_have_reply"myreply"基于https://github.com/zenspider/minitest-matchers的文档我希望我需要编写一个看起来像这样的匹配器:defhave_reply(text)subject.has_css?('.comment_body',:text=>text)endMiniTest::Unit::TestCase.register_matcher:have_reply,:hav

ruby - stub 实例方法在使用 minitest 的第二次调用时返回值不同

我正在对用户的提要进行分页,并想模拟我正在使用的API的响应。API可以返回奇怪的结果,所以我想确保如果API返回我已经看到的项目,请停止分页。我使用minitest在第一次调用方法get_next_page时stub,但我想在第二次和第三次用不同的值调用它时stub。我应该只使用rSpec吗?ruby新手...这是片段test"crawlerdoesnotpaginateifnonewitemsinnextpage"do#1:A,B#2:B,D=>D#3:A=>stopcrawler=CrawlJob.newfirst_page=[{"id"=>"item-A"},{"id"=>"i

ruby - 如何在 MiniTest 中的所有测试中的每个测试用例之前运行代码?

我需要在MiniTest中的所有测试中的每个测试之前运行代码。在我做之前:MiniTest::Unit::TestCase.add_setup_hookdo...codetorunbeforeeachtestend在我将MiniTest升级到4.7.2版本后,它显示以下错误:undefinedmethod`add_setup_hook'forMiniTest::Unit::TestCase:Class(NoMethodError)我正在使用RubyMRI2.0.0p0。解决方案moduleMyMinitestPlugindefbefore_setupsuper#...codetorun

ruby - Minitest 断言在检查时失败

每当我尝试assert_equal两个对象时,我总是会遇到这样的错误:NovisibledifferenceintheUser#inspectoutput.Youshouldlookattheimplementationof#==onUseroritsmembers.Time和Array也发生过这种情况。Minitest文档对此也没有说太多。我使用的是Ruby2.0.0,但我使用的是2.2.0,同样的事情发生了。也使用最新的minitest。此外,我正在运行Ubuntu14.10。 最佳答案 关于留言当断言失败时显示这条消息,有点不

ruby - 使用 Minitest::Mock 验证从未调用过或仅调用过一次的方法

有什么方法可以使用Minitest::Mock验证从未调用过或仅调用过多次的方法提前致谢 最佳答案 具体次数:Minitest::Mock强制开发人员明确消息预期,因此如果您希望给定方法被调用x次,您需要非常直白。my_mock=Minitest::Mock.newx.times{my_mock.expect:some_method,:return_val}从未调用过:从哲学上讲,Minitest避免测试没有发生的事情。虽然不完全相似,但请查看thispost或谷歌“minitestassertnothingraised”。Mini

ruby-on-rails - 如何使用单元样式为集成测试配置 minitest

我找到了配置Rails以使用Minitest的资源。不幸的是,大多数资源都假定对所有测试类型使用Minitest规范,或者在最好的情况下,至少对集成测试。我可能是“老式”,但我觉得alatest:unit断言比rspec风格更适合我。我会使用MiniTest::Unit声明样式和Capybara来运行集成测试。我有兴趣查看minitest_helper.rb和some_model_integration_test.rb的示例,以了解我需要放置的相关配置元素,以使集成测试与Capybara很好地协同工作。有人可以解释一下如何为此配置Rails吗? 最佳答案

ruby-on-rails - 使用Minitest,需要 'minitest_helper'加载错误

我正在测试Minitest::Spec作为RSpec的替代品,但我有一个讨厌的问题,我无法完全找到答案:我在spec/models/*_spec.rb中设置了一些基本规范。我的Rails应用程序包含minitest-rails,我已将我的rakefile设置如下:Rake::TestTask.newdo|t|t.libs.push"lib"t.test_files=FileList['spec/**/*_spec.rb']t.verbose=trueendtask:default=>:test现在,如果我这样写我的规范文件:require'minitest_helper'describ

ruby-on-rails - rails : route helpers for nested resources

我有如下嵌套资源:resources:categoriesdoresources:productsend根据RailsGuides,Youcanalsouseurl_forwithasetofobjects,andRailswillautomaticallydeterminewhichrouteyouwant:Inthiscase,Railswillseethat@magazineisaMagazineand@adisanAdandwillthereforeusethemagazine_ad_pathhelper.Inhelperslikelink_to,youcanspecifyju

ruby-on-rails - ruby rails : Use Variable in link_to helper path

我有一个接收变量bar的HAML部分,我想将该变量注入(inject)到link_to路径中。例如:=link_tonew_foo_path,class:'sourcecard'do.stuff我想用bar替换foo。我试过:=link_tonew_#{bar}_path,class:'sourcecard'do还有许多其他东西,但似乎没有任何效果。想法? 最佳答案 你可以这样试试:link_tosend("new_#{bar}_path"),class:"源卡"do基本上,send使某物成为一种方法或变量,它允许您将该字符串中的所