Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 67 lines (53 sloc) 1.974 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
#================================================================
# Load and configure Capybara

require 'capybara/dsl'
require 'terminus'
Capybara.current_driver = :terminus
extend Capybara::DSL

#================================================================
# Load the example application

dir = ::File.expand_path(::File.dirname(__FILE__))
$LOAD_PATH.unshift(dir + '/../lib')
require 'faye'
require dir + '/ruby/app'

#================================================================
# Build the application stack with Faye in front of our app

application = Rack::Builder.new {
  use Faye::RackAdapter, :mount => '/bayeux', :timeout => 20
  run Sinatra::Application
}
Capybara.app = application.to_app

#================================================================
# Acquire some browsers and log into each with a username

NAMES = %w[alice bob carol dan erica frank gemma harold ingrid james]
BROWSERS = {}
Terminus.ensure_browsers 5

Terminus.browsers.each_with_index do |browser, i|
  name = NAMES[i]
  puts "#{name} is using #{browser}"
  BROWSERS[name] = browser
  Terminus.browser = browser
  visit '/'
  fill_in 'username', :with => name
  click_button 'Go'
end

#================================================================
# Send a message from each browser to every other browser,
# and check that it arrived. If it doesn't arrive, send all
# the browsers back to the dock and raise an exception

BROWSERS.each do |name, sender|
  BROWSERS.each do |at, target|
    next if at == name
    
    Terminus.browser = sender
    fill_in 'message', :with => "@#{at} Hello, world!"
    click_button 'Send'
    
    Terminus.browser = target
    unless page.has_content?("#{name}: @#{at} Hello, world!")
      Terminus.return_to_dock
      raise "Message did not make it from #{sender} to #{target}"
    end
  end
end

#================================================================
# Re-dock all the browsers when we're finished

Terminus.return_to_dock
Something went wrong with that request. Please try again.