root/websites/toror/trunk/vendor/plugins/twitter4r/spec/twitter/client/status_spec.rb @ 8678

Revision 8678, 3.5 kB (checked in by niku, 6 years ago)

toror

Line 
1require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
2
3describe Twitter::Client, "#status" do
4  before(:each) do
5    @twitter = client_context
6    @message = 'This is my unique message'
7    @uris = Twitter::Client.class_eval("@@STATUS_URIS")
8    @options = {:id => 666666}
9    @request = mas_net_http_get(:basic_auth => nil)
10    @response = mas_net_http_response(:success, '{}')
11    @connection = mas_net_http(@response)
12    @float = 43.3434
13    @status = Twitter::Status.new(:id => 2349343)
14    @source = Twitter::Client.class_eval("@@defaults[:source]")
15  end
16
17  it "should return nil if nil is passed as value argument for :get case" do
18    status = @twitter.status(:get, nil)
19    status.should be_nil
20  end
21 
22  it "should not call @twitter#http_connect when passing nil for value argument in :get case" do
23    @twitter.should_not_receive(:http_connect)
24    @twitter.status(:get, nil)
25  end
26 
27  it "should create expected HTTP GET request for :get case" do
28    @twitter.should_receive(:create_http_get_request).with(@uris[:get], @options).and_return(@request)
29    @twitter.status(:get, @options[:id])
30  end
31 
32  it "should invoke @twitter#create_http_get_request with given parameters equivalent to {:id => value.to_i} for :get case" do
33    # Float case
34    @twitter.should_receive(:create_http_get_request).with(@uris[:get], {:id => @float.to_i}).and_return(@request)
35    @twitter.status(:get, @float)
36
37    # Twitter::Status object case
38    @twitter.should_receive(:create_http_get_request).with(@uris[:get], {:id => @status.to_i}).and_return(@request)   
39    @twitter.status(:get, @status)
40  end
41 
42  it "should return nil if nil is passed as value argument for :post case" do
43    status = @twitter.status(:post, nil)
44    status.should be_nil
45  end
46 
47  it "should not call @twitter#http_connect when passing nil for value argument in :post case" do
48    @twitter.should_not_receive(:http_connect)
49    @twitter.status(:post, nil)
50  end
51 
52  it "should create expected HTTP POST request for :post case" do
53    @twitter.should_receive(:create_http_post_request).with(@uris[:post]).and_return(@request)
54    @connection.should_receive(:request).with(@request, {:status => @message, :source => @source}.to_http_str).and_return(@response)
55    @twitter.status(:post, @message)
56  end
57 
58  it "should return nil if nil is passed as value argument for :delete case" do
59    status = @twitter.status(:delete, nil)
60    status.should be_nil
61  end
62 
63  it "should not call @twitter#http_connect when passing nil for value argument in :delete case" do
64    @twitter.should_not_receive(:http_connect)
65    @twitter.status(:delete, nil)
66  end
67 
68  it "should create expected HTTP DELETE request for :delete case" do
69    @twitter.should_receive(:create_http_delete_request).with(@uris[:delete], @options).and_return(@request)
70    @twitter.status(:delete, @options[:id])
71  end
72
73  it "should invoke @twitter#create_http_get_request with given parameters equivalent to {:id => value.to_i} for :delete case" do
74    # Float case
75    @twitter.should_receive(:create_http_delete_request).with(@uris[:delete], {:id => @float.to_i}).and_return(@request)
76    @twitter.status(:delete, @float)
77
78    # Twitter::Status object case
79    @twitter.should_receive(:create_http_delete_request).with(@uris[:delete], {:id => @status.to_i}).and_return(@request)
80    @twitter.status(:delete, @status)
81  end
82 
83  it "should raise an ArgumentError when given an invalid status action" do
84    lambda {
85      @twitter.status(:crap, nil)
86    }.should raise_error(ArgumentError)
87  end
88   
89  after(:each) do
90    nilize(@twitter)
91  end
92end
Note: See TracBrowser for help on using the browser.