意外 =>,在 rspec 中期待 '}' [英] unexpected =>, expecting '}' in rspec expect

查看:35
本文介绍了意外 =>,在 rspec 中期待 '}'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码:

adapter.send(:conditions_to_fields, :user => user).should == {'owner_id' => user.id}

我更新为使用 expect :

which I updated to use expect with:

expect(adapter.send(:conditions_to_fields, :user => user)).to eq {'owner_id' => user.id}

但这给了我:

syntax error, unexpected =>, expecting '}'
... => user)).to eq {'owner_id' => user.id}

我的代码有什么遗漏或错误导致了我的错误?这是一个常见问题吗?

What did I miss or get wrong with my code that is giving me that error? Is it a common issue?

推荐答案

它认为您正在将块传递给 eq,而不是哈希.您可以通过在方法参数周围使用括号来解决此问题:

It thinks you’re passing a block to eq, not a hash. You can solve this by using parentheses around the method arguments:

expect(adapter.foo).to eq({'owner_id' => user.id})

这篇关于意外 =>,在 rspec 中期待 '}'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆