Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rps challenge - raphaella #2137

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
source 'https://rubygems.org'

ruby '3.0.2'
ruby '3.0.0'

gem 'sinatra'
gem 'sinatra-contrib'

group :test do
gem 'capybara'
Expand Down
12 changes: 10 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ GEM
docile (1.4.0)
mini_mime (1.1.1)
mini_portile2 (2.6.1)
multi_json (1.15.0)
mustermann (1.1.1)
ruby2_keywords (~> 0.0.1)
nokogiri (1.12.3)
Expand Down Expand Up @@ -76,6 +77,12 @@ GEM
rack (~> 2.2)
rack-protection (= 2.1.0)
tilt (~> 2.0)
sinatra-contrib (2.1.0)
multi_json
mustermann (~> 1.0)
rack-protection (= 2.1.0)
sinatra (= 2.1.0)
tilt (~> 2.0)
terminal-table (3.0.1)
unicode-display_width (>= 1.1.1, < 3)
tilt (2.0.10)
Expand All @@ -93,9 +100,10 @@ DEPENDENCIES
simplecov
simplecov-console
sinatra
sinatra-contrib

RUBY VERSION
ruby 3.0.2p107
ruby 3.0.0p0

BUNDLED WITH
2.2.26
2.3.14
31 changes: 31 additions & 0 deletions app.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require 'sinatra/base'
require 'sinatra/reloader'

class RockPaperScissors < Sinatra::Base
enable :sessions
configure :development do
register Sinatra::Reloader
end

get '/' do
erb :index
end

post '/names' do
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-202206051844324399637485.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-202206051845543141416175.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-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>
3 changes: 3 additions & 0 deletions config.ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require_relative "./app"

run RockPaperScissors
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
6 changes: 6 additions & 0 deletions spec/features/enter_player_name_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
feature 'Enter player names' do
scenario 'Player submits name' do
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
9 changes: 9 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
ENV['RACK_ENV'] = 'test'

require File.join(File.dirname(__FILE__), '..', 'app.rb')

require 'capybara'
require 'capybara/rspec'
require 'rspec'
require 'simplecov'
require 'simplecov-console'
require 'features/web_helpers'

Capybara.app = RockPaperScissors

SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
SimpleCov::Formatter::Console,
Expand Down
8 changes: 8 additions & 0 deletions views/index.erb
Original file line number Diff line number Diff line change
@@ -0,0 +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>
4 changes: 4 additions & 0 deletions views/play.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<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>