bonkers31
bonkers31

Reputation: 1

testing instance variable equivalence (RSpec)

Apologies if this has been asked before. I'm trying to make the game mastermind using oop. The aim of the class is to check if two instance variables (a code and a guess) are equal or not. How do I set the instance variables in order to test this? Thanks!

class MastermindCodechecker
  def initialize(code, guess)
    @code = code
    @guess = guess
  end

  def check?
    # return true if @code == @guess
  end
end

Upvotes: 0

Views: 56

Answers (1)

Andrey Deineko
Andrey Deineko

Reputation: 52357

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

Upvotes: 2

Related Questions