Skip to content

Commit

Permalink
Added tests for POST '/make_move' and GET '/game_over'
Browse files Browse the repository at this point in the history
  • Loading branch information
lisahamm committed Mar 12, 2015
1 parent 3e60d09 commit de4625d
Showing 1 changed file with 39 additions and 5 deletions.
44 changes: 39 additions & 5 deletions spec/tic_tac_toe_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,46 @@ def app
"current_player_mark" => "X",
"moves" => [nil, nil, nil, nil, nil, nil, nil, nil, nil]}}
expect(last_response).to be_ok
expect(last_response.status).to eq 200
end
end
# it "starts the game" do
# post "/setup", player_mark: "X", computer_opponent: "yes"
# expect(last_response).to be_redirect

#expect(session[:mark]).to eq "O"
# end
describe "POST /make_move" do
before :each do
post '/make_move', {:move => '0'}, {'rack.session' => {
"computer_opponent" => nil,
"player1_mark" => "X",
"player2_mark" => "O",
"current_player_mark" => "X",
"moves" => [nil, nil, nil, nil, nil, nil, nil, nil, nil]}}

end

it "adds the player's mark to the board" do
rack_mock_session.cookie_jar[:moves] == ["X", nil, nil, nil, nil, nil, nil, nil, nil]
end

it "redirects to /game" do
expect(last_response.redirect?).to eq true
follow_redirect!
expect(last_request.path).to eq '/game'
end
end

describe "GET /game_over" do
before :each do
get '/game_over', {}, {'rack.session' => {
"computer_opponent" => nil,
"player1_mark" => "X",
"player2_mark" => "O",
"current_player_mark" => "X",
"moves" => ["X", "X", "X", "O", "O", nil, nil, nil, nil]}}
end

it "loads the game over message" do
expect(last_response).to be_ok
expect(last_response.status).to eq 200
expect(last_response.body).to include "Result: Player X wins"
end
end
end

0 comments on commit de4625d

Please sign in to comment.