test_helper.rb 888 字节
Newer Older
1
require File.expand_path('../../../load_paths', __FILE__)
2

3 4
require 'action_cable'
require 'active_support/testing/autorun'
5 6 7 8


require 'puma'

9
require 'mocha/setup'
T
Thomas Walpole 已提交
10

11
require 'rack/mock'
12

P
Pratik Naik 已提交
13 14
# Require all the stubs and models
Dir[File.dirname(__FILE__) + '/stubs/*.rb'].each {|file| require file }
P
Pratik Naik 已提交
15

16
require 'faye/websocket'
J
Jeremy Daer 已提交
17 18 19
class << Faye::WebSocket
  remove_method :ensure_reactor_running

P
Pratik Naik 已提交
20
  # We don't want Faye to start the EM reactor in tests because it makes testing much harder.
21
  # We want to be able to start and stop EM loop in tests to make things simpler.
J
Jeremy Daer 已提交
22
  def ensure_reactor_running
P
Pratik Naik 已提交
23 24 25 26 27 28 29 30 31
    # no-op
  end
end

class ActionCable::TestCase < ActiveSupport::TestCase
  def run_in_eventmachine
    EM.run do
      yield

32 33
      EM.run_deferred_callbacks
      EM.stop
P
Pratik Naik 已提交
34 35
    end
  end
36 37 38 39

  def spawn_eventmachine
    Thread.new { EventMachine.run } unless EventMachine.reactor_running?
  end
P
Pratik Naik 已提交
40
end