草庐IT

test_proc

全部标签

ruby - 有没有办法在 Test::Unit 中撤消 any_instance 的摩卡 stub

很像thisquestion,我也在使用RyanBates的nifty_scaffold。它具有使用Mocha的any_instance的理想方面。在Controller后面的模型对象中强制进入“无效”状态的方法。与我链接到的问题不同,我没有使用RSpec,而是使用Test::Unit。这意味着那里的两个以RSpec为中心的解决方案对我不起作用。是否有通用的(即:与Test::Unit一起使用)删除any_instancestub的方法?我认为它导致我的测试出现错误,我想验证这一点。 最佳答案 碰巧,Mocha0.10.0允许uns

ruby - 在 Ruby 的 Test::Unit::TestCase 中,如何覆盖初始化方法?

我正在为Test::Unit苦苦挣扎。当我想到单元测试时,我会想到每个文件一个简单的测试。但在Ruby的框架中,我必须改写:classMyTest但是每次调用test_*方法时都会运行设置和拆卸。这正是我不想要的。相反,我想要一个只为整个类(class)运行一次的设置方法。但是我似乎无法在不破坏TestCase的初始化的情况下编写自己的initialize()。这可能吗?还是我让这件事变得无可救药地复杂了? 最佳答案 如HalFulton的书“TheRubyWay”中所述。他覆盖了Test::Unit的self.suite方法,该方

ruby-on-rails - Rails 测试找不到 test_helper

我试图通过ruby​​test/unit/mytest.rb运行单独的测试,但我总是收到“没有这样的文件要加载-test_helper”的错误。Google提出了一些建议,但没有一个对我有用。我在Ubuntu10.10上运行Rails3.0、Ruby1.9.2(通过RVM)这是我到目前为止所做的尝试-非常感谢任何建议将“requiretest_helper”更改为“requireFile.dirname(FILE)+“/../test_helper””在test/unit/mytest_test.rb中。它带回“没有要加载的文件--test/unit/../test_helper”尝试

ruby-on-rails - minitest、test::unit 和 rails

我在某处读到“minitest”是“ruby1.9.2+的新测试::单元”。但ruby​​1.9.3似乎包含两者test::unit和minitest,是真的吗?在默认的rails测试中,如Railstestingguide中所述....诸如ActiveSupport::TestCase、ActionController::TestCase之类的东西,是使用Test::Unit还是Minitest?在Rails指南中,它显示了带有如下定义的测试的示例:test"shouldshowpost"doget:show,:id=>@post.idassert_response:successe

ruby-on-rails - rails : Testing named scopes with RSpec

我是测试Rails网络应用程序和RSpec的新手。我使用遗留代码并需要添加测试。那么使用RSpec测试查找器和命名范围的最佳方法是什么?我在Google中找到了一些方法,但它们并不理想。例如:http://paulsturgess.co.uk/articles/show/93-using-rspec-to-test-a-named_scope-in-ruby-on-railsit"excludesusersthatarenotactive"do@user=Factory(:user,:active=>false)User.active.should_notinclude(@user)e

ruby - Procs的绑定(bind)

是否可以在另一个对象的上下文中执行proc?我知道通常你会执行proc.call(foo),然后block应该定义一个参数。我想知道我是否可以让“self”绑定(bind)到foo,这样就不需要block参数了。proc=Proc.new{self.hello}classFoodefhelloputs"Hello!"endendfoo=Foo.new#Howcanprocbeexecutedwithinthecontextoffoo#suchthatitoutputsthestring"Hello"?proc.call 最佳答案 f

Ruby:Proc.new { 'waffles' } 与 proc { 'waffles' }

在Ruby中,Proc.new{'waffles'}和proc{'waffles'}之间有什么区别吗?我发现很少有人提到第二种语法。使用irb进行测试,我没有发现任何明显的差异。第二个是第一个的语法糖吗? 最佳答案 来自MetaprogammingRuby第113页。在Ruby1.8中,Kernel#proc()实际上是Kernel#lambda()的同义词。由于程序员的强烈抗议,Ruby1.9将proc()改为Proc.new()的同义词。 关于Ruby:Proc.new{'waffl

ruby - 使用带参数的 instance_eval 调用 proc?

我知道这行得通:proc=Proc.newdoputsself.hi+'world'endclassUsadefhi"Hello!"endendUsa.new.instance_eval&proc但是我想将参数传递给proc,所以我尝试了这个不起作用:proc=Proc.newdo|greeting|putsself.hi+greetingendclassUsadefhi"Hello!"endendUsa.new.instance_eval&proc,'world'#doesnotworkUsa.new.instance_eval&proc('world')#doesnotwork谁能

Ruby - lambda 与 Proc.new

这个问题在这里已经有了答案:关闭11年前。PossibleDuplicate:What'sthedifferencebetweenaprocandalambdainRuby?当运行此Ruby代码时:deffunc_oneproc_new=Proc.new{return"123"}proc_new.callreturn"456"enddeffunc_twolambda_new=lambda{return"123"}lambda_new.callreturn"456"endputs"Theresultofrunningfunc_oneis"+func_oneputs""puts"There

ruby-on-rails - Rails 3.1 中的 Rails.cache 错误 - TypeError : can't dump hash with default proc

我在3.1.0.rc4(ruby1.9.2p180(2011-02-18修订版30909)[x86_64-darwin10])上遇到Rails.cache方法问题。该代码在2.3.12(ruby1.8.7(2011-02-18补丁级别334)[i686-linux],MBARI0x8770,RubyEnterpriseEdition2011.03)上的同一应用程序中运行良好,但在升级后开始返回错误。我还没弄明白为什么。当尝试缓存具有多个作用域的对象时似乎会发生错误。此外,无论有多少范围,使用lambda的任何范围都会失败。我曾因这些模式而失败:Rails.cache.fetch("ke