forked from nusco/scoreboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscoreboard_test.rb
66 lines (49 loc) · 1.74 KB
/
scoreboard_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
require_relative 'scoreboard'
require 'test/unit'
require 'rack/test'
ENV['RACK_ENV'] = 'test'
class HelloWorldTest < Test::Unit::TestCase
include Rack::Test::Methods
def app
Sinatra::Application
end
def setup
REDIS.del("closed")
REDIS.del("scoreboard")
end
def test_it_says_hello_world
get '/'
assert last_response.ok?
assert_match("Hell o Team!", last_response.body)
end
def test_it_can_post
post '/score', "teamName" => "Code Monkeys", "score" => "3"
post '/score', "teamName" => "Cowboy Coders", "score" => "4"
assert last_response.ok?
assert_match("<td>Code Monkeys</td><td>3</td>", last_response.body)
assert_match("<td>Cowboy Coders</td><td>4</td>", last_response.body)
end
def test_score_sorted
post '/score', "teamName" => "Code Monkeys", "score" => "3"
post '/score', "teamName" => "Cowboy Coders", "score" => "4"
assert last_response.ok?
cowboy_index = last_response.body.index "<td>Cowboy Coders</td><td>4</td>"
monkey_index = last_response.body.index "<td>Code Monkeys</td><td>3</td>"
assert(cowboy_index < monkey_index, "monkey business")
end
def test_validation
post '/score', "teamName" => "Cowboy Coders", "score" => "dfdfdf"
assert_equal 400, last_response.status
end
def test_score_winning
post '/score', "teamName" => "Cowboy Coders", "score" => "3"
post '/score', "teamName" => "Code Monkeys", "score" => "10"
assert last_response.ok?
assert_match("Code Monkeys Wins!", last_response.body)
end
def test_closed
post '/score', "teamName" => "Cowboy Coders", "score" => "10"
post '/score', "teamName" => "Code Monkeys", "score" => "10"
assert_equal 405, last_response.status
end
end