如何在服务调用后检查 rspec 中的数组更改? [英] how to check array changes in rspec after a service call?

查看:42
本文介绍了如何在服务调用后检查 rspec 中的数组更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目标很简单

例如我们有一个数组

<预><代码>[{名称:幽灵",状态:拒绝"},{名称:驴",状态:拒绝"}]

运行 Service call UpdateAllUsers 后,会将所有用户更改为 'accepted'

<预><代码> [{名称:幽灵",状态:已接受"},{名称:驴",状态:已接受"}]

这里的问题是如何在 rspec 中的服务调用之后检查数组中的所有对象是否具有相同的值?

rspec 中的示例

describe 'call' dolet(:all_users) { build(:users, 2, state: "rejected")service_call { UpdateAllUsers.new.call }它将所有用户状态更改为已批准"执行# 目标是在 Service 调用后检查所有用户状态.# 找不到办法# 之后的状态应该是 state =>'公认'结尾结尾

解决方案

可能为时已晚,但如果有人遇到同样的问题,它可能会很有用.

describe 'call' dolet(:all_users) { build(:users, 2, state: rejected")service_call { UpdateAllUsers.new.call }它将所有用户状态更改为已批准"做# 目标是在 Service 调用后检查所有用户状态.# 找不到办法# 之后的状态应该是 state =>'公认'all_users.each 做 |user|期望(用户).包括(:状态=> '接受')结尾结尾结尾

The goal is simple

example we have an array

[
  {name: "ghost", state: "rejected"}, 
  {name: "donkey", state: "rejected"}
]

After running the Service call UpdateAllUsers, it would change all the users to 'accepted'

   [
      {name: "ghost", state: "accepted"}, 
      {name: "donkey", state: "accepted"}
    ]

The question here is how do i check all the object in the array to have the same value after that service call in rspec?

example in rspec

describe 'call' do
   let(:all_users) { build(:users, 2, state: "rejected")

    service_call { UpdateAllUsers.new.call }


    it "change all user state to approved" do
         # The goal is to check all the users state after the Service call.
         # Can't find a way to do so
         # the after state should be state => 'accepted'
     end
end

解决方案

May be is too late but it could be useful if someone stumble with the same problem.

describe 'call' do
   let(:all_users) { build(:users, 2, state: "rejected")

    service_call { UpdateAllUsers.new.call }


    it "change all user state to approved" do
         # The goal is to check all the users state after the Service call.
         # Can't find a way to do so
         # the after state should be state => 'accepted'
        all_users.each do |user|
          expect(user).to include(:state => 'accepted')
        end
    end
end

这篇关于如何在服务调用后检查 rspec 中的数组更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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