Skip to content
This repository has been archived by the owner on Jul 24, 2023. It is now read-only.

Commit

Permalink
Merge pull request #119 from olleolleolle/fix/avoid-test-warnings
Browse files Browse the repository at this point in the history
Reduce warnings output in test runs: Use assert_nil, File.exist?, avoid useless assignment
  • Loading branch information
tobiashm authored Apr 30, 2019
2 parents 1e86d8c + ed225e2 commit 502b24d
Show file tree
Hide file tree
Showing 15 changed files with 75 additions and 79 deletions.
3 changes: 1 addition & 2 deletions lib/openid/extensions/ax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -539,9 +539,8 @@ def initialize(succeeded = true, error_message = nil)
end

def self.from_success_response(success_response)
resp = nil
ax_args = success_response.message.get_args(NS_URI)
resp = ax_args.key?('error') ? new(false, ax_args['error']) : new
ax_args.key?('error') ? new(false, ax_args['error']) : new
end

def succeeded?
Expand Down
2 changes: 1 addition & 1 deletion lib/openid/store/filesystem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def mktemp
# create a safe filename from a url
def filename_escape(s)
s = '' if s.nil?
filename_chunks = s.each_char.flat_map {|c|
s.each_char.flat_map {|c|
@@FILENAME_ALLOWED.include?(c) ? c : c.bytes.map {|b|
"_%02X" % b
}
Expand Down
28 changes: 14 additions & 14 deletions test/test_associationmanager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def setup
# server error or is otherwise undecipherable.
def test_bad_response
assert_log_matches('Server error when requesting an association') {
assert_equal(call_negotiate([mk_message({})]), nil)
assert_nil(call_negotiate([mk_message({})]))
}
end

Expand All @@ -320,7 +320,7 @@ def test_empty_assoc_type
"Server #{@server_url} responded with unsupported "\
"association session but did not supply a fallback."
) {
assert_equal(call_negotiate([msg]), nil)
assert_nil(call_negotiate([msg]))
}

end
Expand All @@ -337,7 +337,7 @@ def test_empty_session_type
"Server #{@server_url} responded with unsupported "\
"association session but did not supply a fallback."
) {
assert_equal(call_negotiate([msg]), nil)
assert_nil(call_negotiate([msg]))
}
end

Expand All @@ -357,7 +357,7 @@ def test_not_allowed

assert_log_matches('Unsupported association type',
'Server sent unsupported session/association type:') {
assert_equal(call_negotiate([msg], negotiator), nil)
assert_nil(call_negotiate([msg], negotiator))
}
end

Expand Down Expand Up @@ -388,7 +388,7 @@ def test_unsupported_with_retry_and_fail

assert_log_matches('Unsupported association type',
"Server #{@server_url} refused") {
assert_equal(call_negotiate([msg, msg]), nil)
assert_nil(call_negotiate([msg, msg]))
}
end

Expand Down Expand Up @@ -424,7 +424,7 @@ def setup
def test_bad_response
assert_log_matches('Server error when requesting an association') {
response = call_negotiate([mk_message({})])
assert_equal(nil, response)
assert_nil(response)
}
end

Expand All @@ -436,7 +436,7 @@ def test_empty_assoc_type

assert_log_matches('Server error when requesting an association') {
response = call_negotiate([msg])
assert_equal(nil, response)
assert_nil(response)
}
end

Expand All @@ -448,7 +448,7 @@ def test_empty_session_type

assert_log_matches('Server error when requesting an association') {
response = call_negotiate([msg])
assert_equal(nil, response)
assert_nil(response)
}
end

Expand All @@ -466,7 +466,7 @@ def test_not_allowed

assert_log_matches('Server error when requesting an association') {
response = call_negotiate([msg])
assert_equal(nil, response)
assert_nil(response)
}
end

Expand All @@ -482,7 +482,7 @@ def test_unsupported_with_retry

assert_log_matches('Server error when requesting an association') {
response = call_negotiate([msg, assoc])
assert_equal(nil, response)
assert_nil(response)
}
end

Expand Down Expand Up @@ -818,13 +818,13 @@ def set_negotiate_response(assoc)

def test_not_in_store_no_response
set_negotiate_response(nil)
assert_equal(nil, @assoc_manager.get_association)
assert_nil(@assoc_manager.get_association)
end

def test_not_in_store_negotiate_assoc
# Not stored beforehand:
stored_assoc = @store.get_association(@server_url, @assoc.handle)
assert_equal(nil, stored_assoc)
assert_nil(stored_assoc)

# Returned from associate call:
set_negotiate_response(@assoc)
Expand Down Expand Up @@ -898,7 +898,7 @@ def test_success
def test_missing_fields
@message.del_arg(OPENID_NS, 'assoc_type')
assert_log_matches('Missing required par') {
assert_equal(nil, make_request)
assert_nil(make_request)
}
end

Expand All @@ -907,7 +907,7 @@ def test_missing_fields
def test_protocol_error
@message.set_arg(OPENID_NS, 'expires_in', 'goats')
assert_log_matches('Protocol error processing') {
assert_equal(nil, make_request)
assert_nil(make_request)
}
end
end
Expand Down
10 changes: 5 additions & 5 deletions test/test_ax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_construct
assert_equal(type_uri, ainfo.type_uri)
assert_equal(1, ainfo.count)
assert_equal(false, ainfo.required)
assert_equal(nil, ainfo.ns_alias)
assert_nil(ainfo.ns_alias)
end
end

Expand Down Expand Up @@ -234,7 +234,7 @@ def test_mode

def test_construct
assert_equal({}, @msg.requested_attributes)
assert_equal(nil, @msg.update_url)
assert_nil(@msg.update_url)

msg = FetchRequest.new('hailstorm')
assert_equal({}, msg.requested_attributes)
Expand Down Expand Up @@ -494,7 +494,7 @@ def setup
end

def test_construct
assert_equal(nil, @msg.update_url)
assert_nil(@msg.update_url)
assert_equal({}, @msg.data)
end

Expand Down Expand Up @@ -541,7 +541,7 @@ def test_update_url_in_response
end

def test_get_extension_args_single_value_response
# Single values do NOT have a count, and
# Single values do NOT have a count, and
# do not use the array extension
eargs = {
'mode' => 'fetch_response',
Expand Down Expand Up @@ -585,7 +585,7 @@ def test_get_single_success
end

def test_get_single_none
assert_equal(nil, @msg.get_single(@type_a))
assert_nil(@msg.get_single(@type_a))
end

def test_get_single_extra
Expand Down
2 changes: 1 addition & 1 deletion test/test_consumer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_set_get
assert_equal(:endpoint, ep)
consumer.send(:cleanup_last_requested_endpoint)
ep = consumer.send(:last_requested_endpoint)
assert_equal(nil, ep)
assert_nil(ep)
end
end

Expand Down
6 changes: 3 additions & 3 deletions test/test_discover.rb
Original file line number Diff line number Diff line change
Expand Up @@ -724,16 +724,16 @@ def test_isOPEndpoint
end

def test_noIdentifiers
assert_equal(@endpoint.get_local_id, nil)
assert_equal(@endpoint.claimed_id, nil)
assert_nil(@endpoint.get_local_id)
assert_nil(@endpoint.claimed_id)
end

def test_compatibility
assert(!@endpoint.compatibility_mode())
end

def test_canonical_id
assert_equal(@endpoint.canonical_id, nil)
assert_nil(@endpoint.canonical_id)
end

def test_serverURL
Expand Down
18 changes: 9 additions & 9 deletions test/test_discovery_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def test_next
assert_equal(@disco_services.next, @services[1])
assert_equal(@disco_services.current, @services[1])

assert_equal(@disco_services.next, nil)
assert_equal(@disco_services.current, nil)
assert_nil(@disco_services.next)
assert_nil(@disco_services.current)
end

def test_for_url
Expand Down Expand Up @@ -84,7 +84,7 @@ def test_construct
end

def test_get_next_service
assert_equal(@session[@key], nil)
assert_nil(@session[@key])

next_service = @manager.get_next_service {
[@yadis_url, ["one", "two", "three"]]
Expand Down Expand Up @@ -123,24 +123,24 @@ def test_get_next_service
["unused", []]
}

assert_equal(result, nil)
assert_nil(result)
end

def test_cleanup
# With no preexisting manager, cleanup() returns nil.
assert_equal(@manager.cleanup, nil)
assert_nil(@manager.cleanup)

# With a manager, it returns the manager's current service.
disco = Consumer::DiscoveredServices.new(@url, @yadis_url, ["one", "two"])

@session[@key] = disco
assert_equal(@manager.cleanup, nil)
assert_equal(@session[@key], nil)
assert_nil(@manager.cleanup)
assert_nil(@session[@key])

disco.next
@session[@key] = disco
assert_equal(@manager.cleanup, "one")
assert_equal(@session[@key], nil)
assert_nil(@session[@key])

# The force parameter should be passed through to get_manager
# and destroy_manager.
Expand Down Expand Up @@ -178,7 +178,7 @@ def test_get_manager
disco2 = Consumer::DiscoveredServices.new("http://not.this.url.com/",
"http://other.yadis.url/", ["one"])
@session[@key] = disco2
assert_equal(@manager.get_manager, nil)
assert_nil(@manager.get_manager)
assert_equal(@manager.get_manager(true), disco2)
end

Expand Down
Loading

0 comments on commit 502b24d

Please sign in to comment.