1
0
Fork 0
mirror of https://github.com/thoughtbot/factory_bot.git synced 2022-11-09 11:43:51 -05:00
thoughtbot--factory_bot/spec/support/macros/temporary_assignment.rb

15 lines
407 B
Ruby
Raw Permalink Normal View History

module TemporaryAssignment
def with_temporary_assignment(assignee, attribute, temporary_value)
original_value = assignee.public_send(attribute)
attribute_setter = "#{attribute}="
assignee.public_send(attribute_setter, temporary_value)
yield
ensure
assignee.public_send(attribute_setter, original_value)
end
end
RSpec.configure do |config|
config.include TemporaryAssignment
end