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
Oliver Peate 7722017bc7 Adjust use_parent_strategy safely in specs
Uses a block-based helper so we can remove a global around hook.
2019-08-12 18:54:53 +01:00

14 lines
407 B
Ruby

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