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

First Commit #258

Open
wants to merge 1 commit 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ source 'https://rubygems.org'
ruby '3.0.2'

gem 'sinatra'

gem 'sinatra/base'
gem 'sinatra-contrib'
group :test do
gem 'capybara'
gem 'rspec'
Expand All @@ -14,3 +15,9 @@ end
group :development, :test do
gem 'rubocop', '1.20'
end

gem "webrick", "~> 1.7"

gem "sinatra-contrib", "~> 2.1"

gem "rack", "~> 2.2"
14 changes: 14 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ 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)
mini_portile2 (~> 2.6.1)
racc (~> 1.4)
nokogiri (1.12.3-arm64-darwin)
racc (~> 1.4)
nokogiri (1.12.3-x86_64-darwin)
racc (~> 1.4)
parallel (1.20.1)
Expand Down Expand Up @@ -78,24 +81,35 @@ 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)
unicode-display_width (1.6.1)
webrick (1.7.0)
xpath (3.2.0)
nokogiri (~> 1.8)

PLATFORMS
arm64-darwin-21
ruby
x86_64-darwin-20

DEPENDENCIES
capybara
rack (~> 2.2)
rspec
rubocop (= 1.20)
simplecov
simplecov-console
sinatra
sinatra-contrib (~> 2.1)
webrick (~> 1.7)

RUBY VERSION
ruby 3.0.2p107
Expand Down
26 changes: 23 additions & 3 deletions app.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
require 'sinatra/base'
require 'sinatra/reloader'

Copy link

Choose a reason for hiding this comment

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

need a require './lib/player'

class RockPaperScissors < Sinatra::Base
get '/test' do
'test page'
set :sessions, true
configure :development do
register Sinatra::Reloader
end
get '/' do
"hey"
end
Copy link

Choose a reason for hiding this comment

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

may need to introduce erb (:index) here so that the user can move forward onto next page


post '/names' do
$player1 = Player.new(params[:Player1])
$player2 = Player.new(params[:Player2])
redirect '/play'
end

get '/play' do
@player1 = $player1.name
@player2 = $player1.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.

does :play need to be in brackets?

end

run! if app_file == $0

run! if app_file == $0

end
2 changes: 1 addition & 1 deletion config.ru
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
require_relative './app'
require_relative './app.rb'
run RockPaperScissors
9 changes: 9 additions & 0 deletions lib/player.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Player
def initialize(name)
@name = name
end

def name
return name
end
end
Copy link

Choose a reason for hiding this comment

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

single responsibility principle seems good here

9 changes: 9 additions & 0 deletions spec/features/player_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'player'
RSpec.desribe Player do
context "initially" do
it "returns a name" do
player = Player.new("Ronan")
expect( player.name ).to eq "Ronan"
end
end
end
Copy link

Choose a reason for hiding this comment

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

test is easy to understand

12 changes: 6 additions & 6 deletions spec/features/test_page_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
feature 'test page' do
scenario 'visit test page' do
visit '/test'
expect(page).to have_content('test page')
end
end
# feature 'test page' do
# scenario 'visit test page' do
# visit '/test'
# expect(page).to have_content('test page')
# end
# end
13 changes: 11 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
require 'capybara'
require 'capybara/rspec'
require 'simplecov'
require 'simplecov-console'
require 'rspec'
require './app.rb'


SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
SimpleCov::Formatter::Console,
Expand All @@ -10,8 +14,13 @@
SimpleCov.start

# For accurate test coverage measurements, require your code AFTER 'SimpleCov.start'

ENV['RACK_ENV'] = 'test'
require 'capybara'
require 'capybara/rspec'
require 'simplecov'
require 'simplecov-console'
require 'rspec'
require './app.rb'
ENV['RACK_ENV']="test"

require File.join(File.dirname(__FILE__), '..', 'app.rb')
Capybara.app = RockPaperScissors
Expand Down
16 changes: 16 additions & 0 deletions views.rb/index.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

<form action='/' method="post">
<ul>
<li>
<label for="Player1">Player 1</label>
<input type="text" id="Player1" name="Player1">
</li>
<li>
<label for="Player2">Player 2</label>
<input type="text" id="Player2" name="Player2">
</li>a
<li>
<input type="submit" value="Submit">
</li>
</ul>
</form>
Copy link

Choose a reason for hiding this comment

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

nicely formatted html (with the indentations and stuff)

11 changes: 11 additions & 0 deletions views.rb/play.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<h1>
<%= "#{@player1} vs #{@player2}" %>
</h1>

<h1>
<%= "#{@player1}, youre fighting #{@player2} who has 10hp remaining!" %>
</h1>

<form action='/attack' method="get">
<input type="submit" value="Attack">
</form>