Skip to content

Instantly share code, notes, and snippets.

@tarynsauer
Last active January 2, 2016 07:39
Show Gist options
  • Save tarynsauer/8271427 to your computer and use it in GitHub Desktop.
Save tarynsauer/8271427 to your computer and use it in GitHub Desktop.
require 'spec_helper'
describe 'AppController' do
describe "GET '/'" do
it "loads homepage" do
get '/'
expect(last_response).to be_ok
end
it "displays hompage content" do
get '/'
expect(last_response.body).to include("Select game options")
end
it "clears session" do
get '/', {}, { 'rack.session' => {:player_one_type => 'human' }}
rack_mock_session.cookie_jar[:player_one_type].should be_nil
end
end
describe "GET '/play'" do
it "redirects to homepage when session nil" do
get '/play'
expect(last_response.redirect?).to be_true
follow_redirect!
last_request.path.should == '/'
end
it "loads play page" do
get '/play', {}, { 'rack.session' => {
:player_one_type => 'human',
:player_two_type => 'human',
:board_size => 3,
:current_board => {
"1A"=>nil, "2A"=>'X', "3A"=>nil,
"1B"=>nil, "2B"=>nil, "3B"=>nil,
"1C"=>nil, "2C"=>nil, "3C"=>nil }
}}
expect(last_response).to be_ok
end
it "displays play page content" do
get '/play', {}, { 'rack.session' => {
:player_one_type => 'human',
:player_two_type => 'human',
:board_size => 3,
:current_board => {
"1A"=>nil, "2A"=>'X', "3A"=>nil,
"1B"=>nil, "2B"=>nil, "3B"=>nil,
"1C"=>nil, "2C"=>nil, "3C"=>nil }
}}
expect(last_response.body).to include("Make your move")
end
end
describe "POST '/move'" do
before :each do
post '/move', {"move"=>"1A"}, { 'rack.session' => {
:player_one_type => 'human',
:player_two_type => 'human',
:board_size => 3,
:current_board => {
"1A"=>nil, "2A"=>'X', "3A"=>nil,
"1B"=>nil, "2B"=>nil, "3B"=>nil,
"1C"=>nil, "2C"=>nil, "3C"=>nil } }}
end
it "adds marker to board" do
rack_mock_session.cookie_jar[:current_board] == { "1A"=>'O', "2A"=>'X', "3A"=>nil,
"1B"=>nil, "2B"=>nil, "3B"=>nil,
"1C"=>nil, "2C"=>nil, "3C"=>nil }
end
it "redirects to /play" do
follow_redirect!
last_request.path.should == '/play'
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment