如果之前有人问过,请道歉。我正在尝试使用oop制作游戏策划者。该类的目的是检查两个实例变量(代码和猜测)是否相等。如何设置实例变量以进行测试?谢谢!
class MastermindCodechecker
def initialize(code, guess)
@code = code
@guess = guess
end
def check?
# return true if @code == @guess
end
end
答案 0 :(得分:2)
RSpec.describe 'MastermindCodechecker' do
describe '#check?' do
context 'when code and guess are different' do
@foo = MastermindCodechecker.new('bar', 'baz')
it 'returns false after check' do
expect(@foo.check?).to eq false
end
end
context 'when code and guess are equal' do
@foo = MastermindCodechecker.new('bar', 'bar')
it 'returns true after check' do
expect(@foo.check?).to eq true
end
end
end
end