-
Notifications
You must be signed in to change notification settings - Fork 250
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
Test to Home page #251
base: main
Are you sure you want to change the base?
Test to Home page #251
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ source 'https://rubygems.org' | |
ruby '3.0.2' | ||
|
||
gem 'sinatra' | ||
gem 'webrick' | ||
|
||
group :test do | ||
gem 'capybara' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,35 @@ | ||
require 'sinatra/base' | ||
|
||
|
||
class RockPaperScissors < Sinatra::Base | ||
get '/test' do | ||
'test 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' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this be done without /names? Maybe in /play instead to save having to redirect the user? |
||
end | ||
|
||
get '/play' do | ||
@player_name = session[:player_name] | ||
erb :play | ||
end | ||
|
||
get '/result' do | ||
@player_name = session[:player_name] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indentation needs fixing |
||
erb :result | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before this, you should access the button/input value from the user (rock, paper or scissors). You could then sample the three choices for the computer, and work out a result before returning to the Result page. |
||
end | ||
|
||
|
||
|
||
|
||
run! if app_file == $0 | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,36 @@ | ||
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 | ||
# 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, the results are in!' | ||
end | ||
|
||
scenario 'choose paper' do | ||
sign_in_and_play | ||
click_button 'Paper' | ||
expect(page).to have_content 'Hannah, the results are in!' | ||
end | ||
|
||
scenario 'choose scissors' do | ||
sign_in_and_play | ||
click_button 'Scissors' | ||
expect(page).to have_content 'Hannah, the results are in!' | ||
end | ||
end | ||
|
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: 'Hannah' | ||
click_button 'Submit' | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!DOCTYPE html> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. HTML structure isn't required for ERB files to work |
||
<html> | ||
<head> | ||
</head> | ||
<body> | ||
<h1>Rock Paper Scissors</h1> | ||
<h2>Sign in to play</h2> | ||
<form action="/names" method="post"> | ||
<label for="player_name"> | ||
Enter name | ||
<input type="text" name="player_name"> | ||
</label> | ||
<input type="submit" value="Submit"> | ||
</form> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
</head> | ||
<body> | ||
<%= @player_name %> vs. Computer | ||
|
||
<p>Make your selection: Rock, Paper or Scissors</p> | ||
|
||
<form action="/result" method="get" class="rps"> | ||
<input type="submit" value="Rock"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe a button might be more helpful - "Input" does take a value but it might be more useful. Button requires a name, which can then be accessed by app.rb |
||
<input type="submit" value="Paper"> | ||
<input type="submit" value="Scissors"> | ||
</form> | ||
|
||
|
||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
</head> | ||
<body> | ||
<%= @player_name %>, the results are in! | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs results |
||
</body> | ||
</html> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation isn't in line with rest of code