我想测试一个特定的方法是否不会引发类AError的错误。它可以引发BError、ArgumentError、几乎任何其他类型的错误,或者没有错误,只是不是AError。是否有任何未弃用的(从RSpec3开始)的方法来做到这一点?我试过了expect{object.do_something}.not_toraise_error(AError)但是我明白了ArgumentError:`expect{}.not_toraise_error(SpecificErrorClass)`isnotvalid,use`expect{}.not_toraise_error`(withnoargs)ins
作为序言,我对Rails和一般的MVC格式非常陌生。我正在使用Rspec进行所有测试,但我的controller_spec中的这段代码有问题:describe"GETshow"docontext'withanadminusersignedin'dowith:adminlet!(:invitation){create:invitation}beforedosign_inadminget:show,id:invitation.idendit{shouldrespond_with:ok}it{shouldrespond_with_content_type:html}it{shouldrend
有什么方法可以访问RSpec示例中的Ruby警告列表吗?我在正在测试的库中收到以下错误,并想为其编写单元测试。warning:previousdefinitionofBUILD_FILEwashere 最佳答案 我最终启动了一个新流程来评估流程输出。在我的例子中,问题是一个重新定义的常量,所以我通过将类两次加载到新的Ruby进程中然后使用IO流读取输出来进行测试:it'shouldnotredefineBUILD_FILEconstant'doroot_path="#{File.dirname(__FILE__)}/../../..
我正在使用ruby和rspec与watir一起编写自动化测试用例。C:\Users\san\Dragon>gemlist'rspec'***LOCALGEMS***rspec(3.4.0,2.14.1)rspec-core(3.4.3,2.14.8)rspec-expectations(3.4.0,2.14.5)rspec-mocks(3.4.1,2.14.6)rspec-support(3.4.1)当我使用以下命令运行测试用例时。C:\Users\san\Dragon>rspec-fspec\sampletest_spec.rb:65我遇到了这个错误C:/Ruby193/lib/
我有一个类似这样的服务对象:classSecurityQueryServiceclassContract::NotFound我有以下相关规范:require'spec_helper'describeSecurityQueryServicedolet(:user){create(:customer)}let!(:equity_contract){create(:equity_contract)}describe"#call"dodescribe"#find_contract"doit"returnscontractbasedoncontracttype."doservice=Securi
我的测试有问题。我有这个规范:context'whennosectionissupplied'doit'raisesanArgumentErrorregardingthemissingsection_idargument'doexpectdodescribed_class.with_sectionend.toraise_error(ArgumentError).with_message/wrongnumberofarguments\(given0\,expected1\)/endend在某些环境中,消息是:ArgumentError:wrongnumberofarguments(0fo
我在RubyonRails环境中使用RSpec和FactoryGirl进行测试。我想指定我的工厂如下:factory:userdorole#stubfactory:residentdoassociation:role,factory::resident_roleendfactory:admindoassociation:role,factory::admin_roleendend我想在我的规范中做这样的事情:require'rails_helper'RSpec.describeUser,type::modeldocontext"allusers"do#describeauser#sub
这是创建目录的方法。defcreate_directory(path)system'mkdir','-p',pathend我为此方法创建了一个rspec并使用fakefs来模拟目录的创建。it'shouldcreatedirectorygivenpathasparameter'doFakeFSdocreate_directory(DIRECTORY_PATH)endexpect(File.exists?(DIRECTORY_PATH)).tobe_truthyend当我执行rspec命令时,我得到了这个错误。Failures:1)commonTestforcommonmethoduse
我遇到了以下问题:环境:Ruby:2.3.1和Rails5.0.0.1我正在尝试使用RSpec和FactoryGirl验证日期时间字段。我遇到了这个错误:expected:"2016-11-1113:30:31UTC"(FromFactoryGirl)got:"2016-11-11T13:30:31.218Z"(Fromdatabase)我的代码:klass_object=FactoryGirl.create(:character)klass=CharacterRSpec.shared_examples'APIGET#index'do|klass|before{get:index,pa
我在尝试验证请求规范时遇到问题。如何在每个http请求的header中传递有效的身份验证token?我的方法是否正确?tweets_request_spec.rbrequire'rails_helper'RSpec.describe'TweetsAPI',type::requestdobeforedo@tweets=create_list(:tweet,10)@tweet=@tweets.firstenddescribe'GET/tweets'dobefore{get'/tweets',{"Authorization":*somesortoftoken*}}it"returnstwee