sms_beholder_spec.rb 3.71 KB
Newer Older
Joe Libipl's avatar
Joe Libipl committed
1 2
require 'spec_helper'
require 'rack/test'
Joe Libipl's avatar
Joe Libipl committed
3
require 'timeout'
Joe Libipl's avatar
Joe Libipl committed
4 5 6 7 8 9 10 11 12 13
require_relative '../sms_beholder.rb'

describe SMSBeholder do
  include Rack::Test::Methods

  def app
    SMSBeholder.new
  end

  it 'responds with initial state' do
14
    get '/', From: 'Dude1'
Joe Libipl's avatar
Linting  
Joe Libipl committed
15

16
    expect(last_response.body).to include('Please tell me your name.')
Joe Libipl's avatar
Joe Libipl committed
17 18
  end

19 20 21
  it 'responds with initial state for each player' do
    get '/', From: 'Dude1'
    get '/', From: 'Dude2'
Joe Libipl's avatar
Linting  
Joe Libipl committed
22

23 24 25 26 27 28
    expect(last_response.body).to include('Please tell me your name.')
  end

  it 'moves to second state' do
    get '/', From: 'Dude3'
    get '/', From: 'Dude3'
Joe Libipl's avatar
Linting  
Joe Libipl committed
29

30
    expect(last_response.body).to include('Day One.')
Joe Libipl's avatar
Joe Libipl committed
31
  end
Joe Libipl's avatar
Joe Libipl committed
32 33 34 35 36 37 38 39 40

  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
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55

  it 'uses the right player name' do
    get '/', From: 'Dude5'
    get '/', From: 'Dude5', Body: 'NumberFive'
    get '/', From: 'Dude6'
    get '/', From: 'Dude6'
    get '/', From: 'Dude5'
    get '/', From: 'Dude5'

    expect(last_response.body).to include("You're NumberFive, a student at Beholder High.")
  end

  it 'lets you skip to a different state for testing' do
    get '/', From: 'Dude7', SkipToState: 'D1S107'

Joe Libipl's avatar
Linting  
Joe Libipl committed
56
    expect(last_response.body).to include('Your brooding has distracted you')
57 58
  end

Joe Libipl's avatar
Joe Libipl committed
59 60 61 62 63
  it 'presents selections to player' do
    get '/', From: 'Dude8', SkipToState: 'D1S108'

    expect(last_response.body).to include("what is the solution?\n1) Six\n2) Sixteen\n3) I wasn't paying attention")
  end
Joe Libipl's avatar
Joe Libipl committed
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85

  it 'respects selections from player' do
    get '/', From: 'Dude8', SkipToState: 'D1S108'
    get '/', From: 'Dude8', Body: '1'

    expect(last_response.body).to include('Wrong. You haven\'t been paying attention, have you?')
  end

  it 'rejects non-numeric selections from player' do
    get '/', From: 'Dude9', SkipToState: 'D1S108'
    get '/', From: 'Dude9', Body: 'Dan'

    expect(last_response.body).to include("what is the solution?\n1) Six\n2) Sixteen\n3) I wasn't paying attention")
  end

  it 'rejects invalid selections from player' do
    get '/', From: 'Dude', SkipToState: 'D1S108'
    get '/', From: 'Dude', Body: '4'

    expect(last_response.body).to include("what is the solution?\n1) Six\n2) Sixteen\n3) I wasn't paying attention")
  end

Joe Libipl's avatar
Joe Libipl committed
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
  it 'shows constant selections from conditional selection set' do
    get '/', From: 'Dude', SkipToState: 'M00'

    expect(last_response.body).to include("1) How do you like soccer?\n2) Do you like dancing?")
  end

  # it 'hides conditional selection without condition' do
  #   get '/', From: 'Dude', SkipToState: 'M00'

  #   expect(last_response.body).not_to include("that killer bicycle kick")
  # end

  # it 'hides conditional selection with failed condition' do
  #   get '/', From: 'Dude', SkipToState: 'M00', SetKey: 'mox-kick', SetKeyValue: 'unknown'

  #   expect(last_response.body).to include("1) How do you like soccer?\n2) Do you like dancing?")
  #   expect(last_response.body).not_to include("that killer bicycle kick")
  # end

105 106 107 108 109 110 111 112 113 114 115 116
  # it 'can be played all the way through' do
  #   get '/', From: 'Dude'
  #   Timeout::timeout(10) do
  #     until last_response.body.include?('And you won\'t be alone...') ||
  #       last_response.body.include?('Royalty does not concern itself with common dances.') ||
  #       last_response.body.include?('True power is slow dancing with someone who could beat you senseless.') ||
  #       last_response.body.include?('Thirst for knowledge. Hunger for power. No feast is fine enough.') do
  #       get '/', From: 'Dude', Body: ['1','2','3'].sample
  #       puts last_response.body
  #     end
  #   end
  # end
Joe Libipl's avatar
Joe Libipl committed
117

Joe Libipl's avatar
Joe Libipl committed
118
end