Created
October 18, 2020 19:17
-
-
Save afmicc/2df97cceefbbe78cf1d5e40b0a2ab887 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def change_multiple(list, item_field, expected_changes = ->(x) { x }) | |
change_matcher = lambda { |item| | |
expected_changes.call( | |
change { item.reload[item_field] } | |
) | |
} | |
first_item = list.first | |
rest = list[1..-1] | |
first_matcher = change_matcher.call(first_item) | |
rest.inject(first_matcher) do |matcher, item| | |
matcher.and( | |
change_matcher.call(item) | |
) | |
end | |
end | |
# Example of use: | |
it 'updates the question‘s activity' do | |
expect { | |
subject | |
}.to change_multiple(Question.all, :activity_id, ->(x) { x.from(nil).to(Integer) }) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment