Skip to content

Commit

Permalink
User story 1: added config.ru file and ENV[RACK_ENV] = test
Browse files Browse the repository at this point in the history
require File.join(File.dirname(__FILE__), .., app.rb) in the spec_helper:
rspec now passing correctly. enabled session in controller, stored instance variable in controller
[started again with tests this time]

User Story 1

As a marketeer
So that I can see my name in lights
I would like to register my name before playing an online game
  • Loading branch information
BenjaminNeustadt committed Jun 6, 2022
1 parent ac76d85 commit 8de8ddc
Show file tree
Hide file tree
Showing 15 changed files with 85 additions and 266 deletions.
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ source 'https://rubygems.org'

ruby '3.0.2'

gem 'sinatra'
gem 'sinatra-contrib'
gem 'rspec'
gem 'capybara'

group :production do
gem 'sinatra'
end
Expand Down
8 changes: 8 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -94,6 +101,7 @@ DEPENDENCIES
simplecov
simplecov-console
sinatra
sinatra-contrib
webrick (~> 1.7)

RUBY VERSION
Expand Down
25 changes: 25 additions & 0 deletions app.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require 'sinatra/base'
require 'sinatra/reloader'

class RockPaperScissors < Sinatra::Base
configure :development do
register Sinatra::Reloader
end
enable :sessions

get '/' do
erb :index
end

post '/name' do
session[:name] = params[:name]
redirect '/play'
end

get '/play' do
@name = session[:name]
erb :play
end

run! if app_file == $0
end
2 changes: 2 additions & 0 deletions config.ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require './app'
run RockPaperScissors
57 changes: 0 additions & 57 deletions controller.rb

This file was deleted.

86 changes: 0 additions & 86 deletions lib/game.rb

This file was deleted.

44 changes: 0 additions & 44 deletions lib/model1.rb

This file was deleted.

9 changes: 0 additions & 9 deletions lib/player.rb

This file was deleted.

12 changes: 0 additions & 12 deletions spec/features/player_spec.rb

This file was deleted.

15 changes: 15 additions & 0 deletions spec/features/register_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'spec_helper'

# As a marketeer
# So that I can see my name in lights
# I would like to register my name before playing an online game

feature 'registering name' do
scenario 'register and see my name' do
visit '/'
fill_in 'name', with: 'Benjamin'
click_button 'Submit'
expect(page).to have_content 'Benjamin'
end
end

37 changes: 23 additions & 14 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
ENV['RACK_ENV'] = 'test'

require File.join(File.dirname(__FILE__), '..', 'app.rb')

require 'capybara'
require 'capybara/rspec'
require 'rspec'
require 'simplecov'
require 'simplecov-console'

SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
SimpleCov::Formatter::Console,
# Want a nice code coverage website? Uncomment this next line!
# SimpleCov::Formatter::HTMLFormatter
])
SimpleCov.start
Capybara.app = RockPaperScissors


# SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
# SimpleCov::Formatter::Console,
# # Want a nice code coverage website? Uncomment this next line!
# # SimpleCov::Formatter::HTMLFormatter
# ])
# SimpleCov.start

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

RSpec.configure do |config|
config.after(:suite) do
puts
puts "\e[33mHave you considered running rubocop? It will help you improve your code!\e[0m"
puts "\e[33mTry it now! Just run: rubocop\e[0m"
end
end
# RSpec.configure do |config|
# config.after(:suite) do
# puts
# puts "\e[33mHave you considered running rubocop? It will help you improve your code!\e[0m"
# puts "\e[33mTry it now! Just run: rubocop\e[0m"
# end
# end
6 changes: 6 additions & 0 deletions views/index.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<form method="POST" action="/name">
<input type="text" name="name" value="" />
<input type="submit" value="Submit" />
</form>


13 changes: 0 additions & 13 deletions views/name.erb

This file was deleted.

13 changes: 1 addition & 12 deletions views/play.erb
Original file line number Diff line number Diff line change
@@ -1,12 +1 @@
Ok! <%= @player %>, choose your weapon: <br>
<br>
<form action="/result">
<input type="radio" value="Rock">
<input type="radio" value="Paper">
<input type="radio" value="Scissors">
</form>

<%# Options:
Pick Rock, paper, or scissors %>

@player.play(result)
Hello, <%= @name %>!

0 comments on commit 8de8ddc

Please sign in to comment.