Sha256: 35c271240d7adc1d35b0391b842babcb31b114b1695fe74dac76b8fb2037b9e9

Contents?: true

Size: 1.56 KB

Versions: 149

Compression:

Stored size: 1.56 KB

Contents

# -*- encoding: utf-8 -*-
require File.expand_path('helper', File.dirname(__FILE__))

require 'httpclient/include_client'
class TestIncludeClient < Test::Unit::TestCase
  class Widget
      extend HTTPClient::IncludeClient

      include_http_client("http://example.com") do |client|
        client.cookie_manager = nil
        client.agent_name = "iMonkey 4k"
      end
  end

  class OtherWidget
    extend HTTPClient::IncludeClient

    include_http_client
    include_http_client(:method_name => :other_http_client)
  end
  
  class UnrelatedBlankClass ; end

  def test_client_class_level_singleton
    assert_equal Widget.http_client.object_id, Widget.http_client.object_id

    assert_equal Widget.http_client.object_id, Widget.new.http_client.object_id

    assert_not_equal Widget.http_client.object_id, OtherWidget.http_client.object_id
  end

  def test_configured
    assert_equal Widget.http_client.agent_name, "iMonkey 4k"
    assert_nil Widget.http_client.cookie_manager
    assert_equal Widget.http_client.proxy.to_s, "http://example.com"
  end
  
  def test_two_includes
    assert_not_equal OtherWidget.http_client.object_id, OtherWidget.other_http_client.object_id
    
    assert_equal OtherWidget.other_http_client.object_id, OtherWidget.new.other_http_client.object_id          
  end
  
  # meta-programming gone wrong sometimes accidentally
  # adds the class method to _everyone_, a mistake we've made before. 
  def test_not_infected_class_hieararchy
    assert ! Class.respond_to?(:http_client)
    assert ! UnrelatedBlankClass.respond_to?(:http_client)
  end


end

Version data entries

149 entries across 141 versions & 13 rubygems

Version Path
fluent-plugin-google-cloud-logging-on-prem-0.1.0 vendor/ruby/3.1.0/gems/httpclient-2.8.3/test/test_include_client.rb
httpclient-fixcerts-2.8.5 test/test_include_client.rb
vagrant-unbundled-2.2.19.0 vendor/bundle/ruby/3.0.0/gems/httpclient-2.8.3/test/test_include_client.rb
vagrant-unbundled-2.2.18.0 vendor/bundle/ruby/3.0.0/gems/httpclient-2.8.3/test/test_include_client.rb
vagrant-unbundled-2.2.16.0 vendor/bundle/ruby/2.7.0/gems/httpclient-2.8.3/test/test_include_client.rb
vagrant-unbundled-2.2.16.0 vendor/bundle/ruby/3.0.0/gems/httpclient-2.8.3/test/test_include_client.rb
video_chat_get-0.1.9 vendor/bundle/ruby/2.5.0/gems/httpclient-2.8.3/test/test_include_client.rb
vagrant-unbundled-2.2.14.0 vendor/bundle/ruby/2.7.0/gems/httpclient-2.8.3/test/test_include_client.rb
video_chat_get-0.1.6 vendor/bundle/ruby/2.5.0/gems/httpclient-2.8.3/test/test_include_client.rb
vagrant-unbundled-2.2.10.0 vendor/bundle/ruby/2.7.0/gems/httpclient-2.8.3/test/test_include_client.rb
video_chat_get-0.1.5 vendor/bundle/ruby/2.5.0/gems/httpclient-2.8.3/test/test_include_client.rb
video_chat_get-0.1.4 vendor/bundle/ruby/2.5.0/gems/httpclient-2.8.3/test/test_include_client.rb
video_chat_get-0.1.3 vendor/bundle/ruby/2.5.0/gems/httpclient-2.8.3/test/test_include_client.rb
video_chat_get-0.1.2 vendor/bundle/ruby/2.5.0/gems/httpclient-2.8.3/test/test_include_client.rb
video_chat_get-0.1.1 vendor/bundle/ruby/2.5.0/gems/httpclient-2.8.3/test/test_include_client.rb
video_chat_get-0.1.0 vendor/bundle/ruby/2.5.0/gems/httpclient-2.8.3/test/test_include_client.rb
vagrant-unbundled-2.2.9.0 vendor/bundle/ruby/2.7.0/gems/httpclient-2.8.3/test/test_include_client.rb
vagrant-unbundled-2.2.8.0 vendor/bundle/ruby/2.7.0/gems/httpclient-2.8.3/test/test_include_client.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.6.0/gems/httpclient-2.8.3/test/test_include_client.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.4.0/gems/httpclient-2.8.3/test/test_include_client.rb