<commit_before>require File.join(File.dirname(__FILE__), "test_helper")

class TestFakeWeb < Test::Unit::TestCase

  def setup
    FakeWeb.allow_net_connect = true
    FakeWeb.clean_registry
  end

  def test_register_uri
    FakeWeb.register_uri('http://mock/test_example.txt', :string => "example")
    assert FakeWeb.registered_uri?('http://mock/test_example.txt')
  end

  def test_register_uri_with_wrong_number_of_arguments
    assert_raises ArgumentError do
      FakeWeb.register_uri("http://example.com")
    end
    assert_raises ArgumentError do
      FakeWeb.register_uri(:get, "http://example.com", "/example", :string => "example")
    end
  end

  def test_registered_uri_with_wrong_number_of_arguments
    assert_raises ArgumentError do
      FakeWeb.registered_uri?
    end
    assert_raises ArgumentError do
      FakeWeb.registered_uri?(:get, "http://example.com", "/example")
    end
  end

  def test_response_for_with_wrong_number_of_arguments
    assert_raises ArgumentError do
      FakeWeb.response_for
    end
    assert_raises ArgumentError do
      FakeWeb.response_for(:get, "http://example.com", "/example")
    end
  end

  def test_register_uri_without_domain_name
    assert_raises URI::InvalidURIError do
      FakeWeb.register_uri('test_example2.txt', File.dirname(__FILE__) + '/fixtures/test_example.txt')
    end
  end

  def test_register_uri_with_port_and_check_with_port
    FakeWeb.register_uri('http://example.com:3000/', :string => 'foo')
    assert FakeWeb.registered_uri?('http://example.com:3000/')
  end

  def test_register_uri_with_port_and_check_without_port
    FakeWeb.register_uri('http://example.com:3000/', :string => 'foo')
    assert !FakeWeb.registered_uri?('http://example.com/')
  end

  def test_register_uri_with_default_port_for_http_and_check_without_port
    FakeWeb.register_uri('http://example.com:80/', :string => 'foo')
    assert FakeWeb.registered_uri?('http://example.com/')
  end

  def test_register_uri_with_default_port_for_https_and_check_without_port
    FakeWeb.register_uri('https://example.com:443/', :string => 'foo')
    assert FakeWeb.registered_uri?('https://example.com/')
  end

  def test_register_uri_with_no_port_for_http_and_check_with_default_port
    FakeWeb.register_uri('http://example.com/', :string => 'foo')
    assert FakeWeb.registered_uri?('http://example.com:80/')
  end

  def test_register_uri_with_no_port_for_https_and_check_with_default_port
    FakeWeb.register_uri('https://example.com/', :string => 'foo')
    assert FakeWeb.registered_uri?('https://example.com:443/')
  end

  def test_register_uri_for_any_method_explicitly
    FakeWeb.register_uri(:any, "http://example.com/rpc_endpoint", :string => "OK")
    assert FakeWeb.registered_uri?(:get, "http://example.com/rpc_endpoint")
    assert FakeWeb.registered_uri?(:post, "http://example.com/rpc_endpoint")
    assert FakeWeb.registered_uri?(:put, "http://example.com/rpc_endpoint")
    assert FakeWeb.registered_uri?(:delete, "http://example.com/rpc_endpoint")
    assert FakeWeb.registered_uri?(:any, "http://example.com/rpc_endpoint")
    assert FakeWeb.registered_uri?("http://example.com/rpc_endpoint")
  end

  def test_register_uri_for_get_method_only
    FakeWeb.register_uri(:get, "http://example.com/users", :string => "User list")
    assert FakeWeb.registered_uri?(:get, "http://example.com/users")
    assert !FakeWeb.registered_uri?(:post, "http://example.com/users")
    assert !FakeWeb.registered_uri?(:put, "http://example.com/users")
    assert !FakeWeb.registered_uri?(:delete, "http://example.com/users")
    assert !FakeWeb.registered_uri?(:any, "http://example.com/users")
    assert !FakeWeb.registered_uri?("http://example.com/users")
  end

  def test_response_for_with_registered_uri
    FakeWeb.register_uri('http://mock/test_example.txt', :file => File.dirname(__FILE__) + '/fixtures/test_example.txt')
    assert_equal 'test example content', FakeWeb.response_for('http://mock/test_example.txt').body
  end

  def test_response_for_with_unknown_uri
    assert_equal nil, FakeWeb.response_for(:get, 'http://example.com/')<commit_msg>Add test coverage for a couple corner cases in FakeWeb.register_uri<commit_after>require File.join(File.dirname(__FILE__), "test_helper")

class TestFakeWeb < Test::Unit::TestCase

  def setup
    FakeWeb.allow_net_connect = true
    FakeWeb.clean_registry
  end

  def test_register_uri
    FakeWeb.register_uri('http://mock/test_example.txt', :string => "example")
    assert FakeWeb.registered_uri?('http://mock/test_example.txt')
  end

  def test_register_uri_with_wrong_number_of_arguments
    assert_raises ArgumentError do
      FakeWeb.register_uri("http://example.com")
    end
    assert_raises ArgumentError do
      FakeWeb.register_uri(:get, "http://example.com", "/example", :string => "example")
    end
  end

  def test_registered_uri_with_wrong_number_of_arguments
    assert_raises ArgumentError do
      FakeWeb.registered_uri?
    end
    assert_raises ArgumentError do
      FakeWeb.registered_uri?(:get, "http://example.com", "/example")
    end
  end

  def test_response_for_with_wrong_number_of_arguments
    assert_raises ArgumentError do
      FakeWeb.response_for
    end
    assert_raises ArgumentError do
      FakeWeb.response_for(:get, "http://example.com", "/example")
    end
  end

  def test_register_uri_without_domain_name
    assert_raises URI::InvalidURIError do
      FakeWeb.register_uri('test_example2.txt', File.dirname(__FILE__) + '/fixtures/test_example.txt')
    end
  end

  def test_register_uri_with_port_and_check_with_port
    FakeWeb.register_uri('http://example.com:3000/', :string => 'foo')
    assert FakeWeb.registered_uri?('http://example.com:3000/')
  end

  def test_register_uri_with_port_and_check_without_port
    FakeWeb.register_uri('http://example.com:3000/', :string => 'foo')
    assert !FakeWeb.registered_uri?('http://example.com/')
  end

  def test_register_uri_with_default_port_for_http_and_check_without_port
    FakeWeb.register_uri('http://example.com:80/', :string => 'foo')
    assert FakeWeb.registered_uri?('http://example.com/')
  end

  def test_register_uri_with_default_port_for_https_and_check_without_port
    FakeWeb.register_uri('https://example.com:443/', :string => 'foo')
    assert FakeWeb.registered_uri?('https://example.com/')
  end

  def test_register_uri_with_no_port_for_http_and_check_with_default_port
    FakeWeb.register_uri('http://example.com/', :string => 'foo')
    assert FakeWeb.registered_uri?('http://example.com:80/')
  end

  def test_register_uri_with_no_port_for_https_and_check_with_default_port
    FakeWeb.register_uri('https://example.com/', :string => 'foo')
    assert FakeWeb.registered_uri?('https://example.com:443/')
  end

  def test_register_uri_with_no_port_for_https_and_check_with_443_on_http
    FakeWeb.register_uri('https://example.com/', :string => 'foo')
    assert !FakeWeb.registered_uri?('http://example.com:443/')
  end

  def test_register_uri_with_no_port_for_http_and_check_with_80_on_https
    FakeWeb.register_uri('http://example.com/', :string => 'foo')
    assert !FakeWeb.registered_uri?('https://example.com:80/')
  end

  def test_register_uri_for_any_method_explicitly
    FakeWeb.register_uri(:any, "http://example.com/rpc_endpoint", :string => "OK")
    assert FakeWeb.registered_uri?(:get, "http://example.com/rpc_endpoint")
    assert FakeWeb.registered_uri?(:post, "http://example.com/rpc_endpoint")
    assert FakeWeb.registered_uri?(:put, "http://example.com/rpc_endpoint")
    assert FakeWeb.registered_uri?(:delete, "http://example.com/rpc_endpoint")
    assert FakeWeb.registered_uri?(:any, "http://example.com/rpc_endpoint")
    assert FakeWeb.registered_uri?("http://example.com/rpc_endpoint")
  end

  def test_register_uri_for_get_method_only
    FakeWeb.register_uri(:get, "http://example.com/users", :string => "User list")
    assert FakeWeb.registered_uri?(:get, "http://example.com/users")
    assert !FakeWeb.registered_uri?(:post, "http://example.com/users")
    assert !FakeWeb.registered_uri?(:put, "http://example.com/users")
    assert !FakeWeb.registered_uri?(:delete, "http://example.com/users")
    assert !FakeWeb.registered_uri?(:any, "http://example.com/users")
    assert !FakeWeb.registered_uri?("http://example.com/users")
  end

  def test_response_for_with_registered_uri
    FakeWeb.register_uri('http://mock/test_example.txt', :file => File.dirname(__FILE__) + '/fixtures/test_example.txt')
    assert_equal 'test example content', FakeWeb.response_for('http://mock/test_example.txt').body
  end

  def test_response_for_with_unknown_uri
    assert_equal nil, FakeWeb.response_for(:get, 'http://example.com/')
{'fraction_non_alphanumeric': 0.13098785239514096, 'fraction_numerical': 0.006417602567041027, 'mean_word_length': 4.8688634835238735, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, 'https://': 10, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4515423', 'n_tokens_mistral': 3034, 'n_tokens_neox': 2869, 'n_words': 408}