spec/warcards/gameplay_spec.rb in warcards-0.0.3 vs spec/warcards/gameplay_spec.rb in warcards-0.0.5

- old
+ new

@@ -1,13 +1,13 @@ require_relative '../spec_helper' module Cardgame describe Gameplay do def setup - @deck = Deck.new - @player = Player.new - @ai = Ai.new + @deck = Deck.new + @player = Player.new + @ai = Ai.new @gameplay = Gameplay.new(:deck => @deck, :player => @player, :ai => @ai) end it "can create a new game" do @gameplay.must_be_instance_of Gameplay @@ -33,13 +33,13 @@ end describe "dealt deck" do def setup - @deck = Deck.new - player = Player.new - ai = Ai.new + @deck = Deck.new + player = Player.new + ai = Ai.new @gameplay = Gameplay.new(:deck => @deck, :player => player, :ai => ai) @gameplay.shuffle @gameplay.deal end @@ -100,13 +100,14 @@ end end describe "#war" do it "must play war when there is a draw" do - card_ai_1 = (Card.new(:suit => :clubs, :value => 5)) - card_ai_2 = (Card.new(:suit => :spades, :value => 4)) - card_ai_3 = (Card.new(:suit => :clubs, :value => 4)) + output = StringIO.new("") + card_ai_1 = (Card.new(:suit => :clubs, :value => 5)) + card_ai_2 = (Card.new(:suit => :spades, :value => 4)) + card_ai_3 = (Card.new(:suit => :clubs, :value => 4)) card_player_1 = (Card.new(:suit => :hearts, :value => 4)) card_player_2 = (Card.new(:suit => :diamonds, :value => 4)) card_player_3 = (Card.new(:suit => :hearts, :value => 4)) @gameplay.ai.stack.clear << card_ai_1 @gameplay.ai.stack << card_ai_2 @@ -114,11 +115,11 @@ @gameplay.player.stack.clear << card_player_1 @gameplay.player.stack << card_player_2 @gameplay.player.stack << card_player_3 @gameplay.show_cards - @gameplay.war? + @gameplay.war?(output) result = @gameplay.contest result[:ai_cards].must_be_instance_of Array result[:ai_cards].last.must_be_instance_of Card [card_ai_1, card_ai_2, card_ai_3].each { |card| result[:ai_cards].must_include card } @@ -158,28 +159,28 @@ end end describe "#game_over?" do def setup - @deck = Deck.new - player = Player.new - ai = Ai.new + @deck = Deck.new + player = Player.new + ai = Ai.new @gameplay = Gameplay.new(:deck => @deck, :player => player, :ai => ai) @gameplay.ai.stack.clear << (Card.new(:suit => :clubs, :value => 2)) @gameplay.ai.stack << (Card.new(:suit => :hearts, :value => 1)) @gameplay.player.stack.clear << (Card.new(:suit => :clubs, :value => 12)) @gameplay.player.stack << (Card.new(:suit => :hearts, :value => 11)) end it "must end the game when a participant is out of cards" do - skip "you'll need to mock stdout and stderr first. Of course you'll have to learn how before doing that." 2.times do + @gameplay.game_over? @gameplay.show_cards @gameplay.discard(@gameplay.contest) end - lambda do - @gameplay.game_over? - end.must_output(STDOUT, STDERR) {"Game Over"; exit} + @gameplay.game_over? + @gameplay.game_over?[:over?].must_equal true end end + end end \ No newline at end of file