|
4 | 4 | let(:game) { Game.create!(name: 'Starship Battle', slug: 'starship-battle') } |
5 | 5 |
|
6 | 6 | describe "GET show" do |
7 | | - context "url is not parametrized" do |
| 7 | + context "url is not parameterized" do |
8 | 8 | before :each do |
9 | 9 | get URI::encode("/games/#{game.name}") |
10 | 10 | end |
|
107 | 107 | end |
108 | 108 |
|
109 | 109 | context "when game is finished" do |
| 110 | + let(:rico) { Player.create!(nickname: "Rico") } |
| 111 | + let(:zim) { Player.create!(nickname: "Zim") } |
| 112 | + |
110 | 113 | before :each do |
111 | 114 | game.update(state: "finished") |
112 | | - Player.create!(nickname: "Zim", game: game) |
113 | | - Player.create!(nickname: "Rico", game: game, won: true) |
114 | 115 |
|
| 116 | + rico.update!(game: game, won: true) |
| 117 | + zim.update!(game: game, won: false) |
| 118 | + end |
| 119 | + |
| 120 | + it 'displays that game is finished' do |
115 | 121 | get "/games/#{game.to_param}" |
| 122 | + expect(response.body).to include("finished") |
| 123 | + end |
| 124 | + |
| 125 | + context 'wen signed in player won the game' do |
| 126 | + before :each do |
| 127 | + allow_any_instance_of(ApplicationController).to receive(:current_player).and_return(rico) |
| 128 | + end |
| 129 | + |
| 130 | + it 'displays that user won the game' do |
| 131 | + get "/games/#{game.to_param}" |
| 132 | + expect(response.body).to include("WON") |
| 133 | + end |
116 | 134 | end |
117 | 135 |
|
118 | | - it { expect(response.body).to include("finished") } |
| 136 | + context 'when signed in player lost the game' do |
| 137 | + before :each do |
| 138 | + allow_any_instance_of(ApplicationController).to receive(:current_player).and_return(zim) |
| 139 | + end |
| 140 | + |
| 141 | + it 'displays that user lost the game' do |
| 142 | + get "/games/#{game.to_param}" |
| 143 | + expect(response.body).to include("LOSE") |
| 144 | + end |
| 145 | + end |
119 | 146 | end |
120 | 147 | end |
121 | 148 |
|
|
0 commit comments