Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require 'sinatra/reloader'

class RockPaperScissors < Sinatra::Base
enable :sessions
configure :development do
register Sinatra::Reloader
end
Expand All @@ -11,9 +12,20 @@ class RockPaperScissors < Sinatra::Base
end

post '/names' do
@player_name = params[:player_name]
session[:player_name] = params[:player_name]
redirect '/play'
end

get '/play' do
player = Player.new(session[:player_name])
$game = Game.new()
erb :play
end

post '/weapon_selection' do
@player_weapon = params[:weapon]
erb :weapon
end

run! if app_file == $0
end
1 change: 1 addition & 0 deletions capybara-202206051848375381777213.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div>Player: Raphaella</div>
1 change: 1 addition & 0 deletions capybara-202206051853567196877204.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div>Player: </div>
1 change: 1 addition & 0 deletions capybara-202206051948349999865139.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div> selected Rock </div>
1 change: 1 addition & 0 deletions capybara-202206051952116251524656.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div> selected Rock </div>
1 change: 1 addition & 0 deletions capybara-202206052001351811768539.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div> selected Rock </div>
5 changes: 5 additions & 0 deletions lib/choose_weapon.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class ChooseWeapon



end
4 changes: 4 additions & 0 deletions lib/game.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Game


end
10 changes: 10 additions & 0 deletions lib/player.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Player
def initialize(name)
@name = name
end

def name
@name
end

end
4 changes: 1 addition & 3 deletions spec/features/enter_player_name_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
feature 'Enter player names' do
scenario 'Player submits name' do
visit('/')
fill_in :player_name, with: 'Raphaella'
click_button 'Submit'
sign_in_and_play()
expect(page).to have_content 'Player: Raphaella'
end
end
10 changes: 10 additions & 0 deletions spec/features/single_player_game_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
feature 'single player game' do
xscenario 'player selects rock' do
visit('/')
fill_in :player_name, with: 'Raphaella'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test is comprehensive, and understandable. I just wonder whether you could use the web_helper 'sign in and play' here instead of fill_in[...]?

click_button 'Submit'
click_button 'Rock'
save_and_open_page
expect(page).to have_content 'Raphaella selected Rock'
end
end
5 changes: 5 additions & 0 deletions spec/features/web_helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def sign_in_and_play()
visit('/')
fill_in :player_name, with: 'Raphaella'
click_button 'Submit'
end
11 changes: 11 additions & 0 deletions spec/game_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'game'

RSpec.describe Game do
it 'returns player name' do
player = Player.new(double(:name))
expect(player.name).to eq player.name
end



end
8 changes: 8 additions & 0 deletions spec/player_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'player'

RSpec.describe Player do
it 'returns name' do
player = Player.new(double(:name))
expect(player.name).to eq player.name
end
end
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
require 'rspec'
require 'simplecov'
require 'simplecov-console'
require 'features/web_helpers'

Capybara.app = RockPaperScissors

Expand Down
4 changes: 4 additions & 0 deletions views/index.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<h1>Rock Paper Scissors</h1>
<h2>Enter your name to play</h2>
<form action='/names' method='post'>
<label for='player_name'>
<input type='text' name='player_name'>
</label>
<input type='submit' value='Submit'>
</form>
5 changes: 4 additions & 1 deletion views/play.erb
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
<div>Player: <%= @player_name %></div>
<div>Player: <%= @player.name %></div>
<form action='/weapon_selection' method='post'>
<input type='submit' value='Rock' name='weapon'>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is really nice, I am going to try implement something in my own code.

</form>
1 change: 1 addition & 0 deletions views/weapon.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div><%= @player.name %> selected <%= Rock %> </div>