как проверить изменения массива в rspe c после вызова службы? - PullRequest
2 голосов
/ 18 июня 2020

Цель проста

Например, у нас есть массив

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

После выполнения вызова службы UpdateAllUsers он изменит всех пользователей на 'accepted'

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

Вопрос в том, как мне проверить, чтобы все объекты в массиве имели одинаковое значение после этого вызова службы в rspe c?

пример в rspe c

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

1 Ответ

0 голосов
/ 12 июля 2020

Возможно, уже слишком поздно, но это может быть полезно, если кто-то столкнется с той же проблемой.

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
...