Last active
December 16, 2015 07:29
-
-
Save yeehaa123/5399209 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rspec' | |
class Game | |
attr_reader :game_values | |
def initialize | |
@game_values = %w{rock paper scissors} | |
end | |
def start(guess) | |
if game_values.include? guess | |
computer_guess | |
else | |
"Not Okay" | |
end | |
end | |
def computer_guess | |
game_values.sample | |
end | |
end | |
describe Game do | |
before do | |
@game = Game.new | |
end | |
it "should only allow three input values" do | |
@game.game_values.should == %w{rock paper scissors} | |
end | |
it "should say 'Not Okay' when it gets another input value" do | |
@game.start("cup").should == "Not Okay" | |
end | |
it "should respond with one of the three game values" do | |
@game.game_values.should include(@game.start("rock")) | |
@game.game_values.should include(@game.start("paper")) | |
@game.game_values.should include(@game.start("scissors")) | |
end | |
it "should return 'computer wins' if user guesses 'rock' and computer guesses 'paper'" do | |
@game.stub(:start).and_return("paper") | |
@game.start("rock").should == "paper" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Be careful, the stub is syntactically correct but does not really test anything at the moment. Fix this, by refactoring the code!