Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not use begin/rescue in tests #198

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 18 additions & 5 deletions test/adapters/generic_adapter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,29 @@ class GenericAdapterTest < ActiveSupport::TestCase
to_return(status: 200, headers: { 'Content-Type' => 'application/json' },
body: { token_endpoint: 'protocol/openid-connect/token' }.to_json)

stub_request(:post, 'http://lvh.me:3000/auth/realm/name/protocol/openid-connect/token').to_timeout
get_token = stub_request(:post, 'http://lvh.me:3000/auth/realm/name/protocol/openid-connect/token').to_timeout

adapter = RESTAdapter.new('http://id:secret@lvh.me:3000/auth/realm/name')

begin
log = Object.new
class << log
def error_object
@error
end

def error(object)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not using a MiniTest::Mock ?

@error = object
end
end

Rails.logger.stub :error, log.method(:error) do
adapter.test
rescue RESTAdapter::OIDC::AuthenticationError => error
assert_kind_of Faraday::TimeoutError, error.cause
assert error.bugsnag_meta_data.presence
end

error = log.error_object
assert_kind_of Faraday::TimeoutError, error.cause
assert error.bugsnag_meta_data.presence
assert_requested get_token
end

test 'create client' do
Expand Down
10 changes: 5 additions & 5 deletions test/adapters/keycloak_adapter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ class KeycloakAdapterTest < ActiveSupport::TestCase
to_return(status: 200, headers: { 'Content-Type' => 'application/json' },
body: { token_endpoint: 'protocol/openid-connect/token' }.to_json)

stub_request(:post, 'http://lvh.me:3000/auth/realm/name/protocol/openid-connect/token').to_timeout
get_token = stub_request(:post, 'http://lvh.me:3000/auth/realm/name/protocol/openid-connect/token').to_timeout

keycloak = KeycloakAdapter.new('http://id:secret@lvh.me:3000/auth/realm/name')

begin
error = assert_raises KeycloakAdapter::OIDC::AuthenticationError do
keycloak.test
rescue KeycloakAdapter::OIDC::AuthenticationError => error
assert_kind_of Faraday::TimeoutError, error.cause
assert error.bugsnag_meta_data.presence
end
assert_kind_of Faraday::TimeoutError, error.cause
assert error.bugsnag_meta_data.presence
assert_requested get_token
end

test 'test' do
Expand Down