草庐IT

expecting

全部标签

ruby-on-rails - 收到失败/错误 : expected: 1 time with any arguement,:任何参数 0 次

我有一个下面的规范,我在其中模拟我的用户模型并stub它的方法。require'spec_helper'describeUserdolet(:username){"test@test.com"}let(:password){"123"}let(:code){"0"}context"whensigningin"dolet(:expected_results){{token:"123"}.to_json}it"shouldsignin"doexpect(User).toreceive(:login).with({email:username,password:password,code:c

ruby - 逗号在 RSpec 的 expect 命令中起什么作用?

给定这段代码:expect(exit_code).toeq(0),result我明白expect(exit_code).toeq(0)应该做什么,但我不明白逗号或result变量在做什么。有人可以帮我解释一下吗? 最佳答案 这不是很常见,但是to方法可以接受一个额外的参数,它是在示例失败时显示的消息。看看sourcecode.因此,自定义消息可以提供额外的信息,如何处理失败的规范:expect(exit_code).to(eq(0),"specfailed,becauseexit_codeis0,pleasehandleit")第二

c++ - 谷歌模拟 : how can I "EXPECT " that no method will be called on a mock

我想测试在某些失败的情况下不会在模拟对象上调用任何方法,使用谷歌模拟。所以代码是这样的:automocObj=newMockObj;EXPECT_NO_METHOD_CALL(mocObj);//thisiswhatI'mlockingforautomainObj=newMainObj(mocObj,......andothermocks);//hereIsimulateafailusingtheothermockobjects,andIwanttobesurethenomethodsarecalledonthemockObj 最佳答案

c++ - 谷歌模拟 : how can I "EXPECT " that no method will be called on a mock

我想测试在某些失败的情况下不会在模拟对象上调用任何方法,使用谷歌模拟。所以代码是这样的:automocObj=newMockObj;EXPECT_NO_METHOD_CALL(mocObj);//thisiswhatI'mlockingforautomainObj=newMainObj(mocObj,......andothermocks);//hereIsimulateafailusingtheothermockobjects,andIwanttobesurethenomethodsarecalledonthemockObj 最佳答案

ruby-on-rails - 类型错误 : wrong argument type Class (expected Module) with Controller concern

所以我有一个名为guests_controller.rb的Controller,如下所示:classGuestsController而且我在controllers/concens/中还有一个名为data.rb的问题:moduleDataextendActiveSupport:Concerndefsave_data(save_method)casesave_methodwhen"db"@guest=Guest.new(guest_params)if@guest.saveflash[:success]="Newguestentrycreated!"redirect_toguests_pat

ruby - 如何编写 expect {}.to raise_error when rspec's syntax is configured with only should

我在rspec上有这个配置:config.expect_with:rspecdo|c|c.syntax=:shouldend它使expect{}.toraise_error无效,我怎么能用should语法编写这个错误引发测试? 最佳答案 我建议仅在最新的RSpecexpect{code()}.toraise_error语法对您不可用时才使用它:lambda{foo(:bad_param)}.shouldraise_error或lambda{foo(:bad_param)}.shouldraise_error(ArgumentErro

ruby-on-rails - 我如何解决 "bad argument (expected URI object or URI string)"? Ruby on Rails,Michael Hartl 教程

我正在关注RubyonRailsTutorial作者:MichaelHartl。我到达了Chapter11.37但我的测试失败了。我收到以下错误:Failure/Error:xhr:post,:create,relationship:{followed_id:other_user.id}ArgumentError:badargument(expectedURIobjectorURIstring)我是RubyonRails的新手,所以我真的不知道出了什么问题。有人可以帮助解决此错误吗?controllers/relationships_controller.rb:classRelatio

ruby-on-rails - Michael Hartl 的 Rails 教程 : Rspec's "Expected response to be a redirect to ..." is wrong

在MichaelHartl的(精彩的)Rails教程中,我遇到了一个意外的Rspec测试失败的形式:"Expectedresponsetobearedirecttohttp://test.host/signin>butwasaredirecttohttp://test.host/signin?notice=Please+sign+in+to+access+this+page.>."(在第10.3节中找到它。)因此,从错误本身,您可以看出服务器正在重定向到适当的页面,除了有一个额外的通知“请登录”。测试代码如下所示:describe"GET'index'"dodescribe"forno

ruby-on-rails - "Association expected, got String"与多对多关联

目前我正在Rails3中创建类似“运动管理和结果收集应用程序”的东西。在这个应用程序中我需要创建几个练习,它们本身可以有多个“结果类型”(心率,距离公里,重复,...)。并且应该可以按照我喜欢的顺序排列结果类型。所以,这是一个经典的多对多关系。我提出了以下迁移:classCreateExercisestruet.timestampsendenddefself.downdrop_table:exercisesendendclassCreateResulttypesfalsedo|t|t.integer"exercise_id"t.integer"resulttype_id"endadd_

ruby - minitest - 将任何参数传递给 expect

我有以下代码用于模拟对类方法的调用:deftest_calls_update_profile_job_for_a_leadinput=ContactInput.newvalid_attributesmock=MiniTest::Mock.newuse_case=CreateContact.newuser,input,mockmock.expect(:perform_async,nil,[user.id,1,::Contact])use_case.run!assertmock.verifyend问题是我必须传递特定值-[user.id,1,::Contact]使测试通过。有没有一种方法我