草庐IT

ngx_http_stub_status_module

全部标签

ruby-on-rails - 何时以及何时不 stub /模拟测试

我正在齐心协力围绕Rspec进行研究,以便转向更多的TDD/BDD开发模式。但是,我还有很长的路要走,并且在一些基础知识上苦苦挣扎:比如,我究竟什么时候应该使用模拟/stub,什么时候不应该?以这种情况为例:我有一个Site模型has_many:blogs和Blog模型has_many:articles。在我的Site模型中,我有一个回调过滤器,它为每个新站点创建一组默认的博客和文章。我想测试该代码,所以这里是:describeSite,"whencreated"doincludeSiteSpecHelperbefore(:each)do@site=Site.createvalid_s

ruby-on-rails - 在 Controller 中 stub 一个实例变量

我正在使用rspec1.3.2来测试看起来像这样的Controller操作:defaction_foo...@bar.can_do_something?...end我正在尝试stub@bar(假设它是Bar类的一个实例)实例变量,但我无法做到。我认为如果我可以访问any_instance那么我可以执行Bar.any_instance.stub(:can_do_something?)但这在我使用的rspec版本中不可用。是否有另一种方法来访问和stub@bar?以下均无效:@bar.stub(:can_do_something?)controller.instance_variable_

ruby - 在 AWS Linux 上增加 RestClient/Net::HTTP 中的 connect(2) 超时

我正在使用rest-client发布到一个非常慢的网络服务。我将timeout设置为600秒,并且我已经确认它正在传递给Net::HTTP的@read_timeout和@open_timeout.但是,大约两分钟后,我收到一个低级超时错误,Errno::ETIMEDOUT:Connectiontimedout-connect(2):回溯的相关部分是Operationtimedout-connect(2)for[myhost]port[myport]/Users/dmoles/.rvm/rubies/ruby-2.2.5/lib/ruby/2.2.0/net/http.rb:879:in

ruby - 模块嵌套在 instance_eval/exec 或 module_eval/exec 中

我在尝试回答this时想到了这个问题.以下是预期的行为:moduleApModule.nestingend#=>[A]但是以下内容:A.instance_eval{pModule.nesting}A.instance_exec{pModule.nesting}A.module_eval{pModule.nesting}A.module_exec{pModule.nesting}全部返回[]。为什么这些不能像上面那样工作?附加问题Muistooshort提出了一个有趣的观点。如果这是正确的,那么Module.nesting将是依赖于文字上下文的方法和变量之一,例如Method#sourc

ruby - 允许传递 [hash_key] 的 rspec stub

如何创建rspec方法stub以允许接收散列键的方法的响应返回其值?这是我要测试的线路sub_total=menu.menu_items[item]*quantity并且我在rspec中使用这一行作为我的double测试stub。allow(menu).toreceive(:menu_items[item]).and_return(2.0)我的环境是用ruby​​2.2.0和spec3.1.7设置的但是我不断得到一个NameError:undefinedlocalvariableormethod`item'ruby代码defplace_order(item,quantity,menu)

Ruby module_function,调用模块的私有(private)方法,在模块的类方法样式中调用显示错误

test_module.rbmoduleMyModuledefmodule_func_aputs"module_func_ainvoked"private_bendmodule_function:module_func_aprivatedefprivate_bputs"private_binvoked"endendclassMyClassincludeMyModuledeftest_modulemodule_func_aendend从类中调用模块函数c=MyClass.newc.test_module输出1:$rubytest_module.rbmodule_func_ainvoked

ruby - stub http 请求以返回带有 Net::HTTPResponse 的 HTTPartyResponse

我正在尝试编写一个rspec规范来测试我的逻辑是否能够处理状态代码为401的特定Net::HTTPResponse。当我使用HTTParty时,.get将返回一个HTTPartyResponse并且我'我们将使用httparty_repsonse_object.response检索Net::HTTPResponse。net_response_object=Net::HTTPResponse.new(1.1,401,'Forbidden')#notsurewhattodohere?writeatestdoubletoreturnanet_response_object?stub_requ

ruby-on-rails - rails : Can't access a module in my lib directory

我想创建一个通用的字符串操作类,可以在我的Rails应用程序中跨模型、View和Controller使用。现在,我正试图将一个模块放入我的lib目录中,我只是试图访问Rails控制台中的函数来测试它。我已经尝试了很多来自类似问题的技术,但我无法让它发挥作用。在我的lib/filenames.rb文件中:moduleFilenamesdefsanitize_filename(filename)#Replaceanynon-letterornon-numbercharacterwithaspacefilename.gsub!(/[^A-Za-z0-9]+/,'')#removespaces

ruby - 为什么在 Net::HTTP 上使用 Faraday?

为什么有人会使用Faradaygem而不是直接使用Net::HTTP?使用这样的包装器有什么好处? 最佳答案 直接使用Net::HTTP适配器就可以了,它只是将您的代码绑定(bind)到一个特定的接口(interface),这可能与其他工具不同。人们会使用Faraday的主要原因是它包装了多个适配器,其中之一是Net::HTTP。如果您使用Faraday并开始使用Net:HTTP,您可以稍后决定使用Excon,Typhoeus,Patron或EventMachine无需更改超过一两行配置。如果您直接使用Net::HTTP,则必须更改

ruby-on-rails - 在 Rspec 中 stub ActionMailer

致敬!我正在尝试使用如下所示的Rspec测试Controller方法:defemail_customer@quote=Quote.find(params[:quote_id])hash={quote:@quote,body:params[:email_body],subject:params[:email_subject]}QuoteMailer.email_customer(hash).deliverredirect_toedit_quote_pathparams[:quote_id]end相应的规范如下所示:describe'POSTemail_customer'dolet!(:q