Sha256: 274b4adf5a0e91f97f01f25ede4ee3212cf5e183d07a7e4e58144994c3964d26

Contents?: true

Size: 1.37 KB

Versions: 7

Compression:

Stored size: 1.37 KB

Contents

ENV['RACK_ENV'] = 'test'

require 'minitest/autorun'

class TestEndpointHandlers < MiniTest::Test

  def setup
    @handlers = PinchHitter::Service::EndpointHandlers.new
  end

  def json
    %Q{{"key"::"value"}}
  end

  def test_defaults_to_message_queue
    @handlers.store_message 'endpoint', json
    assert_equal json, @handlers.respond_to('endpoint')
  end

  def test_register_module
    @handlers.register_module('endpoint', TestModule)
    assert_equal "THIS IS A TEST", @handlers.respond_to('endpoint')
  end

  def test_reset_clears_message_queues
    @handlers.store_message 'endpoint', json
    @handlers.reset
    assert_nil @handlers.respond_to('endpoint')
  end

  def test_reset_does_not_clear_modules
    @handlers.register_module('endpoint', TestModule)
    @handlers.reset
    assert_equal "THIS IS A TEST", @handlers.respond_to('endpoint')
  end

  def test_register_module_with_marshalling
    mod = Marshal.dump(TestModule)
    @handlers.register_module('endpoint', Marshal.load(mod))
    assert_equal "THIS IS A TEST", @handlers.respond_to('endpoint')
  end

  def test_requests
    request = { body: '{"Hot Rod" : "Williams"}' }
    @handlers.respond_to('endpoint', request)
    assert_equal [request], @handlers.requests('endpoint')
  end


  module TestModule
    def respond_to(msg)
      test_message
    end
    def test_message
      "THIS IS A TEST"
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
pinch_hitter-0.5.5 test/test_endpoint_handlers.rb
pinch_hitter-0.5.4 test/test_endpoint_handlers.rb
pinch_hitter-0.5.3 test/test_endpoint_handlers.rb
pinch_hitter-0.5.2 test/test_endpoint_handlers.rb
pinch_hitter-0.5.1 test/test_endpoint_handlers.rb
pinch_hitter-0.5 test/test_endpoint_handlers.rb
pinch_hitter-0.4 test/test_endpoint_handlers.rb