试图找出我的rspec测试失败的原因。最值得注意的是看起来自相矛盾的失败消息。声明我有一个ActiveRecord::RecordInvalid错误,这正是我断言应该发生的事情。这是我的user.rb...validates_presence_of:email...这是我的users_spec.rb...it"isinvalidwithoutemail"doFactory(:user,email:nil).shouldraise_error(ActiveRecord::RecordInvalid)end...这是输出:Failures:1)Userauser(ingeneral)isi
有没有办法在rspec中匹配参数的属性value?检查thedocumentation看起来还有其他可用的匹配器,例如anything、an_instance_of和hash_including-但没有检查对象属性值的方法。示例-假设我有这个实例方法:classDateParserdefparse_year(a_date)putsa_date.yearendend然后我可以这样写一个期望:dp=DateParser.newexpect(dp).toreceive(:parse_year).with(some_matcher)我想让some_matcher检查parse_year是用任何
作为作业的一部分,我正在创建一个基本网站。当rails服务器未运行且我对根目录执行“rspec”时,将执行rspec。但是测试失败。当我启动railsserver并从另一个终端窗口执行rspec时(进入根目录后),rspec不起作用。我收到以下消息-Tushars-MacBook-Pro:recipefindertusharsaurabh$rspec-bash:rspec:commandnotfound请告诉我如何修复它。 最佳答案 也许你的rspec命令没有在系统范围内安装,没关系,试试运行bundleexecrspec它应该可以
我使用简单的Rails4.1.0应用程序,不使用设计。我正在测试应用程序Controller:classApplicationController我对authenticate_user!方法有疑问。完整规范seehere.方法规范:describe'authenticate_user!'docontext'whenuserloggedin'dobefore{subject.send(:current_user=,create(:user))}it'donothing'doexpect(subject.send(:authenticate_user!)).toeqnilendendcon
我的类中的逻辑有时使用Rollbar.silenced来忽略一些异常(因此它们不会被报告)。我正在尝试编写一个测试以确保rollbar实际报告错误。it'doesnotmuterollbar'doexpect(Rollbar).not_toreceive(:silenced)expect(Rollbar).toreceive(:error).with(any_args).and_call_originalexpect{query}.toraise_error(unknown_exception)end不幸的是,在报告未挽救的错误时,rollbar不会在:error、:critical、
我正在对cucumber使用rspec期望值。似乎在cucumber步骤中使用多个期望时,cucumber会评估它们直到第一个失败。但是,我想继续运行,其他人也希望清楚地了解出了什么问题。我能以某种方式实现这一点吗?例子:-让我们假设response="1",code="2"andstatus="3"expect(response).toeq("0")expect(code).toeq("2")expect(status).toeq("1")Cucumber在评估响应变量时会失败。但我想检查其他两个变量的值并获得错误状态值的输出。这可能吗? 最佳答案
在RSpec单元测试中,我有一个像这样定义的模拟:let(:point){instance_double("Point",:to_coords=>[3,2])}在Point类中,我还有一个setter,用于被测类(称为Robot)。我想stub那个setter来测试Robot#move。这是我到目前为止的错误代码:describe"#move"doit"sets@xand@yonestepforwardinthedirectiontherobotisfacing"dopoint.stub(:coords=).and_return([4,2])robot.moveexpect(robot
这个例子有点做作,但很好地解释了用例。let(:number_of_users){User.count}it'countsusers'doUser.createnumber_of_users.should==1User.createnumber_of_users.should==2end此测试失败,因为number_of_users仅评估一次,并且变得陈旧。有没有办法在每次调用时重新评估它? 最佳答案 您可以只定义一个常规方法:defnumber_of_usersUser.countendit'countsusers'doUser.
有如下RSpec代码:it'isnotvalidifnameisnotpresent'do@car.name=nilexpect(@car).tobe_invalidend我现在读了AaronSumner的“TestingwithRSpec”,他写了关于RSpec中的新样式的文章。之前我写了下面的代码:it'isnotvalidifnameisnotpresent'do@car.name=nilit{should_notbe_valid}end请告诉我,我这样做对吗?谢谢。 最佳答案 我认为这是一个很好的例子describe"Car
我对测试还很陌生,并且有一个我想测试的UsersController。我从新的Action开始,到目前为止有以下内容;require'spec_helper'describeUsersControllerdodescribe"GET'new'"doit"assignsanewUserto@user"douser=User.newget:newassigns(:user).shouldeq(user)endit"rendersthe:newtemplate"endend到目前为止,我的UsersController看起来像这样classUsersController我预计我的第一个测试会