From 83d4a9556705446c9decf4db2050c783f73ececc Mon Sep 17 00:00:00 2001
From: HanzAkor <95639001+HanzAkor@users.noreply.github.com>
Date: Fri, 8 Jul 2022 11:55:00 +0100
Subject: [PATCH 1/4] Test to Home page
---
Gemfile | 1 +
app.rb | 2 +-
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/Gemfile b/Gemfile
index 63415039..0db781be 100644
--- a/Gemfile
+++ b/Gemfile
@@ -3,6 +3,7 @@ source 'https://rubygems.org'
ruby '3.0.2'
gem 'sinatra'
+gem
group :test do
gem 'capybara'
diff --git a/app.rb b/app.rb
index 4abb71ec..d9e69bec 100644
--- a/app.rb
+++ b/app.rb
@@ -1,7 +1,7 @@
require 'sinatra/base'
class RockPaperScissors < Sinatra::Base
get '/test' do
- 'test page'
+ 'home page'
end
run! if app_file == $0
From dd30e90a829f03556923d137988986884b5aa050 Mon Sep 17 00:00:00 2001
From: HanzAkor <95639001+HanzAkor@users.noreply.github.com>
Date: Fri, 8 Jul 2022 14:28:39 +0100
Subject: [PATCH 2/4] Created /names page
---
Gemfile | 2 +-
Gemfile.lock | 2 ++
app.rb | 23 +++++++++++++++++++++--
lib/web_helpers.rb | 6 ++++++
spec/features/test_page_spec.rb | 20 ++++++++++++++++----
views/index.erb | 16 ++++++++++++++++
views/play.erb | 13 +++++++++++++
7 files changed, 75 insertions(+), 7 deletions(-)
create mode 100644 lib/web_helpers.rb
create mode 100644 views/index.erb
create mode 100644 views/play.erb
diff --git a/Gemfile b/Gemfile
index 0db781be..68e184c3 100644
--- a/Gemfile
+++ b/Gemfile
@@ -3,7 +3,7 @@ source 'https://rubygems.org'
ruby '3.0.2'
gem 'sinatra'
-gem
+gem 'webrick'
group :test do
gem 'capybara'
diff --git a/Gemfile.lock b/Gemfile.lock
index b5673894..90098ca3 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -82,6 +82,7 @@ GEM
unicode-display_width (>= 1.1.1, < 3)
tilt (2.0.10)
unicode-display_width (1.6.1)
+ webrick (1.7.0)
xpath (3.2.0)
nokogiri (~> 1.8)
@@ -96,6 +97,7 @@ DEPENDENCIES
simplecov
simplecov-console
sinatra
+ webrick
RUBY VERSION
ruby 3.0.2p107
diff --git a/app.rb b/app.rb
index d9e69bec..ed28a15f 100644
--- a/app.rb
+++ b/app.rb
@@ -1,8 +1,27 @@
require 'sinatra/base'
class RockPaperScissors < Sinatra::Base
- get '/test' do
- 'home page'
+
+ enable :sessions
+
+ # get '/test' do
+ # 'home page'
+ # end
+
+ get '/' do
+ erb :index
+ end
+
+ post '/names' do
+ session[:player_name] = params[:player_name]
+ redirect '/play'
+ end
+
+ get '/play' do
+ @player_name = session[:player_name]
+ erb :play
end
+
+
run! if app_file == $0
end
diff --git a/lib/web_helpers.rb b/lib/web_helpers.rb
new file mode 100644
index 00000000..56674102
--- /dev/null
+++ b/lib/web_helpers.rb
@@ -0,0 +1,6 @@
+def sign_in_and_play
+ visit('/')
+ fill_in :player_1_name, with: 'Hannah'
+ fill_in :player_2_name, with: 'Dede'
+ click_button 'Submit'
+end
\ No newline at end of file
diff --git a/spec/features/test_page_spec.rb b/spec/features/test_page_spec.rb
index 5d6e8919..96b70657 100644
--- a/spec/features/test_page_spec.rb
+++ b/spec/features/test_page_spec.rb
@@ -1,6 +1,18 @@
-feature 'test page' do
- scenario 'visit test page' do
- visit '/test'
- expect(page).to have_content('test page')
+# feature 'test page' do
+# scenario 'visit test page' do
+# visit '/test'
+# expect(page).to have_content('home page')
+# end
+# end
+
+feature 'Enter name' do
+ scenario 'submitting name' do
+ # sign_in_and_play
+ visit('/')
+ fill_in :player_name, with: 'Hannah'
+ click_button 'Submit'
+ # save_and_open_page # will save the web page and open the browser to display it
+
+ expect(page).to have_content 'Hannah vs. Computer'
end
end
diff --git a/views/index.erb b/views/index.erb
new file mode 100644
index 00000000..5d56af92
--- /dev/null
+++ b/views/index.erb
@@ -0,0 +1,16 @@
+
+
+
+
+
+ Rock Paper Scissors
+ Sign in to play
+
+
+
diff --git a/views/play.erb b/views/play.erb
new file mode 100644
index 00000000..7e4b83b7
--- /dev/null
+++ b/views/play.erb
@@ -0,0 +1,13 @@
+
+
+
+
+
+ <%= @player_name %> vs. Computer
+
+
+ <%# Play %>
+
+
+
+
From 17af7b435b2e4638b3edef79d55b9e1b445ee796 Mon Sep 17 00:00:00 2001
From: HanzAkor <95639001+HanzAkor@users.noreply.github.com>
Date: Fri, 8 Jul 2022 15:57:50 +0100
Subject: [PATCH 3/4] get /result - Want to display single message
---
app.rb | 6 +++++-
lib/player.rb | 0
lib/web_helpers.rb | 6 ------
spec/features/test_page_spec.rb | 28 +++++++++++++++++++++++-----
spec/features/web_helpers.rb | 6 ++++++
spec/game_spec.rb | 0
spec/player_spec.rb | 0
spec/spec_helper.rb | 1 +
views/play.erb | 10 +++++++---
views/result.erb | 11 +++++++++++
10 files changed, 53 insertions(+), 15 deletions(-)
create mode 100644 lib/player.rb
delete mode 100644 lib/web_helpers.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/result.erb
diff --git a/app.rb b/app.rb
index ed28a15f..522ee121 100644
--- a/app.rb
+++ b/app.rb
@@ -21,7 +21,11 @@ class RockPaperScissors < Sinatra::Base
erb :play
end
-
+ get '/result' do
+ @player_name = session[:player_name]
+ @computer_play = ["Rock", "Paper", "Scissors"].sample
+ erb :result
+ end
run! if app_file == $0
end
diff --git a/lib/player.rb b/lib/player.rb
new file mode 100644
index 00000000..e69de29b
diff --git a/lib/web_helpers.rb b/lib/web_helpers.rb
deleted file mode 100644
index 56674102..00000000
--- a/lib/web_helpers.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-def sign_in_and_play
- visit('/')
- fill_in :player_1_name, with: 'Hannah'
- fill_in :player_2_name, with: 'Dede'
- click_button 'Submit'
-end
\ No newline at end of file
diff --git a/spec/features/test_page_spec.rb b/spec/features/test_page_spec.rb
index 96b70657..2234146e 100644
--- a/spec/features/test_page_spec.rb
+++ b/spec/features/test_page_spec.rb
@@ -5,14 +5,32 @@
# end
# end
+
feature 'Enter name' do
scenario 'submitting name' do
- # sign_in_and_play
- visit('/')
- fill_in :player_name, with: 'Hannah'
- click_button 'Submit'
+ sign_in_and_play
# save_and_open_page # will save the web page and open the browser to display it
-
expect(page).to have_content 'Hannah vs. Computer'
end
end
+
+feature 'Display reasults' do
+ scenario 'choose rock' do
+ sign_in_and_play
+ click_button 'Rock'
+ expect(page).to have_content 'Hannah, you chose Rock.'
+ end
+
+ scenario 'choose paper' do
+ sign_in_and_play
+ click_button 'Paper'
+ expect(page).to have_content 'Hannah, you chose Paper.'
+ end
+
+ scenario 'choose scissors' do
+ sign_in_and_play
+ click_button 'Scissors'
+ expect(page).to have_content 'Hannah, you chose Scissors.'
+ end
+end
+
diff --git a/spec/features/web_helpers.rb b/spec/features/web_helpers.rb
new file mode 100644
index 00000000..ad68c048
--- /dev/null
+++ b/spec/features/web_helpers.rb
@@ -0,0 +1,6 @@
+def sign_in_and_play
+ visit('/')
+ fill_in :player_name, with: 'Hannah'
+ # fill_in :player_2_name, with: 'Dede'
+ 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 00000000..e69de29b
diff --git a/spec/player_spec.rb b/spec/player_spec.rb
new file mode 100644
index 00000000..e69de29b
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 2177ec6a..1a164471 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -1,6 +1,7 @@
require 'capybara/rspec'
require 'simplecov'
require 'simplecov-console'
+require 'features/web_helpers'
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
SimpleCov::Formatter::Console,
diff --git a/views/play.erb b/views/play.erb
index 7e4b83b7..6c5f9cf9 100644
--- a/views/play.erb
+++ b/views/play.erb
@@ -5,9 +5,13 @@
<%= @player_name %> vs. Computer
-
- <%# Play %>
-
+ Make your selection: Rock, Paper or Scissors
+
+