Skip to content

Commit

Permalink
Add test for logging in warm up round
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwynne committed Sep 29, 2011
1 parent 484884d commit d8335e0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
10 changes: 10 additions & 0 deletions features/step_definitions/steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,13 @@
score_for(row['player']).should == row['score'].to_i
end
end

Then /^the log for (\w+) should show:$/ do |player_name, table|
player = players.find{ |p| p.name == player_name }
visit player.personal_page
actual = page.all('li').map do |li|
li.all('div').map do |div|
div.text
end
end
end
4 changes: 4 additions & 0 deletions features/support/testing_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module TestingApi

class TestablePlayer
attr_reader :url, :name
attr_accessor :personal_page

def initialize(name, content)
@name, @content = name, content
Expand Down Expand Up @@ -58,6 +59,9 @@ def create_player(name, content)

def enter_player(player)
post '/players', :name => player.name, :url => player.url
doc = Nokogiri.parse(last_response.body)
personal_page_link = doc.css('a').first
player.personal_page = personal_page_link['href']
end

def stub_correct_answer_to_be(correct_answer, points_awarded = 1)
Expand Down
2 changes: 2 additions & 0 deletions features/warm_up.feature
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ Feature: Warm up
Then the scores should be:
| player | score |
| bob | 10 |
And the log for bob should show:
| result: correct | points awarded: 10 |
8 changes: 6 additions & 2 deletions lib/extreme_startup/web_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,13 @@ def to_json(*a)
get '/graph' do
haml :scores
end

get %r{/players/([\w]+)} do |uuid|
haml :personal_page, :locals => { :name => players[uuid].name, :playerid => uuid, :score => scoreboard.scores[uuid], :log => players[uuid].log[0..25] }
haml :personal_page, :locals => {
:name => players[uuid].name,
:playerid => uuid,
:score => scoreboard.scores[uuid],
:log => players[uuid].log[0..25] }
end

get '/players' do
Expand Down

0 comments on commit d8335e0

Please sign in to comment.