diff options
author | Azul <azul@riseup.net> | 2017-09-23 11:07:32 +0200 |
---|---|---|
committer | Azul <azul@riseup.net> | 2017-09-23 16:53:27 +0200 |
commit | 40916407517f4bdb75a295caf29e02d4f403349b (patch) | |
tree | 8219567c0ecdf583fdd916594ec7915ab9eb2f19 /test | |
parent | 22c6c80310a8d3d3abbd1006598b4fbaec98ffd0 (diff) |
style: rubocop mostly auto-correct
Diffstat (limited to 'test')
33 files changed, 128 insertions, 150 deletions
diff --git a/test/file_content.rb b/test/file_content.rb index 0d0ac21..abc0fd8 100644 --- a/test/file_content.rb +++ b/test/file_content.rb @@ -1,11 +1,9 @@ module FileContent - def file_content(filename) (@file_contents ||= {})[filename] ||= File.read(file_path(filename)) end def file_path(filename) - "%s/files/%s" % [File.dirname(__FILE__), filename] + format('%s/files/%s', File.dirname(__FILE__), filename) end - end diff --git a/test/functional/bin_test.rb b/test/functional/bin_test.rb index 3e2774c..3a4e6c7 100644 --- a/test/functional/bin_test.rb +++ b/test/functional/bin_test.rb @@ -2,13 +2,12 @@ require 'minitest/autorun' require 'minitest/pride' class BinTest < Minitest::Test - def teardown - run_command "stop" + run_command 'stop' end def test_bin_loading - assert_command_runs("version") + assert_command_runs('version') end def test_not_running_by_default @@ -16,26 +15,26 @@ class BinTest < Minitest::Test end def test_start - run_command "start" + run_command 'start' assert_running end protected def assert_running - status = run_command "status" - assert_includes status, "Nickserver running" + status = run_command 'status' + assert_includes status, 'Nickserver running' end def assert_stopped - status = run_command "status" - assert_includes status, "No nickserver processes are running." + status = run_command 'status' + assert_includes status, 'No nickserver processes are running.' end def assert_command_runs(command) out = run_command command - assert ($?.exitstatus == 0), - "failed to run 'nickserver #{command}':\n #{out}" + assert ($CHILD_STATUS.exitstatus == 0), + "failed to run 'nickserver #{command}':\n #{out}" end def run_command(command) @@ -45,5 +44,4 @@ class BinTest < Minitest::Test def path_to_executable File.expand_path(File.dirname(__FILE__) + '/../../bin/nickserver') end - end diff --git a/test/functional/sample_test.rb b/test/functional/sample_test.rb index 2b49527..dbd8796 100644 --- a/test/functional/sample_test.rb +++ b/test/functional/sample_test.rb @@ -49,7 +49,7 @@ class SampleTest < FunctionalTest end def lookup(address) - run_command %Q(curl localhost:6425 #{curl_opts} -d "address=#{address}") + run_command %(curl localhost:6425 #{curl_opts} -d "address=#{address}") end def curl_opts @@ -57,13 +57,13 @@ class SampleTest < FunctionalTest end def open_files_count - run_command(%Q(lsof | grep " #{nickserver_pid} " | wc -l)).to_i + run_command(%(lsof | grep " #{nickserver_pid} " | wc -l)).to_i end def run_command(command) `#{command} 2>&1`.tap do |out| - assert ($?.exitstatus == 0), - "failed to run '#{command}':\n #{out}" + assert ($CHILD_STATUS.exitstatus == 0), + "failed to run '#{command}':\n #{out}" end end end diff --git a/test/integration/couch_db/source_test.rb b/test/integration/couch_db/source_test.rb index cb1153e..ac237c6 100644 --- a/test/integration/couch_db/source_test.rb +++ b/test/integration/couch_db/source_test.rb @@ -4,7 +4,7 @@ require 'nickserver/couch_db/source' module Nickserver::CouchDB class SourceTest < Minitest::Test - include FileContent + include FileContent def test_couch_query_and_response adapter = adapter_returns 200, file_content(:blue_couchdb_result) diff --git a/test/integration/dispatcher_test.rb b/test/integration/dispatcher_test.rb index b551e87..58aa972 100644 --- a/test/integration/dispatcher_test.rb +++ b/test/integration/dispatcher_test.rb @@ -13,7 +13,6 @@ require 'nickserver/dispatcher' # class Nickserver::DispatcherTest < Minitest::Test - def test_empty_query handle assert_response not_found @@ -26,12 +25,12 @@ class Nickserver::DispatcherTest < Minitest::Test def test_fingerprint_to_short handle fingerprint: ['44F2F455E28'] - assert_response error("Fingerprint invalid: 44F2F455E28") + assert_response error('Fingerprint invalid: 44F2F455E28') end def test_fingerprint_is_not_hex handle fingerprint: ['X36E738D69173C13Z709E44F2F455E2824D18DDX'] - assert_response error("Fingerprint invalid: X36E738D69173C13Z709E44F2F455E2824D18DDX") + assert_response error('Fingerprint invalid: X36E738D69173C13Z709E44F2F455E2824D18DDX') end def test_missing_domain @@ -42,28 +41,28 @@ class Nickserver::DispatcherTest < Minitest::Test end def test_email_via_hkp - handle address: ['valid@email.tld'], headers: { "Host" => "http://nickserver.me" } + handle address: ['valid@email.tld'], headers: { 'Host' => 'http://nickserver.me' } stub_nicknym_not_available hkp_source.expect :query, success, [Nickserver::EmailAddress] assert_response success end def test_email_via_hkp_nicknym_unreachable - handle address: ['valid@email.tld'], headers: { "Host" => "http://nickserver.me" } + handle address: ['valid@email.tld'], headers: { 'Host' => 'http://nickserver.me' } stub_nicknym_raises hkp_source.expect :query, success, [Nickserver::EmailAddress] assert_response success end def test_email_not_found_hkp_nicknym_unreachable - handle address: ['valid@email.tld'], headers: { "Host" => "http://nickserver.me" } + handle address: ['valid@email.tld'], headers: { 'Host' => 'http://nickserver.me' } stub_nicknym_raises hkp_source.expect :query, nil, [Nickserver::EmailAddress] assert_response http_connection_error end def test_email_via_nicknym - handle address: ['valid@email.tld'], headers: { "Host" => "http://nickserver.me" } + handle address: ['valid@email.tld'], headers: { 'Host' => 'http://nickserver.me' } nicknym_source.expect :available_for?, true, [String] nicknym_source.expect :query, success, [Nickserver::EmailAddress] assert_response success @@ -73,7 +72,7 @@ class Nickserver::DispatcherTest < Minitest::Test handle fingerprint: ['E36E738D69173C13D709E44F2F455E2824D18DDF'] stub_nicknym_not_available hkp_source.expect :get_key_by_fingerprint, success, - ['E36E738D69173C13D709E44F2F455E2824D18DDF'] + ['E36E738D69173C13D709E44F2F455E2824D18DDF'] assert_response success end @@ -81,7 +80,7 @@ class Nickserver::DispatcherTest < Minitest::Test def handle(params = {}) @headers = params.delete(:headers) || {} - @params = Hash[ params.map{ |k,v| [k.to_s, v] } ] + @params = Hash[params.map { |k, v| [k.to_s, v] }] end def assert_response(response) @@ -115,7 +114,7 @@ class Nickserver::DispatcherTest < Minitest::Test end def success - response status: 200, content: "fake content" + response status: 200, content: 'fake content' end def not_found @@ -128,7 +127,7 @@ class Nickserver::DispatcherTest < Minitest::Test def http_connection_error response status: 502, - content: JSON.dump(error: "HTTP::ConnectionError") + content: JSON.dump(error: 'HTTP::ConnectionError') end def response(options) @@ -142,5 +141,4 @@ class Nickserver::DispatcherTest < Minitest::Test def responder @responder ||= Minitest::Mock.new end - end diff --git a/test/integration/hkp_test.rb b/test/integration/hkp_test.rb index da128c2..c12588c 100644 --- a/test/integration/hkp_test.rb +++ b/test/integration/hkp_test.rb @@ -70,7 +70,7 @@ class HkpTest < Minitest::Test end def test_fetch_key_too_short - uid = 'chiiph@leap.se' + uid = 'chiiph@leap.se' stubbing_http do stub_sks_vindex_reponse(uid, body: file_content(:short_key_vindex_result)) @@ -86,13 +86,13 @@ class HkpTest < Minitest::Test end end - def assert_response_for_uid(uid, &block) + def assert_response_for_uid(uid) Nickserver::Hkp::Source.new(adapter).query uid do |response| yield response end end - def assert_key_info_for_uid(uid, &block) + def assert_key_info_for_uid(uid) Nickserver::Hkp::Source.new(adapter).search uid do |status, keys| assert_equal 200, status yield keys @@ -105,5 +105,4 @@ class HkpTest < Minitest::Test assert_key_info_for_uid(uid, &block) end end - end diff --git a/test/integration/nickserver_test.rb b/test/integration/nickserver_test.rb index 5dffcd2..fb9b952 100644 --- a/test/integration/nickserver_test.rb +++ b/test/integration/nickserver_test.rb @@ -33,9 +33,9 @@ class NickserverTest < CelluloidTest stub_sks_get_reponse(key_id, body: file_content(:leap_public_key)) start do - params = {query: {"address" => uid}} + params = { query: { 'address' => uid } } get(params) do |response| - assert_equal file_content(:leap_public_key), JSON.parse(response.to_s)["openpgp"] + assert_equal file_content(:leap_public_key), JSON.parse(response.to_s)['openpgp'] end end end @@ -45,19 +45,19 @@ class NickserverTest < CelluloidTest stub_sks_get_reponse(fingerprint, body: file_content(:leap_public_key)) start do - params = {query: {"fingerprint" => fingerprint}} + params = { query: { 'fingerprint' => fingerprint } } get(params) do |response| - assert_equal file_content(:leap_public_key), JSON.parse(response.to_s)["openpgp"] + assert_equal file_content(:leap_public_key), JSON.parse(response.to_s)['openpgp'] end end end def test_GET_served_via_couch_not_found - domain = "example.org" - uid = "bananas@" + domain + domain = 'example.org' + uid = 'bananas@' + domain stub_couch_response(uid, status: 404) do start do - params = {query: {"address" => uid}, head: {"Host" => domain}} + params = { query: { 'address' => uid }, head: { 'Host' => domain } } get(params) do |response| assert_equal 404, response.code end @@ -66,11 +66,11 @@ class NickserverTest < CelluloidTest end def test_GET_served_via_couch_empty_results - domain = "example.org" - uid = "stompy@" + domain + domain = 'example.org' + uid = 'stompy@' + domain stub_couch_response(uid, body: file_content(:empty_couchdb_result)) do start do - params = {query: {"address" => uid}, head: {host: domain}} + params = { query: { 'address' => uid }, head: { host: domain } } get(params) do |response| assert_equal 404, response.code end @@ -79,11 +79,11 @@ class NickserverTest < CelluloidTest end def test_GET_served_via_couch_success - domain = "example.org" - uid = "blue@" + domain + domain = 'example.org' + uid = 'blue@' + domain stub_couch_response(uid, body: file_content(:blue_couchdb_result)) do start do - params = {query: {"address" => uid}, head: {"Host" => domain}} + params = { query: { 'address' => uid }, head: { 'Host' => domain } } get(params) do |response| assert_equal file_content(:blue_nickserver_result), response.to_s end @@ -104,7 +104,7 @@ class NickserverTest < CelluloidTest # # start nickserver # - def start(timeout = 1) + def start(_timeout = 1) server = Nickserver::ReelServer.new '127.0.0.1', config.port stubbing_http do yield server @@ -133,10 +133,9 @@ class NickserverTest < CelluloidTest # this works because http requests to 127.0.0.1 are not stubbed, but requests to other domains are. # def request(method, options = {}) - response = HTTP. - headers(options.delete(:head)). - request method, "http://127.0.0.1:#{config.port}/", options + response = HTTP + .headers(options.delete(:head)) + .request method, "http://127.0.0.1:#{config.port}/", options yield response end - end diff --git a/test/remote/celluloid_http_test.rb b/test/remote/celluloid_http_test.rb index da5f5d7..b315c6b 100644 --- a/test/remote/celluloid_http_test.rb +++ b/test/remote/celluloid_http_test.rb @@ -3,7 +3,6 @@ require 'support/celluloid_test' require 'nickserver/adapters/celluloid_http' class Nickserver::Adapters::CelluloidHttpTest < CelluloidTest - def test_https_for_hkp url = Nickserver::Config.hkp_url status, _body = adapter.get url diff --git a/test/remote/hkp_source_test.rb b/test/remote/hkp_source_test.rb index c246097..8232dce 100644 --- a/test/remote/hkp_source_test.rb +++ b/test/remote/hkp_source_test.rb @@ -19,8 +19,8 @@ class RemoteHkpSourceTest < CelluloidTest ca_file = file_path('mayfirst-ca.pem') config.stub(:hkp_url, hkp_url) do + # config.stub(:hkp_ca_file, file_path('autistici-ca.pem')) do config.stub(:hkp_ca_file, ca_file) do - #config.stub(:hkp_ca_file, file_path('autistici-ca.pem')) do assert File.exist?(Nickserver::Config.hkp_ca_file) uid = 'elijah@riseup.net' assert_key_info_for_uid uid do |keys| diff --git a/test/remote/nicknym_source_test.rb b/test/remote/nicknym_source_test.rb index b97f2b2..6fff1f6 100644 --- a/test/remote/nicknym_source_test.rb +++ b/test/remote/nicknym_source_test.rb @@ -48,8 +48,8 @@ class RemoteNicknymSourceTest < CelluloidTest def assert_pgp_key_in(response) json = JSON.parse response.content - assert_equal email_with_key.to_s, json["address"] - refute_empty json["openpgp"] + assert_equal email_with_key.to_s, json['address'] + refute_empty json['openpgp'] rescue JSON::ParserError skip "invalid json response: #{response.content}" end @@ -65,5 +65,4 @@ class RemoteNicknymSourceTest < CelluloidTest def email_without_key Nickserver::EmailAddress.new('pleaseneverusethisemailweuseittotest@mail.bitmask.net') end - end diff --git a/test/remote/wkd_source_test.rb b/test/remote/wkd_source_test.rb index acb6759..7eaab79 100644 --- a/test/remote/wkd_source_test.rb +++ b/test/remote/wkd_source_test.rb @@ -27,8 +27,8 @@ class RemoteWkdSourceTest < CelluloidTest def assert_pgp_key_in(response) json = JSON.parse response.content - assert_equal email_with_key.to_s, json["address"] - refute_empty json["openpgp"] + assert_equal email_with_key.to_s, json['address'] + refute_empty json['openpgp'] assert_equal file_content('dewey.pgp.asc'), json['openpgp'] end diff --git a/test/support/celluloid_test.rb b/test/support/celluloid_test.rb index ddcfcbb..a00edff 100644 --- a/test/support/celluloid_test.rb +++ b/test/support/celluloid_test.rb @@ -1,5 +1,4 @@ class CelluloidTest < Minitest::Test - def setup super Celluloid.boot @@ -10,5 +9,4 @@ class CelluloidTest < Minitest::Test Celluloid.shutdown super end - end diff --git a/test/support/functional_test.rb b/test/support/functional_test.rb index 4ebc40a..ceabfea 100644 --- a/test/support/functional_test.rb +++ b/test/support/functional_test.rb @@ -2,28 +2,27 @@ require 'minitest/autorun' require 'minitest/pride' class FunctionalTest < Minitest::Test - protected def nickserver_pid - status = nickserver "status" + status = nickserver 'status' /process id (\d*)\./.match(status)[1] end def assert_running - status = nickserver "status" - assert_includes status, "Nickserver running" + status = nickserver 'status' + assert_includes status, 'Nickserver running' end def assert_stopped - status = nickserver "status" - assert_includes status, "No nickserver processes are running." + status = nickserver 'status' + assert_includes status, 'No nickserver processes are running.' end def assert_command_runs(command) out = nickserver command - assert ($?.exitstatus == 0), - "failed to run 'nickserver #{command}':\n #{out}" + assert ($CHILD_STATUS.exitstatus == 0), + "failed to run 'nickserver #{command}':\n #{out}" end def nickserver(command) @@ -37,5 +36,4 @@ class FunctionalTest < Minitest::Test def self.path_to_executable File.expand_path(File.dirname(__FILE__) + '/../../bin/nickserver') end - end diff --git a/test/support/http_adapter_helper.rb b/test/support/http_adapter_helper.rb index 6817e1e..a22b696 100644 --- a/test/support/http_adapter_helper.rb +++ b/test/support/http_adapter_helper.rb @@ -1,7 +1,6 @@ require 'nickserver/adapters/celluloid_http' module HttpAdapterHelper - def setup super @adapter = Nickserver::Adapters::CelluloidHttp.new @@ -15,5 +14,4 @@ module HttpAdapterHelper protected attr_reader :adapter - end diff --git a/test/support/http_stub_helper.rb b/test/support/http_stub_helper.rb index cc9196e..ee50698 100644 --- a/test/support/http_stub_helper.rb +++ b/test/support/http_stub_helper.rb @@ -1,6 +1,7 @@ require 'nickserver/reel_server' module HttpStubHelper + protected def stubbing_http Nickserver::ReelServer::DEFAULT_ADAPTER_CLASS.stub :new, adapter do @@ -11,18 +12,35 @@ module HttpStubHelper def stub_nicknym_available_response(domain, response = {}) stub_http_get "https://#{domain}/provider.json", - response, - Hash + response, + Hash end - def stub_sks_vindex_reponse(uid, response = {}) - stub_http_get config.hkp_url, response, - query: {op: 'vindex', search: uid, exact: 'on', options: 'mr', fingerprint: 'on'} + def stub_sks_vindex_reponse(_uid, response = {}) + stub_http_get config.hkp_url, + response, + query: vindex_query end - def stub_sks_get_reponse(key_id, response = {}) - stub_http_get config.hkp_url, response, - query: {op: 'get', search: "0x"+key_id, exact: 'on', options: 'mr'} + def vindex_query + { op: 'vindex', + search: uid, + exact: 'on', + options: 'mr', + fingerprint: 'on' } + end + + def stub_sks_get_reponse(_key_id, response = {}) + stub_http_get config.hkp_url, + response, + query: sks_get_query + end + + def sks_get_query + { op: 'get', + search: '0x' + key_id, + exact: 'on', + options: 'mr' } end def stub_couch_response(uid, response = {}) @@ -30,12 +48,10 @@ module HttpStubHelper stub_http_get(/#{Regexp.escape(config.couch_url)}.*#{query}/, response) end - private - def stub_http_get(url, response, options = nil) - response = {status: 200, body: ""}.merge(response || {}) + response = { status: 200, body: '' }.merge(response || {}) adapter.expect :get, [response[:status], response[:body]], - [url, options].compact + [url, options].compact end def adapter diff --git a/test/support/request_handler_test_helper.rb b/test/support/request_handler_test_helper.rb index c063108..292f99c 100644 --- a/test/support/request_handler_test_helper.rb +++ b/test/support/request_handler_test_helper.rb @@ -1,7 +1,6 @@ require 'nickserver/request' module RequestHandlerTestHelper - protected def assert_refuses(opts = {}) @@ -33,9 +32,8 @@ module RequestHandlerTestHelper end def request(opts = {}) - params = {'address' => [opts[:email]]} - headers = {'Host' => opts[:domain]} + params = { 'address' => [opts[:email]] } + headers = { 'Host' => opts[:domain] } Nickserver::Request.new params, headers end - end diff --git a/test/test_helper.rb b/test/test_helper.rb index 06e8e78..1d48c63 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -23,7 +23,7 @@ class Minitest::Test end def file_path(filename) - "%s/files/%s" % [File.dirname(__FILE__), filename] + format('%s/files/%s', File.dirname(__FILE__), filename) end def config diff --git a/test/unit/adapters/http_test.rb b/test/unit/adapters/http_test.rb index f6768df..5bf3468 100644 --- a/test/unit/adapters/http_test.rb +++ b/test/unit/adapters/http_test.rb @@ -3,7 +3,6 @@ require 'http' require 'nickserver/adapters/http' class HttpAdapterTest < Minitest::Test - def test_normal_raise stub_http_to_raise do assert_raises HTTP::ConnectionError do @@ -29,7 +28,7 @@ class HttpAdapterTest < Minitest::Test protected def stub_http_to_raise(&block) - raises_exception = -> (*_args) { + raises_exception = lambda { |*_args| raise HTTP::ConnectionError, 'for some reason' } HTTP.stub :get, raises_exception, &block diff --git a/test/unit/couch_db/response_test.rb b/test/unit/couch_db/response_test.rb index d44760d..3003307 100644 --- a/test/unit/couch_db/response_test.rb +++ b/test/unit/couch_db/response_test.rb @@ -6,20 +6,20 @@ class Nickserver::CouchDB::ResponseTest < Minitest::Test include FileContent def test_404 - response = response_for "bananas@example.org", - status: 404, body: "{}" + response = response_for 'bananas@example.org', + status: 404, body: '{}' assert_equal 404, response.status end def test_200_with_empty_response - response = response_for "stompy@example.org", - status: 200, body: file_content(:empty_couchdb_result) + response = response_for 'stompy@example.org', + status: 200, body: file_content(:empty_couchdb_result) assert_equal 404, response.status end def test_200_with_success - response = response_for "blue@example.org", - status: 200, body: file_content(:blue_couchdb_result) + response = response_for 'blue@example.org', + status: 200, body: file_content(:blue_couchdb_result) assert_equal 200, response.status assert_equal file_content(:blue_nickserver_result), response.content end diff --git a/test/unit/couch_db/source_unit_test.rb b/test/unit/couch_db/source_unit_test.rb index e5a4f43..d14ff2f 100644 --- a/test/unit/couch_db/source_unit_test.rb +++ b/test/unit/couch_db/source_unit_test.rb @@ -3,21 +3,20 @@ require 'nickserver/couch_db/source' module Nickserver::CouchDB class SourceUnitTest < Minitest::Test - def test_query - address = "nick@domain.tl" + address = 'nick@domain.tl' adapter = Minitest::Mock.new adapter.expect :get, [200, nil], - [String, {query: { reduce: "false", key: "\"#{address}\"" }}] + [String, { query: { reduce: 'false', key: "\"#{address}\"" } }] Source.new(adapter).query address adapter.verify end def test_401 - address = "nick@domain.tl" + address = 'nick@domain.tl' adapter = Minitest::Mock.new adapter.expect :get, [401, nil], - [String, {query: { reduce: "false", key: "\"#{address}\"" }}] + [String, { query: { reduce: 'false', key: "\"#{address}\"" } }] assert_raises Error do Source.new(adapter).query address end diff --git a/test/unit/email_address_test.rb b/test/unit/email_address_test.rb index 2fea65d..983e979 100644 --- a/test/unit/email_address_test.rb +++ b/test/unit/email_address_test.rb @@ -2,7 +2,6 @@ require 'test_helper' require 'nickserver/email_address' class EmailAddressTest < Minitest::Test - def test_domain nick = Nickserver::EmailAddress.new 'nick@test.me' assert_equal 'test.me', nick.domain @@ -24,5 +23,4 @@ class EmailAddressTest < Minitest::Test nick = Nickserver::EmailAddress.new 'asdf' assert nick.invalid? end - end diff --git a/test/unit/error_response_test.rb b/test/unit/error_response_test.rb index 7242b38..5b81e46 100644 --- a/test/unit/error_response_test.rb +++ b/test/unit/error_response_test.rb @@ -2,11 +2,9 @@ require 'test_helper' require 'nickserver/error_response' class ErrorResponseTest < Minitest::Test - def test_content - response = Nickserver::ErrorResponse.new "Not a valid address" + response = Nickserver::ErrorResponse.new 'Not a valid address' assert_equal "500 Not a valid address\n", response.content assert_equal 500, response.status end - end diff --git a/test/unit/handler_chain_test.rb b/test/unit/handler_chain_test.rb index fae0418..1d79f18 100644 --- a/test/unit/handler_chain_test.rb +++ b/test/unit/handler_chain_test.rb @@ -2,7 +2,6 @@ require 'test_helper' require 'nickserver/handler_chain' class HandlerChainTest < Minitest::Test - def test_initialization assert chain end @@ -12,14 +11,14 @@ class HandlerChainTest < Minitest::Test end def test_triggering_handlers - handler_mock.expect :call, nil, [:a, :b] + handler_mock.expect :call, nil, %i[a b] chain handler_mock chain.handle :a, :b handler_mock.verify end def test_returns_handler_result - chain handler_with_nil, handler_with_result + chain handler_with_nil, handler_with_result assert_equal :result, chain.handle end @@ -55,14 +54,14 @@ class HandlerChainTest < Minitest::Test end def handler_with_nil - Proc.new {} + proc {} end def handler_with_result - Proc.new { :result } + proc { :result } end def handler_raising(exception = RuntimeError) - Proc.new { raise exception } + proc { raise exception } end end diff --git a/test/unit/hkp/client_test.rb b/test/unit/hkp/client_test.rb index 9784d0a..8941c5e 100644 --- a/test/unit/hkp/client_test.rb +++ b/test/unit/hkp/client_test.rb @@ -3,22 +3,21 @@ require 'nickserver/hkp/client' module Nickserver::Hkp class ClientTest < Minitest::Test - def test_get_key_infos_by_email - adapter_expects_query op: "vindex", - search: email, - options: "mr", - fingerprint: "on", - exact: "on" + adapter_expects_query op: 'vindex', + search: email, + options: 'mr', + fingerprint: 'on', + exact: 'on' client.get_key_infos_by_email(email) @adapter.verify end def test_key_by_fingerprint - adapter_expects_query op: "get", - search: "0x#{fingerprint}", - options: "mr", - exact: "on" + adapter_expects_query op: 'get', + search: "0x#{fingerprint}", + options: 'mr', + exact: 'on' client.get_key_by_fingerprint(fingerprint) @adapter.verify end @@ -34,7 +33,7 @@ module Nickserver::Hkp def adapter_expects(*args) @adapter = Minitest::Mock.new @adapter.expect :get, dummy_response, - args + args end def email @@ -48,6 +47,5 @@ module Nickserver::Hkp def dummy_response [200, 'dummy_response'] end - end end diff --git a/test/unit/hkp/v_index_response_test.rb b/test/unit/hkp/v_index_response_test.rb index d909520..270409a 100644 --- a/test/unit/hkp/v_index_response_test.rb +++ b/test/unit/hkp/v_index_response_test.rb @@ -7,7 +7,7 @@ class Nickserver::Hkp::VIndexResponseTest < Minitest::Test def test_leap_public_key response = response_for 'cloudadmin@leap.se', - body: file_content(:leap_vindex_result) + body: file_content(:leap_vindex_result) assert_equal 'E818C478D3141282F7590D29D041EB11B1647490', response.keys.first.keyid end diff --git a/test/unit/logging_responder_test.rb b/test/unit/logging_responder_test.rb index bb6c4a0..9053860 100644 --- a/test/unit/logging_responder_test.rb +++ b/test/unit/logging_responder_test.rb @@ -3,10 +3,9 @@ require 'nickserver/logging_responder' module Nickserver class LoggingResponderTest < Minitest::Test - def test_responds_and_logs - logger.expect :info, nil, [" -> 200"] - respond_to 200, "body" + logger.expect :info, nil, [' -> 200'] + respond_to 200, 'body' logger.verify end @@ -26,6 +25,5 @@ module Nickserver def logger @logger ||= Minitest::Mock.new end - end end diff --git a/test/unit/nicknym/source_test.rb b/test/unit/nicknym/source_test.rb index b17f22b..040e0eb 100644 --- a/test/unit/nicknym/source_test.rb +++ b/test/unit/nicknym/source_test.rb @@ -5,7 +5,6 @@ require 'nickserver/nicknym/source' require 'nickserver/email_address' class NicknymSourceTest < Minitest::Test - def test_initialization assert source end @@ -39,7 +38,7 @@ class NicknymSourceTest < Minitest::Test def proxies_query_response?(status = 0, body = nil) adapter.expect :get, [status, body], - ['https://nicknym.leap_powered.tld:6425', query: {address: email_stub.to_s}] + ['https://nicknym.leap_powered.tld:6425', query: { address: email_stub.to_s }] response = source.query(email_stub) assert_equal status, response.status assert_equal body, response.content @@ -48,10 +47,10 @@ class NicknymSourceTest < Minitest::Test def available_on?(*args) adapter.expect :get, args, - ['https://remote.tld/provider.json', Hash] + ['https://remote.tld/provider.json', Hash] available = source.available_for?('remote.tld') adapter.verify - return available + available end def source diff --git a/test/unit/request_handlers/local_email_handler_test.rb b/test/unit/request_handlers/local_email_handler_test.rb index 1645451..badf3d6 100644 --- a/test/unit/request_handlers/local_email_handler_test.rb +++ b/test/unit/request_handlers/local_email_handler_test.rb @@ -32,5 +32,4 @@ class LocalEmailHandlerTest < MiniTest::Test def source_class Nickserver::CouchDB::Source end - end diff --git a/test/unit/request_test.rb b/test/unit/request_test.rb index eee01c3..7010d9c 100644 --- a/test/unit/request_test.rb +++ b/test/unit/request_test.rb @@ -2,7 +2,6 @@ require 'test_helper' require 'nickserver/request' class Nickserver::RequestTest < Minitest::Test - def test_email request = request_with_params address: fake_email assert_equal fake_email, request.email @@ -19,8 +18,7 @@ class Nickserver::RequestTest < Minitest::Test end def test_domain - request = Nickserver::Request.new Hash.new, - 'Host' => ' nicknym.my.domain.tld:123' + request = Nickserver::Request.new({}, 'Host' => ' nicknym.my.domain.tld:123') assert_equal 'my.domain.tld', request.domain end @@ -29,7 +27,7 @@ class Nickserver::RequestTest < Minitest::Test # params are encoded with strings as keys and arrays with the # given value(s) def request_with_params(params = {}) - params = params.collect{|k,v| [k.to_s, Array(v)]}.to_h + params = params.collect { |k, v| [k.to_s, Array(v)] }.to_h Nickserver::Request.new params, {} end @@ -40,5 +38,4 @@ class Nickserver::RequestTest < Minitest::Test def fake_fingerprint 'F' * 40 end - end diff --git a/test/unit/response_test.rb b/test/unit/response_test.rb index ac7a3a8..401f8ee 100644 --- a/test/unit/response_test.rb +++ b/test/unit/response_test.rb @@ -2,11 +2,9 @@ require 'test_helper' require 'nickserver/response' class ResponseTest < Minitest::Test - def test_ok_response - response = Nickserver::Response.new 200, "content" - assert_equal "content", response.content + response = Nickserver::Response.new 200, 'content' + assert_equal 'content', response.content assert_equal 200, response.status end - end diff --git a/test/unit/test_helper.rb b/test/unit/test_helper.rb deleted file mode 100644 index ade21a0..0000000 --- a/test/unit/test_helper.rb +++ /dev/null @@ -1 +0,0 @@ -require File.dirname(File.dirname(__FILE__)) + '/test_helper'
\ No newline at end of file diff --git a/test/unit/wkd/url_test.rb b/test/unit/wkd/url_test.rb index 1f875b5..d4e0e28 100644 --- a/test/unit/wkd/url_test.rb +++ b/test/unit/wkd/url_test.rb @@ -25,7 +25,7 @@ module Nickserver::Wkd end def test_user_url - 'https://test.gnupg.org/.well-known/openpgpkey/hu/' + + 'https://test.gnupg.org/.well-known/openpgpkey/hu/' \ '1g8totoxbt4zf6na1sukczp5fiewr1oe' end @@ -34,7 +34,7 @@ module Nickserver::Wkd end def sample_url - 'https://example.org/.well-known/openpgpkey/hu/' + + 'https://example.org/.well-known/openpgpkey/hu/' \ 'iy9q119eutrkn8s1mk4r39qejnbu3n5q' end end diff --git a/test/unit/zbase_test.rb b/test/unit/zbase_test.rb index 97f0fc5..e2997a3 100644 --- a/test/unit/zbase_test.rb +++ b/test/unit/zbase_test.rb @@ -3,9 +3,8 @@ require 'minitest/autorun' require 'zbase32' class Zbase32Test < Minitest::Test - def test_samples - samples.each do |k,v| + samples.each do |k, v| assert_equal k, decode(v) assert_equal v, encode(k) end |