Skip to content

Commit

Permalink
Feature/Ability to use configuration configuration with default setti…
Browse files Browse the repository at this point in the history
…ngs without block (#23)

* Updated OnStrum::Healthcheck.configure, tests
* Updated gem documentation
  • Loading branch information
bestwebua authored Mar 28, 2024
1 parent 54e5892 commit 654142b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ Please note, to start using this middleware you should configure `OnStrum::Healt
require 'on_strum/healthcheck'

# Configuring OnStrum::Healthcheck with default settings
OnStrum::Healthcheck.configure {}
OnStrum::Healthcheck.configure

Rack::Builder.app do
use OnStrum::Healthcheck::RackMiddleware
Expand All @@ -169,7 +169,7 @@ end
require 'on_strum/healthcheck'

# Configuring OnStrum::Healthcheck with default settings
OnStrum::Healthcheck.configure {}
OnStrum::Healthcheck.configure

class YourApplication < Roda
use OnStrum::Healthcheck::RackMiddleware
Expand All @@ -184,7 +184,7 @@ end
require 'on_strum/healthcheck'

# Configuring OnStrum::Healthcheck with default settings
OnStrum::Healthcheck.configure {}
OnStrum::Healthcheck.configure
```

```ruby
Expand All @@ -203,7 +203,7 @@ end
require 'on_strum/healthcheck'

# Configuring OnStrum::Healthcheck with default settings
OnStrum::Healthcheck.configure {}
OnStrum::Healthcheck.configure
```

```ruby
Expand Down
2 changes: 2 additions & 0 deletions lib/on_strum/healthcheck.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ def configuration(&block)
end

def configure(&block)
return configuration {} unless block # rubocop:disable Lint/EmptyBlock

configuration(&block)
end

Expand Down
23 changes: 21 additions & 2 deletions spec/on_strum/healthcheck_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,27 @@
let(:config_block) { nil }

context 'without block' do
it { expect(configuration).to be_nil }
it { expect { configuration }.not_to change(described_class, :configuration) }
it 'sets default attributes into configuration instance' do
expect { configuration }
.to change(described_class, :configuration)
.from(nil)
.to(be_instance_of(OnStrum::Healthcheck::Configuration))
expect(configuration).to be_an_instance_of(OnStrum::Healthcheck::Configuration)
expect(configuration.services).to eq({})
expect(configuration.services_startup).to eq([])
expect(configuration.services_liveness).to eq([])
expect(configuration.services_readiness).to eq([])
expect(configuration.endpoints_namespace).to eq(OnStrum::Healthcheck::Configuration::ENDPOINTS_NAMESPACE)
expect(configuration.endpoint_startup).to eq(OnStrum::Healthcheck::Configuration::ENDPOINT_STARTUP)
expect(configuration.endpoint_liveness).to eq(OnStrum::Healthcheck::Configuration::ENDPOINT_LIVENESS)
expect(configuration.endpoint_readiness).to eq(OnStrum::Healthcheck::Configuration::ENDPOINT_READINESS)
expect(configuration.endpoint_startup_status_success).to eq(OnStrum::Healthcheck::Configuration::DEFAULT_HTTP_STATUS_SUCCESS)
expect(configuration.endpoint_liveness_status_success).to eq(OnStrum::Healthcheck::Configuration::DEFAULT_HTTP_STATUS_SUCCESS)
expect(configuration.endpoint_readiness_status_success).to eq(OnStrum::Healthcheck::Configuration::DEFAULT_HTTP_STATUS_SUCCESS)
expect(configuration.endpoint_startup_status_failure).to eq(OnStrum::Healthcheck::Configuration::DEFAULT_HTTP_STATUS_FAILURE)
expect(configuration.endpoint_liveness_status_failure).to eq(OnStrum::Healthcheck::Configuration::DEFAULT_HTTP_STATUS_FAILURE)
expect(configuration.endpoint_readiness_status_failure).to eq(OnStrum::Healthcheck::Configuration::DEFAULT_HTTP_STATUS_FAILURE)
end
end

context 'with block' do
Expand Down

0 comments on commit 654142b

Please sign in to comment.