Added v 0.2.3 snapshot.
[twitter4r-core.git] / spec / twitter / config_spec.rb
blob70899213d7fd90020e38a2c5821651a4e472534b
1 require File.join(File.dirname(__FILE__), '..', 'spec_helper')
3 describe Twitter::Client, ".configure" do
4   it "should respond to :configure class method" do
5     Twitter::Client.respond_to?(:configure).should be(true)
6   end  
8   it "should not accept calls that do not specify blocks" do
9     lambda {
10       Twitter::Client.configure()
11     }.should raise_error(ArgumentError)
12   end  
13 end
15 describe Twitter::Client, ".configure with mocked @config" do
16   before(:each) do
17     @block_invoked = false
18     @conf_yielded = false
19     @conf = mock(Twitter::Config)
20     @block = Proc.new do |conf| 
21       @block_invoked = true
22       @conf_yielded = true if conf.is_a?(Twitter::Config)
23     end
24     Twitter::Config.stub!(:new).and_return(@conf)
25   end
26   
27   it "should not raise an error when passing block" do
28     lambda {
29       Twitter::Client.configure(&@block)
30     }.should_not raise_error
31   end
32   
33   it "should yield a Twitter::Client object to block" do
34     Twitter::Client.configure(&@block)
35     @block_invoked.should be(true)
36     @conf_yielded.should be(true)
37   end
38   
39   after(:each) do
40     nilize(@block, @block_invoked, @conf, @conf_yielded)
41   end
42 end
44 describe Twitter::Config, "#eql?" do
45   before(:each) do
46     @protocol = :ssl
47     @host = 'twitter.com'
48     @port = 443
49     @proxy_host = 'myproxy.host'
50     @proxy_port = 8080
51     attrs = {
52       :protocol => @protocol,
53       :host => @host,
54       :port => @port,
55       :proxy_host => @proxy_host,
56       :proxy_port => @proxy_port,
57     }
58     @obj = stubbed_twitter_config(Twitter::Config.new, attrs)
59     @other = stubbed_twitter_config(Twitter::Config.new, attrs)
60     
61     @different = stubbed_twitter_config(Twitter::Config.new, attrs.merge(:proxy_host => 'different.proxy'))
62     @same = @obj
63   end
64   
65   it "should return true for two logically equivalent objects" do
66     @obj.should be_eql(@other)
67     @other.should be_eql(@obj)
68   end
69   
70   it "should return false for two logically different objects" do
71     @obj.should_not be_eql(@different)
72     @different.should_not be_eql(@obj)
73     @other.should_not be_eql(@different)
74     @different.should_not be_eql(@other)
75   end
76   
77   it "should return true for references to the same object in memory" do
78     @obj.should eql(@same)
79     @same.should eql(@obj)
80     @other.should eql(@other)
81   end
82   
83   after(:each) do
84     nilize(@protocol, @host, @port, @proxy_host, @proxy_port, @obj, @other, @different, @same)
85   end
86 end