草庐IT

test_proc

全部标签

ruby - 如何区分Sinatra请求对象和Rack Test请求方法?

我有一个在Sinatra应用程序范围内运行的方法,用于检查请求是否安全:secure_request?request.env['HTTPS']=='on'end这工作正常,但是当我从另一个不共享Sinatra应用程序范围的类调用它时,它会尝试发出机架测试请求,并引发错误:参数数量错误(1为0).那么,有没有办法显式指定Sinatra应用程序请求,例如self.request或app.request? 最佳答案 从另一个类调用request方法闻起来像是糟糕的代码设计,将另一个类与您的应用程序紧密耦合。secure_request?在

ruby - 如何获取正在通过 rack-test 测试的 Sinatra 应用程序实例?

我想获取正在通过rack-test测试的应用程序实例,以便我可以模拟它的一些方法。我以为我可以简单地将应用程序实例保存在app方法中,但由于某些奇怪的原因不起作用。看起来rack-test只是使用实例来获取类,然后创建自己的实例。我做了一个测试来证明我的问题(它需要gem“sinatra”、“rack-test”和“rr”才能运行):require"sinatra"require"minitest/spec"require"minitest/autorun"require"rack/test"require"rr"describe"instantiatedapp"doincludeRa

ruby - "test".partition( "s") 从 Enumerable 模块而不是 String 模块调用分区

我尝试使用partitionmethodfromtheStringmodule对字符串进行分区.但是,这样做时:puts"test".partition("s")我收到以下错误消息:Line1:in`partition':wrongnumberofarguments(1for0)(ArgumentError)fromt.rb:1我相信Ruby调用了partitionmethodfromtheEnumerablemodule,而不是我想要的来自String模块的那个。如何让Ruby调用所需的方法? 最佳答案 作为injekt已经指出,

ruby-on-rails - 如何使模块方法可用于常量 Proc 变量? ( ruby )

这是在我的应用程序助手中:defcall_me"blah"endP=Proc.new{call_me}deftest_meP.callend如果我在我看来这样做:我收到一条错误消息,指出call_me是一个未定义的方法。如何让Proc能够调用call_me?要求不这样做。前缀为ApplicationHelper::call_me也不会。:(这行得通,但我真的不喜欢它,因为test_me会被调用很多次,而实际上还有更多的Proc:deftest_mep=Proc.new{call_me}p.callend 最佳答案 它应该像在Ruby

ruby - 为什么 Test::Unit.test_order= 没有按预期工作?

有问题InRuby,howtoIcontroltheorderinwhichTest::Unittestsarerun?并想引用test_order=:defined,来回答documentationforTest::Unit::TestCase.test_order说:Setsthecurrenttestorder.Herearetheavailableorder::alphabeticDefault.Testsaresortedinalphabeticorder.:randomTestsaresortedinrandomorder.:definedTestsaresortedind

ruby - 为什么调用在方法中声明的返回 Proc 有效?

我一直在学习CodecademyRuby类(class),其中有一个关于lambdas和Procs的练习。我确实理解其中的区别,但我不太明白为什么此处列出的第一个代码有效,而第二个却无效。为什么这样做:defbatman_ironman_procp=Proc.new{return"Batmanwillwin!"}p.call"IronManwillwin!"endputsbatman_ironman_proc#prints"Batmanwillwin!"但不是这个:defbatman_ironman_proc(p)p.call"IronManwillwin!"endp=Proc.new

ruby-on-rails - 我可以使用 rspec 登录到 test.log 吗?

这里有一个简单的规范来测试这个:require'spec_helper'describeA_controllerdobeforedo@cat_noise="Meow"endit"shoulddonothingbecauseit'semptyandIcreateditjusttotestlogger!"dologger.info"----------Herecomesacatnoise-----------"logger.info@cat_noiselogger.info"-----------Theregoesacatnoise-----------"endend这是我的测试环境的日志

ruby - 找到了 Cucumber.yml,但无法针对 Parallel_Tests 进行解析

使用此命令在Cucumber中使用RubygemParallel_Tests运行多个功能时:parallel_cucumberfeatures/在我的项目根目录下有一个cucumber.yml文件>config文件夹,它看起来像:default:--formathtml--outreport.html我收到以下错误消息:cucumber.ymlwasfound,butcouldnotbeparsed.Pleaserefertocucumber'sdocumentationoncorrectprofileusage.我已经对此进行了调查,其他一些人认为这是由于rerun.txt文件造成的

Ruby Lambda 与 Proc LocalJumpError

Ruby和StackOverflow新手在这里学习Ruby并遇到了我的第一个主要障碍。我真的很难全神贯注于Procs和Lambdas。这是我正在使用的代码。defprocBuilder(message)Proc.new{putsmessage;return}enddeftestputs"enteringmethod"p=procBuilder("enteringproc")p.callputs"exitmethod"endtest按照设计,这是为了抛出LocalJumpError,但我不明白为什么。如果我不得不猜测它做了什么,我猜它最初会在p=procBuilder("entering

ruby-on-rails - '无方法错误 : undefined method `scan' for nil:NilClass' when functional testing with rails

这不是问题,而是我找到的解决方案。我正在使用RubyonRails4.1开发一个应用程序,它可以显示西类牙语、英语和日语的文本。当我开始功能测试时,我不断收到以下错误:NoMethodError:nil:NilClass的未定义方法“扫描”在网上冲浪时,我看到几个帖子都出现了同样的错误,但没有一个对我有用。这是代码原代码:application_controller.rb:classApplicationController所以这是/test/controllers/homes_controller_test.rb的代码:require'test_helper'classHomesCo