草庐IT

guard-minitest

全部标签

ruby - 尝试运行 minitest 单元测试时出错

尝试使用rubytest/test_foo.rb运行minitest单元测试时出现以下错误:Warning:youshouldrequire'minitest/autorun'instead.Warning:oradd'gem"minitest"'before'require"minitest/autorun"'From:/home/emile/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/minitest/autorun.rb:15:```test_foo.rb看起来像这样:require'minitest/autorun'classTestFoo

ruby - 为什么 Minitest 的 assert_raises 在这种情况下没有按预期工作?

我正在尝试使用ActionControllerbugreporttemplate解决Rails中的一个奇怪行为.为了记录,这是模板中的Controller:classTestController我已经为缺失的Action添加了一条路线:routes.drawdoget'/'=>'test#index'get'/missing'=>'test#missing'end并且我试图断言AbstractController::ActionNotFound在遵循该路线时被引发:classBugTest预期行为:绿色测试。实际行为:#Runningtests:D,[2014-04-24T09:17:

ruby-on-rails - 在 Rails 中,我从 Guard 那里收到这个错误,说我必须更新到新的 :cmd syntax

我刚刚更新了我的gem,当我尝试运行Guard时,出现以下错误:Guard::RSpecDEPRECATIONWARNING:The:clioptionisdeprecated.Pleasecustomizethenew:cmdoptiontofityourneed.这是我的Guard文件:guard'rspec',cli:'--drb'dowatch(%r{^spec/.+_spec\.rb$})watch(%r{^lib/(.+)\.rb$}){|m|"spec/lib/#{m[1]}_spec.rb"}watch('spec/spec_helper.rb'){"spec"}#Ra

Ruby:Minitest、测试单元和实例变量

(已在https://www.ruby-forum.com/topic/6876320发布,但在这里交叉发布,因为到目前为止我还没有收到回复)。关于在Minitest和/或Test::Unit中并行化测试的问题(即正确使用parallelize_me!):假设我有一些辅助方法,几个测试都需要这些方法。根据我的理解,我不能用这种方法做这样的事情(简化示例):defprep(m,n)@pid=m@state=nenddefprocessif@stat>5&&@pid!=0...else...endend我想我不能在Minitest和测试单元中这样做,因为如果我从我的几个测试函数调用准备和处

ruby-on-rails - minitest 测试和代码覆盖率

我使用mini-test来测试框架。我使用omniauthgem进行身份验证。我使用simplecov进行代码覆盖。我使用"bundleexecrake"或"rakeminitest:controllers"运行我的测试。我举一个Controller的例子。当我运行rakeminitest:controllers时,Controller代码覆盖率变为100%。但是,当我运行bundleexecrake时,Controller代码覆盖率变为60%。SessionsController.rb代码:classSessionsControllersessionController_测试.rbr

ruby-on-rails - 仍然建议使用 Minitest 在 Rails 4 中测试路由吗?

在Rails3中,当在MiniTest中编写功能测试时,我养成了将路由测试与Controller操作分开测试的习惯。我从RailsGuideonTesting-Section9:TestingRoutes得到了这个想法.然而,在将我的应用程序升级到Rails4之后,我注意到如果我不为get|patch|post|delete方法提供一组适当的参数。例如,给定路线:#config/routes.rbnamespace"api"donamespace"v2",defaults:{format::json}doresources:usersdoresources:postsdoresourc

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