草庐IT

php - 如何在 phpunit 中运行目录结构测试?

全部标签

ruby-on-rails - 如何在 Rails 3 中禁用 XML 解析

我想禁用HTTP参数的自动XML解析。但我发现命令仅适用于Rails2.x,它们都不适用于3.0:config.action_controller.param_parsers.deleteMime::XML(application.rb)ActionController::Base.param_parsers.deleteMime::XMLRails3.0中的等价物是什么? 最佳答案 根据CVE-2013-0156的最新安全公告你可以将它用于Rails3.0。3.1和3.2ActionDispatch::ParamsParser::

ruby-on-rails - Ruby:如何在 fixture 中配置枚举?

给定这个类:classUser我想创建一个如下所示的fixture:testuser1:id:1username:sampermission::permission_staff我尝试了多种语法变体,但没有找到有效的方法。结果user.permission为nil或0。我知道enum是最近添加的。这可以做到吗? 最佳答案 根据enumdocs你可以像这样通过类引用可枚举的:User.permissions[:permission_staff]工厂只是ruby​​代码——所以他们应该能够以相同的方式访问值testuser1:id:1us

ruby-on-rails - 使用 Rspec 测试 rake 任务不接受参数

根据thispostbyStephenHagemann,我正在尝试为我的一个rake任务编写Rspec测试.lib/tasks/retry.rake:namespace:retrydotask:message,[:message_id]=>[:environment]do|t,args|TextMessage.new.resend!(args[:message_id])endendspec/tasks/retry_spec.rb:require'rails_helper'require'rake'describe'retrynamespaceraketask'dodescribe're

ruby - 如何在 heroku 中使用 haml?

我尝试使用sinatra让haml在没有gem的情况下工作(据我所知,Heroku不允许安装gem)到目前为止我做了什么:在我的项目中克隆hamlgitrepo在我的sinatra主文件中添加:require'haml/lib/haml.rb'以下作品:get'/test'doHaml::Engine.new('%ptest').renderend但以下不是:get'/test2'dohaml:my_templateend我得到错误:NoMethodError-nil:NilClass的未定义方法each'(haml):20:inrender'./haml/lib/haml/engin

ruby-on-rails - 获取当前时间的单元测试代码

为获取当前时间的代码编写单元测试的最佳方法是什么?例如,某些对象可能仅在工作日创建,其他对象在检查执行某些操作的权限时会考虑当前时间等。我想我应该模拟Date.today和Time.now。这是正确的做法吗?更新:两种解决方案(a)Time.is和(b)Time.stubs(:now).returns(t)都有效。(a)是非常好的方法,但(b)解决方案将与其他测试代码更加一致。在此question作者要求一个通用的解决方案。对于Ruby,在我的选项中,上述两个解决方案是simpler因此比提取获取当前日期/时间的代码更好。顺便说一句,我建议使用Chronic获得所需的时间,例如requ

ruby-on-rails -/usr/local/lib/libz.1.dylib,文件是为 i386 构建的,它不是被链接的体系结构 (x86_64)

在我的mac上安装几个东西时遇到这个问题,我认为这个问题来自将我的豹子升级到雪豹。我认为这个问题也与macports有关。/usr/local/lib/libz.1.dylib,filewasbuiltfori386whichisnotthearchitecturebeinglinked(x86_64)有什么想法吗?更新更具体地说,这发生在安装nokogirigem时日志看起来像:xslt_stylesheet.c:127:warning:passingargument1of‘Nokogiri_wrap_xml_document’withdifferentwidthduetoproto

ruby-on-rails - 如何在 ActionController::TestCase 请求中设置内容类型

我试图像这样在我的测试用例中执行获取:request.env['CONTENT_TYPE']='application/json'get:index,:application_name=>"Heka"虽然,它失败了:ActionView::MissingTemplate:Missingtemplatealarm_events/indexwith{:handlers=>[:builder,:haml,:erb,:rjs,:rhtml,:rxml],:locale=>[:en,:en],:formats=>[:html]尽管在我的Controller中我有:respond_to:html,

ruby-on-rails - Rspec 测试属于并且有很多

我正在运行rspec测试以确保两个模型通过has_many和belongs_to相互关联。下面是我的测试。describe"testingforhasmanylinks"dobeforedo@post=Post.new(day:"Day1",content:"Test")@link=Link.new(post_id:@post.id,title:"google",url:"google.com")endit"inthepostmodel"do@post.links.first.url.should=="google.com"endend测试告诉我url是一个未定义的方法。我的测试有什么

ruby - 在 Ruby + Chef 中检查现有目录失败

这是我在ChefRecipe中的一blockRuby:#ifdatadirdoesn'texist,moveoverthedefaultoneif!File.exist?("/vol/postgres/data")execute"mv/var/lib/postgresql/9.1/main/vol/postgres/data"end结果是:Executingmv/var/lib/postgresql/9.1/main/vol/postgres/datamv:inter-devicemovefailed:`/var/lib/postgresql/9.1/main'to`/vol/post

Ruby-rspec - 如何打印出测试(组)名称

如果我有一些测试,例如require_relative"Line"require_relative"LineParser"describeLinedoit"Canbecreated"doload"spec_helper.rb"@line.class.should==Lineendit"Canbeparsed"do...如何打印出测试组名称-在本例中为“Line”。我尝试添加:before:alldoputs"In#{self.class}"end但这给出了:InRSpec::Core::ExampleGroup::Nested_3,而不是Line 最佳答案