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 completed #256

Open
wants to merge 6 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
19 changes: 17 additions & 2 deletions app.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
require 'sinatra/base'
require 'sinatra/reloader'
require './lib/player'


class RockPaperScissors < Sinatra::Base
get '/test' do
'test page'

get '/' do
erb :index
end

post '/names' do
$player_1 = Player.new(params[:player_1_name])
redirect '/play'
end

get '/play' do
@name1 = $player_1.name
erb :play
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Referring to play view, but erb file is play_game.erb which you'd already flagged.

end

run! if app_file == $0
end
8 changes: 8 additions & 0 deletions lib/player.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Player
attr_reader :name

def initialize(name)
@name = name
end

end
9 changes: 9 additions & 0 deletions spec/features/enter_name.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
feature 'Enter name' do
scenario 'submitting names' 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 'Hello Kev!'
end
end
11 changes: 11 additions & 0 deletions spec/features/weapon_choice.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
feature 'see weapons' do

scenario 'Player can see choice of weapons' do
sign_in_and_play

expect(page).to have_button("Rock")
expect(page).to have_button("Paper")
expect(page).to have_button("Scissors")
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_1_name, with: 'Kev'
click_button 'Submit'
end
11 changes: 11 additions & 0 deletions views/index.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<h1>Rock, Paper, Scissors</h1>
<hr>
<h2>Register for the game</h2>
<br>
<form action="/name" method="post">
<label for="players_name">
<h3>Please enter your name:</h3>
<input type="text" name="players_name">
<label>
<input type="submit" value="Submit">
</form>
11 changes: 11 additions & 0 deletions views/play_game.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<h1>Rock, Paper, Scissors</h1>
<hr>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possible line break typo?

<h2>Welcome <%= @player_name %>!</h2>
<br>
<h3>Choose Rock, Paper or Scissors:<h3>

<form action="/run_game" method="post">
<input type="Submit" name="rock-button" value="Rock">
<input type="Submit" name="paper-button" value="Paper">
<input type="Submit" name="scissor-button" value="Scissors">
</form>