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
vagrant-unbundled-2.0.3.0 vendor/bundle/ruby/2.5.0/gems/httpclient-2.8.3/test/test_include_client.rb
scout-5.9.12 vendor/httpclient/test/test_include_client.rb
vagrant-unbundled-2.0.2.0 vendor/bundle/ruby/2.4.0/gems/httpclient-2.8.3/test/test_include_client.rb
vagrant-unbundled-2.0.2.0 vendor/bundle/ruby/2.5.0/gems/httpclient-2.8.3/test/test_include_client.rb
vagrant-unbundled-2.0.1.0 vendor/bundle/ruby/2.4.0/gems/httpclient-2.8.3/test/test_include_client.rb
vagrant-unbundled-2.0.0.1 vendor/bundle/ruby/2.4.0/gems/httpclient-2.8.3/test/test_include_client.rb
vagrant-unbundled-1.9.8.1 vendor/bundle/ruby/2.4.0/gems/httpclient-2.8.3/test/test_include_client.rb
vagrant-unbundled-1.9.7.1 vendor/bundle/ruby/2.4.0/gems/httpclient-2.8.3/test/test_include_client.rb
vagrant-unbundled-1.9.5.1 vendor/bundle/ruby/2.4.0/gems/httpclient-2.8.3/test/test_include_client.rb
scout-5.9.11 vendor/httpclient/test/test_include_client.rb
vagrant-unbundled-1.9.1.1 vendor/bundle/ruby/2.4.0/gems/httpclient-2.8.3/test/test_include_client.rb
httpclient-2.8.3 test/test_include_client.rb
vagrant-compose-yaml-0.1.3 vendor/bundle/ruby/2.2.0/gems/httpclient-2.8.0/test/test_include_client.rb
vagrant-compose-yaml-0.1.2 vendor/bundle/ruby/2.2.0/gems/httpclient-2.8.0/test/test_include_client.rb
vagrant-compose-yaml-0.1.1 vendor/bundle/ruby/2.2.0/gems/httpclient-2.8.0/test/test_include_client.rb
vagrant-compose-yaml-0.1.0 vendor/bundle/ruby/2.2.0/gems/httpclient-2.8.0/test/test_include_client.rb
httpclient-2.8.2.4 test/test_include_client.rb
httpclient-2.8.2.3 test/test_include_client.rb
httpclient-2.8.2.2 test/test_include_client.rb
httpclient-2.8.2.1 test/test_include_client.rb