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
httpclient-2.5.3.1 test/test_include_client.rb
httpclient-2.5.3 test/test_include_client.rb
httpclient-2.5.2 test/test_include_client.rb
httpclient-2.5.1 test/test_include_client.rb
scout-5.9.7.2.pre vendor/httpclient/test/test_include_client.rb
httpclient-2.5.0 test/test_include_client.rb
scout-5.9.8.pre vendor/httpclient/test/test_include_client.rb
scout-5.9.7.1 vendor/httpclient/test/test_include_client.rb
glebtv-httpclient-3.2.8 test/test_include_client.rb
scout-5.9.7.pre vendor/httpclient/test/test_include_client.rb
vagrant-tiktalik-0.0.3 vendor/bundle/ruby/2.0.0/gems/httpclient-2.4.0/test/test_include_client.rb
scout-5.9.5 vendor/httpclient/test/test_include_client.rb
scout-5.9.4 vendor/httpclient/test/test_include_client.rb
scout-5.9.4.pre vendor/httpclient/test/test_include_client.rb
httpclient-2.4.0 test/test_include_client.rb
climine-0.0.7 vendor/bundle/ruby/2.0.0/gems/httpclient-2.3.4.1/test/test_include_client.rb
scout-5.9.3 vendor/httpclient/test/test_include_client.rb
glebtv-httpclient-3.2.7 test/test_include_client.rb
glebtv-httpclient-3.2.6 test/test_include_client.rb
glebtv-httpclient-3.2.4 test/test_include_client.rb