Commit 5ca8e043 authored by Joe Libipl's avatar Joe Libipl
Browse files

Name test.

parent 7216697b
Pipeline #9090473 failed with stage
in 1 minute and 28 seconds
GEM
remote: https://rubygems.org/
specs:
ast (2.3.0)
diff-lcs (1.3)
json (2.1.0)
mustermann (1.0.0)
parallel (1.11.2)
parser (2.4.0.0)
ast (~> 2.2)
powerpack (0.1.1)
rack (2.0.3)
rack-protection (2.0.0)
rack
rack-test (0.6.3)
rack (>= 1.0)
rainbow (2.2.2)
rake
rake (12.0.0)
rspec (3.6.0)
rspec-core (~> 3.6.0)
rspec-expectations (~> 3.6.0)
rspec-mocks (~> 3.6.0)
rspec-core (3.6.0)
rspec-support (~> 3.6.0)
rspec-expectations (3.6.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.6.0)
rspec-mocks (3.6.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.6.0)
rspec-support (3.6.0)
rubocop (0.49.1)
parallel (~> 1.10)
parser (>= 2.3.3.1, < 3.0)
powerpack (~> 0.1)
rainbow (>= 1.99.1, < 3.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
rubocop-rspec (1.15.1)
rubocop (>= 0.42.0)
ruby-progressbar (1.8.1)
sinatra (2.0.0)
mustermann (~> 1.0)
rack (~> 2.0)
rack-protection (= 2.0.0)
tilt (~> 2.0)
tilt (2.0.7)
unicode-display_width (1.2.1)
PLATFORMS
x64-mingw32
DEPENDENCIES
json
rack-test
rspec
rubocop
rubocop-rspec
sinatra
BUNDLED WITH
1.15.1
......@@ -4,7 +4,7 @@
"story": "Please tell me your name.",
"next": "DAY1",
"textEntry": {
"key": "playerName",
"key": "name",
"next": "DAY1",
"buttonText": "Start"
},
......
......@@ -3,17 +3,38 @@ require 'sinatra/base'
# Sinatra-derived class for easy testing
class SMSBeholder < Sinatra::Base
player_states = {}
player_data = {}
game_states = JSON.parse(File.open('script.json', 'r').read)
get '/' do
source = params['From']
player_states[source] ||= 'SPLASH'
puts game_states[player_states[source]]
next_state = game_states[player_states[source]]['next']
response = game_states[player_states[source]]['story']
player_states[source] = next_state
puts player_states
body = params['Body']
player_data[source] ||= {}
player_data[source]['state'] ||= 'SPLASH'
state = player_data[source]['state']
puts state
# Handle input
if player_data[source].key?('last_state')
last_state = player_data[source]['last_state']
if game_states[last_state].key?('textEntry')
text_entry_key = game_states[last_state]['textEntry']['key']
player_data[source][text_entry_key] = body
end
end
next_state = game_states[state]['next']
response = game_states[state]['story']
player_data[source]['last_state'] = state
player_data[source]['state'] = next_state
puts player_data
# Fill in values in response
for key in player_data[source].keys
response.sub!(":#{key}:", player_data[source][key])
end
response
end
......
......@@ -28,4 +28,13 @@ describe SMSBeholder do
expect(last_response.body).to include('Day One.')
end
it 'accepts a player name' do
get '/', From: 'Dude4'
get '/', From: 'Dude4', Body: 'NameOfDude4'
get '/', From: 'Dude4'
get '/', From: 'Dude4'
expect(last_response.body).to include("You're NameOfDude4, a student at Beholder High.")
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment