Using instance_variable_set in testing
rlmoser99 opened this issue · comments
In #ruby-testing I have been told to use instance_variable_set
and I have been told that it is a code smell. Is it a code smell when used only in testing?
An an example, is it better to add guess as a parameter, so that one can create a new instance of game for tests subject(:game) { described_class.new(0, 9, 4) }
def initialize(min, max, guess = nil)
@min = min
@max = max
@guess = guess
end
Or is it better to have two arguments and to use game.instance_variable_set(:@guess, 4)
in the tests that require a value for @guess
?
def initialize(min, max)
@min = min
@max = max
@guess = nil
end