草庐IT

test-environments

全部标签

ruby - Rails3 : Functional tests fail with NoMethodError: undefined method `user' for nil:NilClass

我将Devise(v2.1.2)与Omniauth一起用于用户验证。我正在对一个Controller进行功能测试,该Controller将JSON对象作为POST主体,因此使用了thisquestion中的技术。设置原始POST正文。这适用于开发,但是当我运行测试时,我在一个完全未经身份验证的方法上遇到异常:NoMethodError:undefinedmethod`user'fornil:NilClass示例测试:test"shouldbeabletocreateanitem"dom=FactoryGirl.attributes_for(:item)raw_post:create,{

ruby-on-rails - Ruby on Rails,rake 数据库 :seed or db:reset - how do you dictate which mode (development/test/production)?

使用RubyonRails,当您使用rakedb:seed或db:reset重置或重新播种数据库时-您如何指定操作要处于哪种模式(开发/测试/生产)?我使用Sqlite进行开发,使用postgresql进行测试和生产——但使用不同的连接参数。我似乎无法控制Rails在我的开发箱(我在虚拟机Ubuntu13.l0中运行)或在Heroku上运行的模式。此外,当您在Heroku上运行应用时,您如何决定在哪种模式(开发/测试/生产)中运行您的应用?Heroku文档建议的方式不起作用(也就是说,将单行放入Procfile网络:bundleexecunicorn-p$PORT-E$RACK_ENV

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 - rails config/environments 'config' 在哪里定义?

在config/environments/production.rb(和其他环境)中有:config.eager_load=true和一大堆其他config.foobar调用。但是“配置”从何而来?通常你有这样的东西:SomeClass.eachdo|block_variable|block_variable.some_methodend但对于神秘的“配置”,情况并非如此,它就像一个未在任何地方声明的block变量。打开Rails控制台,当我这样做时:irb(main):001:0>configNameError:undefinedlocalvariableormethod`confi

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

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

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 - Sinatra 和 environment.rb

我正在开发一个基于Sinatra的应用程序,并且看到一些应用程序在应用程序的根目录中使用environment.rb文件,代码放置在配置block中。请参阅示例:https://github.com/zapnap/sinatra-template/blob/master/environment.rb;和https://github.com/andrewkolesnikov/sinatra-pro-template/blob/master/environment.rb.我尝试在Google上搜索但找不到关于environment.rb文件如何与Sinatra一起工作以及为什么要将某些内容