Skip to content

Instantly share code, notes, and snippets.

@yeehaa123
Last active December 16, 2015 07:29
Show Gist options
  • Save yeehaa123/5399209 to your computer and use it in GitHub Desktop.
Save yeehaa123/5399209 to your computer and use it in GitHub Desktop.
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
@yeehaa123
Copy link
Author

Be careful, the stub is syntactically correct but does not really test anything at the moment. Fix this, by refactoring the code!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment