samedi 1 octobre 2016

ruby and rspec - Failing test

I am supposed to make this test pass.

describe 'new' do
    it "takes a parameter and returns a HangpersonGame object" do      
      @hangpersonGame = HangpersonGame.new('glorp')
      expect(@hangpersonGame).to be_an_instance_of(HangpersonGame)
      expect(@hangpersonGame.word).to eq('glorp')
      expect(@hangpersonGame.guesses).to eq('')
      expect(@hangpersonGame.wrong_guesses).to eq('')
    end
  end

My code is this,

class HangpersonGame


    attr_accessor :word
    attr_accessor :guesses
    attr_accessor :wrong_guesses

  def initialize(word)
    @word = word
    @guesses = nil
    @wrong_guesses = nil

  end
end

The test is failing. Why? I have run the code seperately and it seems to work.

Aucun commentaire:

Enregistrer un commentaire