草庐IT

expected_conditions

全部标签

ruby - rspec 失败错误 : expected false to respond to `false?`

我正在运行这部分测试:describeDictionarydobeforedo@d=Dictionary.newendit'cancheckwhetheragivenkeywordexists'do@d.include?('fish').shouldbe_falseend使用这段代码:classDictionarydefinitialize@hash={}enddefadd(new_entry)new_entry.class==String?@hash[new_entry]=nil:new_entry.each{|noun,definition|@hash[noun]=definiti

ruby - 我如何在 RSpec 中引发异常的 `expect`?

我有一个方法可以对Cat模型执行一些操作,如果输入不正确会引发异常:context"hungrycat"doit{expect{eat(what:nil)}.toraise_error}end我想做的是检查这个方法是否改变了猫的状态,就像那样:context"hungrycat"doit{expect{eat(what:nil)}.toraise_error}it{expect{eat(what:nil)}.not_tochange(cat,:status)}end问题在于,由于eat(what:nil)将引发异常,因此第二个it无论如何都会失败。那么,是否可以忽略异常并检查某些条件?

ruby - 轨道 3/ ruby : ActiveRecord Find method IN condition Array to Parameters single quote issue

我在微博模型上创建了一个方法,它接受一个user_id数组。在此方法中,我使用以下“查找”方法来提取数组中所有用户的所有帖子。find(:all,:conditions=>["user_idIN(?)",args.join(',')])但是当ActiveRecord为这个查询生成SQL时,它用单引号将逗号分隔的ID列表括起来。这会导致查询只提取单引号内第一个数字的帖子,而不是所有数字。SELECT`microposts`.*FROM`microposts`WHERE(user_idIN('3,4,5'))ORDERBYmicroposts.created_atDESC查询应该看起来像这

ruby - Rspec : expect vs expect with block - what's the difference?

刚刚学习rspec语法,我注意到这段代码有效:context"givenabadlistofplayers"dolet(:bad_players){{}}it"failstocreategivenabadplayerlist"doexpect{Team.new("Random",bad_players)}.toraise_errorendend但是这段代码没有:context"givenabadlistofplayers"dolet(:bad_players){{}}it"failstocreategivenabadplayerlist"doexpect(Team.new("Rando

ruby - RSpec allow/expect 与 just expect/and_return

在RSpec中,特别是版本>=3,有什么区别:使用allow设置带有返回测试替身的参数的消息期望,然后使用expect对返回的测试替身进行断言只需使用expect设置带有参数的期望并返回测试替身还是只是语义?我知道用expect提供/指定返回值是thesyntaxinRSpecmocks2.13,但据我所知,thesyntaxchangedinRSpecmocks3使用允许。但是,在下面的(传递的)示例代码中,使用allow/expect或仅使用expect/and_return似乎产生相同的结果。如果一种语法比另一种语法更受欢迎,也许我会期望有某种弃用通知,但由于没有,这两种语法似乎

ruby-on-rails - ruby rails : conditionally display a partial

我不确定我是否采用了最好的方法,但我有一个数据block,我想在搜索完成后显示,并且之前根本不存在。首先,没有什么可显示的,其次,它引用的模型是nil,所以它抛出异常。我将此block放在部分模板中,并将其添加到布局中的适当位置。有没有办法有条件地干净地渲染部分?有没有更好的方法来解决这个问题? 最佳答案 Ruby允许你做这样的好事:"foo/bar"if@conditions%>为了使它更容易阅读和理解,它可以写成:"foo/bar")if@conditions%>render是一个函数,您向它传递一个散列值,告诉它要渲染哪个部分

ruby - 在 RSpec-2.11 中使用隐式 `subject` 和 `expect`

使用rspec-2.11中新的expect语法,如何使用隐式的subject?有没有比显式引用subject更好的方法,如下所示?describeUserdoit'isvalid'doexpect(subject).tobe_valid# 最佳答案 如果您将RSpec配置为禁用should语法,您仍然可以使用旧的单行语法,因为这不涉及将should添加到每个对象:describeUserdoit{shouldbe_valid}end我们brieflydiscussed一种替代的单行语法,但决定反对它,因为它不需要,我们觉得它可能会增

ruby-on-rails - 'Assignment Branch Condition Size too high' 是什么意思以及如何修复它?

在我的Rails应用程序中,我使用Rubocop检查问题。今天它给了我这样的错误:AssignmentBranchConditionsizeforshowistoohigh。这是我的代码:defshow@category=Category.friendly.find(params[:id])@categories=Category.all@search=@category.products.approved.order(updated_at::desc).ransack(params[:q])@products=@search.result.page(params[:page]).pe

javascript - Auth0 授权者拒绝来自服务的 JWT token - "jwt issuer invalid. expected: https://myservice.auth0.com"

我正在浏览将auth0设置为此处列出的AWS的API网关授权方的教程:https://auth0.com/docs/integrations/aws-api-gateway/custom-authorizers我正在使用此处推荐的授权方:https://github.com/auth0-samples/jwt-rsa-aws-custom-authorizer唯一的修改是配置文件。但是,在测试授权函数时,出现如下错误:{"name":"JsonWebTokenError","message":"jwtissuerinvalid.expected:https://MYSERVICE.au

javascript - 如何封装mocha `expect()`代码?

我正在尝试测试是否存在一些我希望在所有测试中都需要的api响应属性(status和data属性)。这是一个通用测试,它断言supertest中的所需属性expect()方法:it('shouldcreateawidget',done=>{letstatus=200;request(test_url).post('/api/widgets').set('Authorization',`Bearer${token}`).send({sku:my_widget_data.sku,name:my_widget_data.name,description:''}).expect(res=>{as