Skip to content

Instantly share code, notes, and snippets.

@crguezl
Last active December 26, 2015 07:09
Show Gist options
  • Save crguezl/7113648 to your computer and use it in GitHub Desktop.
Save crguezl/7113648 to your computer and use it in GitHub Desktop.
require 'rack'
require 'rack/showexceptions'
require './lib/rps'
builder = Rack::Builder.new do
use(Rack::Session::Cookie, {:key => 'rack session',
#:domain => 'localhost',
#:path => '/', #:expire_after => 2592000,
:secret => 'change_me'})
#:key => 'rack.session',
# :domain => 'foo.com',
# :path => '/', :expire_after => 2592000,
use Rack::Static, :urls => ['/public']
use Rack::ShowExceptions
use Rack::Lint
run RockPaperScissors::App.new
end
Rack::Handler::Thin.run builder
require "test/unit"
require "rack/test"
require './lib/rps'
class TestRockPaperScissorsApp < Test::Unit::TestCase
include Rack::Test::Methods
def app
Rack::Builder.new do
run RockPaperScissors::App.new
end.to_app
end
def test_index
get "/?choice=scissors"
#puts last_response.inspect
assert last_response.ok?, "checking status"
end
def test_body
get "/?choice=scissors"
match = (last_response.body =~ / (Ouch;\s+rock\s+beats\s+scissors
| You\s+tied\s+with\s+the\s+computer
| "Nicely\s+done;\s+scissors\s+beats\s+paper")
/x)
puts "\n\tTesting body. MATCH: #{$1 || 'no match'}"
#puts "\n******\n#{last_response.body}\n********\n"
assert match
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment