Sha256: 8aaeb77edb09a16b9e0569d01e3879a6e2cde6a09b5f081277af0a67c06ab1de

Contents?: true

Size: 1.87 KB

Versions: 15

Compression:

Stored size: 1.87 KB

Contents

ENV['RACK_ENV'] ||= 'test'

require 'logger'
require 'em-http'
require 'faye/websocket'
require 'hiredis'
require 'firehose'

# We use both EM::Http and Net::Http in this test lib. When EM:Http is fired up
# we're usually hitting Rainbows! for integrations, and when Net::Http we want
# to mock that up.
require 'webmock/rspec'
WebMock.allow_net_connect!

module EM::TestHelper
  # Run test inside of reactor.
  def em(ttl=30, &block)
    if block
      # Run the block inside of a reactor
      EM.run do
        EM.add_timer(ttl) do
          EM.stop
          raise "Test timed-out"
        end
        block.call(EM)
      end
    else # or just grab em and go nuts.
      EM
    end
  end
end

module Hiredis::TestHelper
  def redis
    @conn ||= begin
      conn = Hiredis::Connection.new
      conn.connect("127.0.0.1", 6379)
      conn
    end
  end

  def reset_redis
    redis_exec 'flushdb'
  end

  def redis_exec(*tokens)
    redis.write tokens
    redis.read
  end
end

# Configure RSpec runner. See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
RSpec.configure do |config|
  config.treat_symbols_as_metadata_keys_with_true_values = true
  config.run_all_when_everything_filtered = true
  config.filter_run :focus
  config.include Hiredis::TestHelper
  config.before(:each) do
    reset_redis
  end
end

# Allow async responses to get through rack/lint
require 'rack/lint'
class Rack::Lint
  def check_status_with_async(status)
    check_status_without_async(status) unless status == -1
  end
  alias_method :check_status_without_async, :check_status
  alias_method :check_status, :check_status_with_async

  def check_content_type_with_async(status, headers)
    check_content_type_without_async(status, headers) unless status == -1
  end
  alias_method :check_content_type_without_async, :check_content_type
  alias_method :check_content_type, :check_content_type_with_async
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
firehose-1.2.20 spec/spec_helper.rb
firehose-1.2.13 spec/spec_helper.rb
firehose-1.2.12 spec/spec_helper.rb
firehose-1.2.11 spec/spec_helper.rb
firehose-1.2.10 spec/spec_helper.rb
firehose-1.2.9 spec/spec_helper.rb
firehose-1.2.8 spec/spec_helper.rb
firehose-1.2.7 spec/spec_helper.rb
firehose-1.2.6 spec/spec_helper.rb
firehose-1.2.5 spec/spec_helper.rb
firehose-1.2.4 spec/spec_helper.rb
firehose-1.2.3 spec/spec_helper.rb
firehose-1.2.2 spec/spec_helper.rb
firehose-1.2.1 spec/spec_helper.rb
firehose-1.2.0 spec/spec_helper.rb