我正在尝试使用测试驱动开发创建游戏Mastermind。我在解决如何通过这个特定测试时遇到了问题:
it "should valiate secret contains four accepted uppercase characters" do
@game.secret = "XXXX"
secret = "RRRR"
valid1 = @game.checksecret(secret)
valid2 = check_valid(secret)
valid1.should == valid2 && @game.secret.should == secret && valid1.should == 0
end
这是我目前的代码:
def checksecret(secret)
secret = "RRRR"
valid1 = secret
valid2 = check_valid(secret)
valid1.should == valid2 && secret.should == secret && valid1.should == 0
end
这是我收到的错误消息。
1) OXs_Game::Game#Mastermind game should valiate secret contains four accepted uppercase characters
Failure/Error: @game.secret = secret
NoMethodError:
undefined method `secret=' for nil:NilClass
# ./wad_mastermind_spec_01.rb:13:in `check_valid'
# ./wad_mastermind_gen_01.rb:61:in `checksecret'
# ./wad_mastermind_spec_01.rb:92:in `block (3 levels) in <module:OXs_Game>'
我觉得我试图以错误的方式解决它,但无法弄清楚我应该如何解决问题。