Sha256: 16a3ad085d25a15330f5cd231cc30af4cf1068f72610fe39f2a2a0708bf9d5e6

Contents?: true

Size: 1.39 KB

Versions: 67

Compression:

Stored size: 1.39 KB

Contents

require 'spec_helper'
require 'startback/web/health_check'

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

67 entries across 67 versions & 3 rubygems

Version Path
startback-1.0.3 spec/unit/web/test_healthcheck.rb
startback-1.0.2 spec/unit/web/test_healthcheck.rb
startback-1.0.1 spec/unit/web/test_healthcheck.rb
startback-1.0.0 spec/unit/web/test_healthcheck.rb
startback-0.19.4 spec/unit/web/test_healthcheck.rb
startback-0.19.3 spec/unit/web/test_healthcheck.rb
startback-0.19.1 spec/unit/web/test_healthcheck.rb
startback-0.19.0 spec/unit/web/test_healthcheck.rb
startback-0.18.2 spec/unit/web/test_healthcheck.rb
startback-0.18.1 spec/unit/web/test_healthcheck.rb
startback-0.18.0 spec/unit/web/test_healthcheck.rb
startback-0.17.4 spec/unit/web/test_healthcheck.rb
startback-0.17.3 spec/unit/web/test_healthcheck.rb
startback-0.17.2 spec/unit/web/test_healthcheck.rb
startback-0.17.1 spec/unit/web/test_healthcheck.rb
startback-0.17.0 spec/unit/web/test_healthcheck.rb
startback-0.16.0 spec/unit/web/test_healthcheck.rb
startback-0.15.5 spec/unit/web/test_healthcheck.rb
startback-0.15.4 spec/unit/web/test_healthcheck.rb
startback-0.15.3 spec/unit/web/test_healthcheck.rb