Sha256: 49399e945c1f61917ab1822a3746aea8cfe2e5e563ec5079766bceee099ed534

Contents?: true

Size: 1.35 KB

Versions: 4

Compression:

Stored size: 1.35 KB

Contents

require 'spec_helper'

module Startback
  module Web
    describe HealthCheck do
      include Rack::Test::Methods

      context 'when used without a block and no failure' do
        def app
          HealthCheck.new
        end

        it 'returns a 204 when ok' do
          get '/'
          expect(last_response.status).to eql(204)
          expect(last_response.body).to be_empty
        end
      end

      context 'when used without a block a failure' do
        def app
          app = HealthCheck.new
          def app.check!(env)
            raise "Hello error"
          end
          app
        end

        it 'raises when ko' do
          expect(->(){ get '/' }).to raise_error("Hello error")
        end
      end

      context 'when used with a block returning a debug message' do
        def app
          HealthCheck.new{ "Hello world" }
        end

        it 'returns a 200 with plain text message' do
          get '/'
          expect(last_response.status).to eql(200)
          expect(last_response.body).to eql("Hello world")
        end
      end

      context 'when used with a block raising an exception' do
        def app
          HealthCheck.new{ raise("Hello error") }
        end

        it 're-raises it' do
          expect(->(){ get '/' }).to raise_error("Hello error")
        end
      end

    end
  end # module Web
end # module Startback

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
startback-0.3.2 spec/unit/web/test_healthcheck.rb
startback-0.3.1 spec/unit/web/test_healthcheck.rb
startback-0.3.0 spec/unit/web/test_healthcheck.rb
startback-0.2.0 spec/unit/web/test_healthcheck.rb