我有一个下面的规范,我在其中模拟我的用户模型并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
给定这段代码:expect(exit_code).toeq(0),result我明白expect(exit_code).toeq(0)应该做什么,但我不明白逗号或result变量在做什么。有人可以帮我解释一下吗? 最佳答案 这不是很常见,但是to方法可以接受一个额外的参数,它是在示例失败时显示的消息。看看sourcecode.因此,自定义消息可以提供额外的信息,如何处理失败的规范:expect(exit_code).to(eq(0),"specfailed,becauseexit_codeis0,pleasehandleit")第二
我想测试在某些失败的情况下不会在模拟对象上调用任何方法,使用谷歌模拟。所以代码是这样的:automocObj=newMockObj;EXPECT_NO_METHOD_CALL(mocObj);//thisiswhatI'mlockingforautomainObj=newMainObj(mocObj,......andothermocks);//hereIsimulateafailusingtheothermockobjects,andIwanttobesurethenomethodsarecalledonthemockObj 最佳答案
我想测试在某些失败的情况下不会在模拟对象上调用任何方法,使用谷歌模拟。所以代码是这样的:automocObj=newMockObj;EXPECT_NO_METHOD_CALL(mocObj);//thisiswhatI'mlockingforautomainObj=newMainObj(mocObj,......andothermocks);//hereIsimulateafailusingtheothermockobjects,andIwanttobesurethenomethodsarecalledonthemockObj 最佳答案
所以我有一个名为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
我在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
我正在关注RubyonRailsTutorial作者:MichaelHartl。我到达了Chapter11.37但我的测试失败了。我收到以下错误:Failure/Error:xhr:post,:create,relationship:{followed_id:other_user.id}ArgumentError:badargument(expectedURIobjectorURIstring)我是RubyonRails的新手,所以我真的不知道出了什么问题。有人可以帮助解决此错误吗?controllers/relationships_controller.rb:classRelatio
在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
目前我正在Rails3中创建类似“运动管理和结果收集应用程序”的东西。在这个应用程序中我需要创建几个练习,它们本身可以有多个“结果类型”(心率,距离公里,重复,...)。并且应该可以按照我喜欢的顺序排列结果类型。所以,这是一个经典的多对多关系。我提出了以下迁移:classCreateExercisestruet.timestampsendenddefself.downdrop_table:exercisesendendclassCreateResulttypesfalsedo|t|t.integer"exercise_id"t.integer"resulttype_id"endadd_
我有以下代码用于模拟对类方法的调用: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]使测试通过。有没有一种方法我