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..a0b716e220 --- /dev/null +++ b/app.rb @@ -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 \ No newline at end of file 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/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/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/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 new file mode 100644 index 0000000000..42db99dcc3 --- /dev/null +++ b/spec/features/enter_player_name_spec.rb @@ -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 \ 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 11a50a94e5..2b903fc2fb 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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, diff --git a/views/index.erb b/views/index.erb new file mode 100644 index 0000000000..b8ebe8cc38 --- /dev/null +++ b/views/index.erb @@ -0,0 +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 new file mode 100644 index 0000000000..8c857a949c --- /dev/null +++ b/views/play.erb @@ -0,0 +1,4 @@ +
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