Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,5 @@ platform :rbx do
stdlibs = %w(benchmark cgi coverage delegate erb find logger net-http open-uri
optparse ostruct prettyprint singleton tempfile tmpdir yaml)
stdlibs.each { |lib| gem "rubysl-#{lib}", "~> 2.0" }
# rubysl-test-unit 2.0.2's gemspec relaxed its dependency on minitest to allow
# any version (previously, it specified "~> 4.7"). Minitest 5 doesn't have a
# Test::Unit compatibility layer like 4.x, so it doesn't work with Test::Unit
# at all (see e.g. https://github.com/seattlerb/minitest/issues/358). So, I'm
# holding this one back until we find out what's going on.
gem "rubysl-test-unit", "2.0.1"
gem "psych", "~> 2.0"
end
1 change: 1 addition & 0 deletions fakeweb.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Gem::Specification.new do |s|
# Otherwise, prefer up-to-date dev tools
s.add_development_dependency "mocha", ["~> 0.14"] + broken_mocha_spec
s.add_development_dependency "rake", ["~> 10.0"]
s.add_development_dependency "minitest", ["~> 5.0"]

# ZenTest (autotest) wants at least RubyGems 1.8, which is 1.8.7+
# only, as is RDoc, the main dependency of sdoc.
Expand Down
30 changes: 15 additions & 15 deletions test/test_allow_net_connect.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'test_helper'

class TestFakeWebAllowNetConnect < Test::Unit::TestCase
class TestFakeWebAllowNetConnect < Minitest::Test
def test_unregistered_requests_are_passed_through_when_allow_net_connect_is_true
FakeWeb.allow_net_connect = true
setup_expectations_for_real_apple_hot_news_request
Expand All @@ -9,7 +9,7 @@ def test_unregistered_requests_are_passed_through_when_allow_net_connect_is_true

def test_raises_for_unregistered_requests_when_allow_net_connect_is_false
FakeWeb.allow_net_connect = false
assert_raise FakeWeb::NetConnectNotAllowedError do
assert_raises FakeWeb::NetConnectNotAllowedError do
Net::HTTP.get(URI.parse("http://example.com/"))
end
end
Expand Down Expand Up @@ -40,49 +40,49 @@ def test_unregistered_requests_are_passed_through_when_allow_net_connect_is_a_ma

def test_raises_for_unregistered_requests_when_allow_net_connect_is_a_different_string
FakeWeb.allow_net_connect = "http://example.com"
assert_raise FakeWeb::NetConnectNotAllowedError do
assert_raises FakeWeb::NetConnectNotAllowedError do
Net::HTTP.get(URI.parse("http://example.com/path"))
end
end

def test_raises_for_unregistered_requests_when_allow_net_connect_is_a_different_uri
FakeWeb.allow_net_connect = URI.parse("http://example.com")
assert_raise FakeWeb::NetConnectNotAllowedError do
assert_raises FakeWeb::NetConnectNotAllowedError do
Net::HTTP.get(URI.parse("http://example.com/path"))
end
end

def test_raises_for_unregistered_requests_when_allow_net_connect_is_a_non_matching_regexp
FakeWeb.allow_net_connect = %r[example\.net]
assert_raise FakeWeb::NetConnectNotAllowedError do
assert_raises FakeWeb::NetConnectNotAllowedError do
Net::HTTP.get(URI.parse("http://example.com"))
end
end

def test_changing_allow_net_connect_from_string_to_false_corretly_removes_whitelist
FakeWeb.allow_net_connect = "http://example.com"
FakeWeb.allow_net_connect = false
assert_raise FakeWeb::NetConnectNotAllowedError do
assert_raises FakeWeb::NetConnectNotAllowedError do
Net::HTTP.get(URI.parse("http://example.com"))
end
end

def test_changing_allow_net_connect_from_true_to_string_corretly_limits_connections
FakeWeb.allow_net_connect = true
FakeWeb.allow_net_connect = "http://example.com"
assert_raise FakeWeb::NetConnectNotAllowedError do
assert_raises FakeWeb::NetConnectNotAllowedError do
Net::HTTP.get(URI.parse("http://example.net"))
end
end

def test_exception_message_includes_unregistered_request_method_and_uri_but_no_default_port
FakeWeb.allow_net_connect = false
exception = assert_raise FakeWeb::NetConnectNotAllowedError do
exception = assert_raises FakeWeb::NetConnectNotAllowedError do
Net::HTTP.get(URI.parse("http://example.com/"))
end
assert exception.message.include?("GET http://example.com/")

exception = assert_raise FakeWeb::NetConnectNotAllowedError do
exception = assert_raises FakeWeb::NetConnectNotAllowedError do
http = Net::HTTP.new("example.com", 443)
http.use_ssl = true
http.get("/")
Expand All @@ -92,12 +92,12 @@ def test_exception_message_includes_unregistered_request_method_and_uri_but_no_d

def test_exception_message_includes_unregistered_request_port_when_not_default
FakeWeb.allow_net_connect = false
exception = assert_raise FakeWeb::NetConnectNotAllowedError do
exception = assert_raises FakeWeb::NetConnectNotAllowedError do
Net::HTTP.start("example.com", 8000) { |http| http.get("/") }
end
assert exception.message.include?("GET http://example.com:8000/")

exception = assert_raise FakeWeb::NetConnectNotAllowedError do
exception = assert_raises FakeWeb::NetConnectNotAllowedError do
http = Net::HTTP.new("example.com", 4433)
http.use_ssl = true
http.get("/")
Expand All @@ -107,12 +107,12 @@ def test_exception_message_includes_unregistered_request_port_when_not_default

def test_exception_message_includes_unregistered_request_port_when_not_default_with_path
FakeWeb.allow_net_connect = false
exception = assert_raise FakeWeb::NetConnectNotAllowedError do
exception = assert_raises FakeWeb::NetConnectNotAllowedError do
Net::HTTP.start("example.com", 8000) { |http| http.get("/test") }
end
assert exception.message.include?("GET http://example.com:8000/test")

exception = assert_raise FakeWeb::NetConnectNotAllowedError do
exception = assert_raises FakeWeb::NetConnectNotAllowedError do
http = Net::HTTP.new("example.com", 4433)
http.use_ssl = true
http.get("/test")
Expand All @@ -132,7 +132,7 @@ def test_question_mark_method_returns_false_after_setting_allow_net_connect_to_f

def test_question_mark_method_raises_with_no_argument_when_allow_net_connect_is_a_whitelist
FakeWeb.allow_net_connect = "http://example.com"
exception = assert_raise ArgumentError do
exception = assert_raises ArgumentError do
FakeWeb.allow_net_connect?
end
assert_equal "You must supply a URI to test", exception.message
Expand All @@ -156,7 +156,7 @@ def test_question_mark_method_returns_false_when_argument_does_not_match_allow_n
end


class TestFakeWebAllowNetConnectWithCleanState < Test::Unit::TestCase
class TestFakeWebAllowNetConnectWithCleanState < Minitest::Test
# Our test_helper.rb sets allow_net_connect = false in an inherited #setup
# method. Disable that here to test the default setting.
def setup; end
Expand Down
2 changes: 1 addition & 1 deletion test/test_deprecations.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'test_helper'

class TestDeprecations < Test::Unit::TestCase
class TestDeprecations < Minitest::Test

def test_register_uri_without_method_argument_prints_deprecation_warning
warning = capture_stderr do
Expand Down
2 changes: 1 addition & 1 deletion test/test_fake_authentication.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'test_helper'

class TestFakeAuthentication < Test::Unit::TestCase
class TestFakeAuthentication < Minitest::Test

def test_register_uri_with_authentication
FakeWeb.register_uri(:get, 'http://user:pass@mock/test_example.txt', :body => "example")
Expand Down
12 changes: 6 additions & 6 deletions test/test_fake_web.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'test_helper'

class TestFakeWeb < Test::Unit::TestCase
class TestFakeWeb < Minitest::Test

def test_register_uri
FakeWeb.register_uri(:get, 'http://mock/test_example.txt', :body => "example")
Expand Down Expand Up @@ -116,7 +116,7 @@ def test_clean_registry_affects_net_http_requests
response = Net::HTTP.start("example.com") { |query| query.get("/") }
assert_equal "registered", response.body
FakeWeb.clean_registry
assert_raise FakeWeb::NetConnectNotAllowedError do
assert_raises FakeWeb::NetConnectNotAllowedError do
Net::HTTP.start("example.com") { |query| query.get("/") }
end
end
Expand Down Expand Up @@ -508,7 +508,7 @@ def test_mock_rotate_responses
def test_mock_request_using_response_with_transfer_encoding_header_has_valid_transfer_encoding_header
FakeWeb.register_uri(:get, 'http://www.google.com/', :response => fixture_path("google_response_with_transfer_encoding"))
response = Net::HTTP.start('www.google.com') { |query| query.get('/') }
assert_not_nil response['transfer-encoding']
assert !response['transfer-encoding'].nil?
assert response['transfer-encoding'] == 'chunked'
end

Expand All @@ -522,7 +522,7 @@ def test_mock_request_using_response_without_transfer_encoding_header_does_not_h
def test_mock_request_using_response_from_curl_has_original_transfer_encoding_header
FakeWeb.register_uri(:get, 'http://www.google.com/', :response => fixture_path("google_response_from_curl"))
response = Net::HTTP.start('www.google.com') { |query| query.get('/') }
assert_not_nil response['transfer-encoding']
assert !response['transfer-encoding'].nil?
assert response['transfer-encoding'] == 'chunked'
end

Expand All @@ -542,7 +542,7 @@ def test_registering_with_string_containing_null_byte
# The string should be treated as a response body, instead, and an
# EOFError is raised when the byte is encountered.
FakeWeb.register_uri(:get, "http://example.com", :response => "test\0test")
assert_raise EOFError do
assert_raises EOFError do
Net::HTTP.get(URI.parse("http://example.com"))
end

Expand All @@ -555,7 +555,7 @@ def test_registering_with_string_that_is_a_directory_name
# Similar to above, but for Errno::EISDIR being raised since File.exists?
# returns true for directories
FakeWeb.register_uri(:get, "http://example.com", :response => File.dirname(__FILE__))
assert_raise EOFError do
assert_raises EOFError do
Net::HTTP.get(URI.parse("http://example.com"))
end

Expand Down
2 changes: 1 addition & 1 deletion test/test_fake_web_open_uri.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'test_helper'

class TestFakeWebOpenURI < Test::Unit::TestCase
class TestFakeWebOpenURI < Minitest::Test

def test_content_for_registered_uri
FakeWeb.register_uri(:get, 'http://mock/test_example.txt', :body => fixture_path("test_example.txt"))
Expand Down
8 changes: 4 additions & 4 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

require 'helpers/start_simplecov'

require 'test/unit'
require 'minitest/autorun'
require 'open-uri'
require 'pathname'
require 'fake_web'
Expand All @@ -20,7 +20,7 @@
end

# Give all tests a common setup and teardown that prevents shared state
class Test::Unit::TestCase
class Minitest::Test
alias setup_without_fakeweb setup
def setup
FakeWeb.clean_registry
Expand All @@ -36,7 +36,7 @@ def teardown


module FakeWebTestHelper
BUILTIN_ASSERTIONS = Test::Unit::TestCase.instance_methods.select { |m| m.to_s =~ /^assert/ }.map { |m| m.to_sym }
BUILTIN_ASSERTIONS = Minitest::Test.instance_methods.select { |m| m.to_s =~ /^assert/ }.map { |m| m.to_sym }

# Backport assert_empty for Ruby 1.8 (it comes from MiniTest)
if !BUILTIN_ASSERTIONS.include?(:assert_empty)
Expand Down Expand Up @@ -178,4 +178,4 @@ def setup_expectations_for_real_apple_hot_news_request(options = {})

end

Test::Unit::TestCase.send(:include, FakeWebTestHelper)
Minitest::Test.send(:include, FakeWebTestHelper)
2 changes: 1 addition & 1 deletion test/test_last_request.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'test_helper'

class TestLastRequest < Test::Unit::TestCase
class TestLastRequest < Minitest::Test

def test_last_request_returns_correct_net_http_request_class
FakeWeb.register_uri(:get, "http://example.com", :status => [200, "OK"])
Expand Down
2 changes: 1 addition & 1 deletion test/test_missing_open_uri.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'test_helper'

class TestMissingOpenURI < Test::Unit::TestCase
class TestMissingOpenURI < Minitest::Test

def setup
super
Expand Down
2 changes: 1 addition & 1 deletion test/test_missing_pathname.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'test_helper'

class TestMissingPathname < Test::Unit::TestCase
class TestMissingPathname < Minitest::Test

def setup
super
Expand Down
2 changes: 1 addition & 1 deletion test/test_other_net_http_libraries.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Each of these tests shells out to `ruby -rfakeweb ...` so
# we can see how FakeWeb behaves with different combinations of
# other gems loaded without polluting the rest of our tests.
class TestOtherNetHttpLibraries < Test::Unit::TestCase
class TestOtherNetHttpLibraries < Minitest::Test

def capture_output_from_requiring(libs, additional_code = "")
requires = libs.map { |lib| "require '#{lib}'" }.join("; ")
Expand Down
2 changes: 1 addition & 1 deletion test/test_precedence.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'test_helper'

class TestPrecedence < Test::Unit::TestCase
class TestPrecedence < Minitest::Test

def test_matching_get_strings_have_precedence_over_matching_get_regexes
FakeWeb.register_uri(:get, "http://example.com/test", :body => "string")
Expand Down
2 changes: 1 addition & 1 deletion test/test_query_string.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'test_helper'

class TestFakeWebQueryString < Test::Unit::TestCase
class TestFakeWebQueryString < Minitest::Test

def test_register_uri_string_with_query_params
FakeWeb.register_uri(:get, 'http://example.com/?a=1&b=1', :body => 'foo')
Expand Down
4 changes: 2 additions & 2 deletions test/test_regexes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'test_helper'

class TestRegexes < Test::Unit::TestCase
class TestRegexes < Minitest::Test

def test_registered_uri_with_pattern
FakeWeb.register_uri(:get, %r|http://example.com/test_example/\d+|, :body => "example")
Expand Down Expand Up @@ -39,7 +39,7 @@ def test_request_with_authentication_and_pattern_handles_case_insensitivity
def test_requesting_a_uri_that_matches_two_registered_regexes_raises_an_error
FakeWeb.register_uri(:get, %r|http://example\.com/|, :body => "first")
FakeWeb.register_uri(:get, %r|http://example\.com/a|, :body => "second")
assert_raise FakeWeb::MultipleMatchingURIsError do
assert_raises FakeWeb::MultipleMatchingURIsError do
Net::HTTP.start("example.com") { |query| query.get('/a') }
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/test_registering_with_io.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'test_helper'

class TestRegisteringWithIO < Test::Unit::TestCase
class TestRegisteringWithIO < Minitest::Test

def test_registering_a_file_handle_without_transfer_encoding
file = File.new(fixture_path("google_response_without_transfer_encoding"))
Expand Down
2 changes: 1 addition & 1 deletion test/test_response_headers.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'test_helper'

class TestResponseHeaders < Test::Unit::TestCase
class TestResponseHeaders < Minitest::Test
def test_content_type_when_registering_with_string_and_content_type_header_as_symbol_option
FakeWeb.register_uri(:get, "http://example.com/users.json", :body => '[{"username": "chrisk"}]', :content_type => "application/json")
response = Net::HTTP.start("example.com") { |query| query.get("/users.json") }
Expand Down
2 changes: 1 addition & 1 deletion test/test_timeouts.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'test_helper'

class TestTimeouts < Test::Unit::TestCase
class TestTimeouts < Minitest::Test
def test_sending_timeout_accessors_after_starting_session
# this tests an HTTPS request because #ssl_timeout= raises otherwise
FakeWeb.register_uri(:get, "https://example.com", :status => [200, "OK"])
Expand Down
6 changes: 3 additions & 3 deletions test/test_trailing_slashes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'test_helper'

class TestFakeWebTrailingSlashes < Test::Unit::TestCase
class TestFakeWebTrailingSlashes < Minitest::Test

def test_registering_root_without_slash_and_ask_predicate_method_with_slash
FakeWeb.register_uri(:get, "http://www.example.com", :body => "root")
Expand Down Expand Up @@ -32,7 +32,7 @@ def test_registering_path_without_slash_and_ask_predicate_method_with_slash
def test_registering_path_without_slash_and_request_with_slash
FakeWeb.allow_net_connect = false
FakeWeb.register_uri(:get, "http://www.example.com/users", :body => "User list")
assert_raise FakeWeb::NetConnectNotAllowedError do
assert_raises FakeWeb::NetConnectNotAllowedError do
Net::HTTP.start("www.example.com") { |query| query.get('/users/') }
end
end
Expand All @@ -45,7 +45,7 @@ def test_registering_path_with_slash_and_ask_predicate_method_without_slash
def test_registering_path_with_slash_and_request_without_slash
FakeWeb.allow_net_connect = false
FakeWeb.register_uri(:get, "http://www.example.com/users/", :body => "User list")
assert_raise FakeWeb::NetConnectNotAllowedError do
assert_raises FakeWeb::NetConnectNotAllowedError do
Net::HTTP.start("www.example.com") { |query| query.get('/users') }
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/test_utility.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'test_helper'

class TestUtility < Test::Unit::TestCase
class TestUtility < Minitest::Test

def test_decode_userinfo_from_header_handles_basic_auth
authorization_header = "Basic dXNlcm5hbWU6c2VjcmV0"
Expand Down