RSPEC更改匹配器仅与块语法一起工作

发布于 2025-02-05 19:11:50 字数 728 浏览 2 评论 0 原文

it { expect { subject }.to change(tt.child_task_transactions.reload, :size).by 1 }

上面的测试不会传递消息:

预期`taskTransaction :: ActivereCord_associations_collectionproxy#size“已更改为1,但已通过0 更改

      it do
        subject
        expect(tt.child_task_transactions.reload.size).to eq 1
      end

正确传递。还有:

it { expect { subject }.to change { tt.child_task_transactions.reload.size }.by 1 }

此测试也通过。

我在这里错过了什么吗?我虽然语法可互换

我正在使用 RSPEC 3.10.0, 铁轨6.1.4.1和 红宝石2.7.2

it { expect { subject }.to change(tt.child_task_transactions.reload, :size).by 1 }

The above test doesn't pass with the message:

expected `TaskTransaction::ActiveRecord_Associations_CollectionProxy#size` to have changed by 1, but was changed by 0

However:

      it do
        subject
        expect(tt.child_task_transactions.reload.size).to eq 1
      end

passes correctly. And also:

it { expect { subject }.to change { tt.child_task_transactions.reload.size }.by 1 }

And this test passes, too.

Am I missing something here? I though the syntaxes are interchangeable According to the docs.

I'm using
rspec 3.10.0,
Rails 6.1.4.1 and
Ruby 2.7.2

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文