From aa48c421261174cabb1d673895f5a127331aa57f Mon Sep 17 00:00:00 2001 From: Raphaella Date: Sun, 5 Jun 2022 15:11:46 +0100 Subject: [PATCH 1/3] file set-up --- Gemfile | 3 ++- Gemfile.lock | 12 ++++++++++-- app.rb | 14 ++++++++++++++ config.ru | 3 +++ spec/spec_helper.rb | 8 ++++++++ 5 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 app.rb create mode 100644 config.ru diff --git a/Gemfile b/Gemfile index 63415039a7..f7804e91f1 100644 --- a/Gemfile +++ b/Gemfile @@ -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' diff --git a/Gemfile.lock b/Gemfile.lock index 5afab6d697..3e7a688ea4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -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) @@ -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 diff --git a/app.rb b/app.rb new file mode 100644 index 0000000000..df57bd5931 --- /dev/null +++ b/app.rb @@ -0,0 +1,14 @@ +require 'sinatra/base' +require 'sinatra/reloader' + +class RockPaperScissors < Sinatra::Base + configure :development do + register Sinatra::Reloader + end + + get '/' do + 'Hello World' + end + + run! if app_file == $0 +end \ No newline at end of file diff --git a/config.ru b/config.ru new file mode 100644 index 0000000000..79e4b1893a --- /dev/null +++ b/config.ru @@ -0,0 +1,3 @@ +require_relative "./app" + +run RockPaperScissors \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 11a50a94e5..c801f5fdcd 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,7 +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' +Capybara.app = RockPaperScissors + SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([ SimpleCov::Formatter::Console, # Want a nice code coverage website? Uncomment this next line! From 231bcce561eee980e83b4b47bceb3caa499d1c4b Mon Sep 17 00:00:00 2001 From: Raphaella Date: Sun, 5 Jun 2022 18:46:22 +0100 Subject: [PATCH 2/3] player can enter their name and see it on screen --- app.rb | 7 ++++++- capybara-202206051844324399637485.html | 1 + capybara-202206051845543141416175.html | 1 + spec/features/enter_player_name_spec.rb | 8 ++++++++ views/index.erb | 4 ++++ views/play.erb | 1 + 6 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 capybara-202206051844324399637485.html create mode 100644 capybara-202206051845543141416175.html create mode 100644 spec/features/enter_player_name_spec.rb create mode 100644 views/index.erb create mode 100644 views/play.erb diff --git a/app.rb b/app.rb index df57bd5931..1ddd3176bc 100644 --- a/app.rb +++ b/app.rb @@ -7,7 +7,12 @@ class RockPaperScissors < Sinatra::Base end get '/' do - 'Hello World' + erb :index + end + + post '/names' do + @player_name = params[:player_name] + erb :play end run! if app_file == $0 diff --git a/capybara-202206051844324399637485.html b/capybara-202206051844324399637485.html new file mode 100644 index 0000000000..9b0a56b8e1 --- /dev/null +++ b/capybara-202206051844324399637485.html @@ -0,0 +1 @@ +
Player: Raphaella
diff --git a/capybara-202206051845543141416175.html b/capybara-202206051845543141416175.html new file mode 100644 index 0000000000..9b0a56b8e1 --- /dev/null +++ b/capybara-202206051845543141416175.html @@ -0,0 +1 @@ +
Player: Raphaella
diff --git a/spec/features/enter_player_name_spec.rb b/spec/features/enter_player_name_spec.rb new file mode 100644 index 0000000000..7f7f25d4d2 --- /dev/null +++ b/spec/features/enter_player_name_spec.rb @@ -0,0 +1,8 @@ +feature 'Enter player names' do + scenario 'Player submits name' do + visit('/') + fill_in :player_name, with: 'Raphaella' + click_button 'Submit' + expect(page).to have_content 'Player: Raphaella' + end +end \ No newline at end of file diff --git a/views/index.erb b/views/index.erb new file mode 100644 index 0000000000..858f255a85 --- /dev/null +++ b/views/index.erb @@ -0,0 +1,4 @@ +
+ + +
\ No newline at end of file diff --git a/views/play.erb b/views/play.erb new file mode 100644 index 0000000000..8e426f315a --- /dev/null +++ b/views/play.erb @@ -0,0 +1 @@ +
Player: <%= @player_name %>
From 192de5a58fc08362e886b514796e3961d380d57d Mon Sep 17 00:00:00 2001 From: Raphaella Date: Mon, 6 Jun 2022 10:41:55 +0100 Subject: [PATCH 3/3] everything i've done so far --- app.rb | 14 +++++++++++++- capybara-202206051848375381777213.html | 1 + capybara-202206051853567196877204.html | 1 + capybara-202206051948349999865139.html | 1 + capybara-202206051952116251524656.html | 1 + capybara-202206052001351811768539.html | 1 + lib/choose_weapon.rb | 5 +++++ lib/game.rb | 4 ++++ lib/player.rb | 10 ++++++++++ spec/features/enter_player_name_spec.rb | 4 +--- spec/features/single_player_game_spec.rb | 10 ++++++++++ spec/features/web_helpers.rb | 5 +++++ spec/game_spec.rb | 11 +++++++++++ spec/player_spec.rb | 8 ++++++++ spec/spec_helper.rb | 1 + views/index.erb | 4 ++++ views/play.erb | 5 ++++- views/weapon.erb | 1 + 18 files changed, 82 insertions(+), 5 deletions(-) create mode 100644 capybara-202206051848375381777213.html create mode 100644 capybara-202206051853567196877204.html create mode 100644 capybara-202206051948349999865139.html create mode 100644 capybara-202206051952116251524656.html create mode 100644 capybara-202206052001351811768539.html create mode 100644 lib/choose_weapon.rb create mode 100644 lib/game.rb create mode 100644 lib/player.rb create mode 100644 spec/features/single_player_game_spec.rb create mode 100644 spec/features/web_helpers.rb create mode 100644 spec/game_spec.rb create mode 100644 spec/player_spec.rb create mode 100644 views/weapon.erb diff --git a/app.rb b/app.rb index 1ddd3176bc..a0b716e220 100644 --- a/app.rb +++ b/app.rb @@ -2,6 +2,7 @@ require 'sinatra/reloader' class RockPaperScissors < Sinatra::Base + enable :sessions configure :development do register Sinatra::Reloader end @@ -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 \ No newline at end of file diff --git a/capybara-202206051848375381777213.html b/capybara-202206051848375381777213.html new file mode 100644 index 0000000000..9b0a56b8e1 --- /dev/null +++ b/capybara-202206051848375381777213.html @@ -0,0 +1 @@ +
Player: Raphaella
diff --git a/capybara-202206051853567196877204.html b/capybara-202206051853567196877204.html new file mode 100644 index 0000000000..ee16fe1f6c --- /dev/null +++ b/capybara-202206051853567196877204.html @@ -0,0 +1 @@ +
Player:
diff --git a/capybara-202206051948349999865139.html b/capybara-202206051948349999865139.html new file mode 100644 index 0000000000..a942b9c2d8 --- /dev/null +++ b/capybara-202206051948349999865139.html @@ -0,0 +1 @@ +
selected Rock
\ No newline at end of file diff --git a/capybara-202206051952116251524656.html b/capybara-202206051952116251524656.html new file mode 100644 index 0000000000..a942b9c2d8 --- /dev/null +++ b/capybara-202206051952116251524656.html @@ -0,0 +1 @@ +
selected Rock
\ No newline at end of file diff --git a/capybara-202206052001351811768539.html b/capybara-202206052001351811768539.html new file mode 100644 index 0000000000..a942b9c2d8 --- /dev/null +++ b/capybara-202206052001351811768539.html @@ -0,0 +1 @@ +
selected Rock
\ No newline at end of file diff --git a/lib/choose_weapon.rb b/lib/choose_weapon.rb new file mode 100644 index 0000000000..6cae09c25a --- /dev/null +++ b/lib/choose_weapon.rb @@ -0,0 +1,5 @@ +class ChooseWeapon + + + +end \ No newline at end of file diff --git a/lib/game.rb b/lib/game.rb new file mode 100644 index 0000000000..7d1503302a --- /dev/null +++ b/lib/game.rb @@ -0,0 +1,4 @@ +class Game + + +end \ No newline at end of file diff --git a/lib/player.rb b/lib/player.rb new file mode 100644 index 0000000000..a2d0be8b0d --- /dev/null +++ b/lib/player.rb @@ -0,0 +1,10 @@ +class Player + def initialize(name) + @name = name + end + + def name + @name + end + +end \ No newline at end of file diff --git a/spec/features/enter_player_name_spec.rb b/spec/features/enter_player_name_spec.rb index 7f7f25d4d2..42db99dcc3 100644 --- a/spec/features/enter_player_name_spec.rb +++ b/spec/features/enter_player_name_spec.rb @@ -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 \ No newline at end of file diff --git a/spec/features/single_player_game_spec.rb b/spec/features/single_player_game_spec.rb new file mode 100644 index 0000000000..76c4ccff80 --- /dev/null +++ b/spec/features/single_player_game_spec.rb @@ -0,0 +1,10 @@ +feature 'single player game' do + xscenario 'player selects rock' do + visit('/') + fill_in :player_name, with: 'Raphaella' + click_button 'Submit' + click_button 'Rock' + save_and_open_page + expect(page).to have_content 'Raphaella selected Rock' + end +end \ No newline at end of file diff --git a/spec/features/web_helpers.rb b/spec/features/web_helpers.rb new file mode 100644 index 0000000000..8f51e6671b --- /dev/null +++ b/spec/features/web_helpers.rb @@ -0,0 +1,5 @@ +def sign_in_and_play() + visit('/') + fill_in :player_name, with: 'Raphaella' + click_button 'Submit' +end \ No newline at end of file diff --git a/spec/game_spec.rb b/spec/game_spec.rb new file mode 100644 index 0000000000..249636a288 --- /dev/null +++ b/spec/game_spec.rb @@ -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 \ No newline at end of file diff --git a/spec/player_spec.rb b/spec/player_spec.rb new file mode 100644 index 0000000000..6cd926850f --- /dev/null +++ b/spec/player_spec.rb @@ -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 \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c801f5fdcd..2b903fc2fb 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -7,6 +7,7 @@ require 'rspec' require 'simplecov' require 'simplecov-console' +require 'features/web_helpers' Capybara.app = RockPaperScissors diff --git a/views/index.erb b/views/index.erb index 858f255a85..b8ebe8cc38 100644 --- a/views/index.erb +++ b/views/index.erb @@ -1,4 +1,8 @@ +

Rock Paper Scissors

+

Enter your name to play

+
\ No newline at end of file diff --git a/views/play.erb b/views/play.erb index 8e426f315a..8c857a949c 100644 --- a/views/play.erb +++ b/views/play.erb @@ -1 +1,4 @@ -
Player: <%= @player_name %>
+
Player: <%= @player.name %>
+
+ +
diff --git a/views/weapon.erb b/views/weapon.erb new file mode 100644 index 0000000000..fe5d27b2f4 --- /dev/null +++ b/views/weapon.erb @@ -0,0 +1 @@ +
<%= @player.name %> selected <%= Rock %>
\ No newline at end of file