无法通过RSpec中的测试

时间:2019-03-05 17:25:33

标签: ruby rspec

it "should set token of player 1 to X" do
            @game.setplayer1
            @game.player1.should eql "X"
        end

我的方法

def setplayer1
        @output.player1.eql? "X"        
    end¨

我仍然很期待:

  Failure/Error: @game.player1.should eql "X"

   expected: "X"
        got: nil

我不知道问题出在哪里,为什么它没有通过测试。

1 个答案:

答案 0 :(得分:1)

您的setplayer1实际上没有将player1设置为任何值,因此当您访问它时,它仍然为零。

请注意,更优选使用<attribute_name>=而不是set_<attribute_name>作为设置方法。请注意,您可以使用attr_accessor生成简单的getter和setter,有关更多详细信息,请参见What is attr_accessor in Ruby?

相关问题