0

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
1
  • 1
    @code == @guess is what you need (and you already have it). What's the question then? Commented Feb 3, 2017 at 14:19

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.