Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 113 lines (89 sloc) 2.668 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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
require 'rubygems'
require 'bundler'

require 'singleton'
require 'tempfile'

Bundler.setup

require 'daemon_controller'

require 'minitest/unit'
require 'minitest/spec'
require 'minitest/autorun'

require 'turn'

require_relative '../lib/emotions'

Turn.config do |tc|
  tc.ansi = true
  tc.format = :dot
end

IntegrationTestRedis = DaemonController.new(
  identifier: "Emotions Ingration Test Redis Server",
  start_command: "redis-server #{File.expand_path('./emotions_integration_test_redis.conf', 'test')}",
  ping_command: [:tcp, '127.0.0.1', 9737],
  pid_file: "/tmp/emotions_integration_test_redis.pid",
  log_file: "/tmp/emotions_integration_test_redis.log",
  start_timeout: 2
)

module Emotions

  module MiniTest

    class Unit
      TestCase = Class.new(::MiniTest::Unit::TestCase)
    end

    class Acceptance
      TestCase = Class.new(Unit::TestCase)
    end

    class Integration
      TestCase = Class.new(Acceptance::TestCase)
    end

  end

end

Emotions::MiniTest::Unit::TestCase.class_eval do

  def setup_with_clean_objects
    setup_without_clean_objects
    instance_methods = Module.new do
      def ==(other)
        id == other.id
      end
      def initialize(id = nil)
        @id = id
      end
    end
    class_methods = Module.new do
      def find(id)
        new(id)
      end
    end
    ::Object.const_set(:ExampleObject, Class.new)
    ::Object.const_set(:ExampleTarget, Class.new)
    ::ExampleObject.class_eval { attr_accessor :id }
    ::ExampleTarget.class_eval { attr_accessor :id }
    ::ExampleObject.send(:include, instance_methods)
    ::ExampleTarget.send(:include, instance_methods)
    ::ExampleObject.send(:extend, class_methods)
    ::ExampleTarget.send(:extend, class_methods)
  end
  alias :setup_without_clean_objects :setup
  alias :setup :setup_with_clean_objects

  def teardown_with_clean_objects
    teardown_without_clean_objects
    Object.send(:remove_const, :ExampleObject)
    Object.send(:remove_const, :ExampleTarget)
  end
  alias :teardown_without_clean_objects :teardown
  alias :teardown :teardown_with_clean_objects

end

Emotions::MiniTest::Integration::TestCase.class_eval do

  def setup_with_live_redis
    setup_without_live_redis
    ::IntegrationTestRedis.start
    rb = Emotions::RedisBackend.new
    rb.redis = ::Redis.new(port: 9737)
    rb.redis.flushdb
    Emotions.backend = rb
  end
  alias :setup_without_live_redis :setup
  alias :setup :setup_with_live_redis

  def teardown_with_live_redis
    teardown_without_live_redis
    ::IntegrationTestRedis.stop
  end
  alias :teardown_without_live_redis :teardown
  alias :teardown :teardown_with_live_redis

end
Something went wrong with that request. Please try again.