/
block_spec.rb
108 lines (100 loc) · 3.45 KB
/
block_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
require 'helper'
describe Twitter::Client do
before do
@client = Twitter::Client.new
end
describe "#blocking" do
before do
stub_get("/1/blocks/blocking.json").
to_return(:body => fixture("users.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "requests the correct resource" do
@client.blocking
a_get("/1/blocks/blocking.json").
should have_been_made
end
it "returns an array of user objects that the authenticating user is blocking" do
users = @client.blocking
users.should be_an Array
users.first.should be_a Twitter::User
users.first.name.should == "Erik Michaels-Ober"
end
end
describe "#blocked_ids" do
before do
stub_get("/1/blocks/blocking/ids.json").
to_return(:body => fixture("ids.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "requests the correct resource" do
@client.blocked_ids
a_get("/1/blocks/blocking/ids.json").
should have_been_made
end
it "returns an array of numeric user IDs the authenticating user is blocking" do
ids = @client.blocked_ids
ids.should be_an Array
ids.first.should == 47
end
end
describe "#block?" do
before do
stub_get("/1/blocks/exists.json").
with(:query => {:screen_name => "sferik"}).
to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
stub_get("/1/blocks/exists.json").
with(:query => {:screen_name => "pengwynn"}).
to_return(:body => fixture("not_found.json"), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
end
it "requests the correct resource" do
@client.block?("sferik")
a_get("/1/blocks/exists.json").
with(:query => {:screen_name => "sferik"}).
should have_been_made
end
it "returns true if block exists" do
block = @client.block?("sferik")
block.should be_true
end
it "returns false if block does not exist" do
block = @client.block?("pengwynn")
block.should be_false
end
end
describe "#block" do
before do
stub_post("/1/blocks/create.json").
with(:body => {:screen_name => "sferik"}).
to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "requests the correct resource" do
@client.block("sferik")
a_post("/1/blocks/create.json").
should have_been_made
end
it "returns an array of blocked users" do
users = @client.block("sferik")
users.should be_an Array
users.first.should be_a Twitter::User
users.first.name.should == "Erik Michaels-Ober"
end
end
describe "#unblock" do
before do
stub_delete("/1/blocks/destroy.json").
with(:query => {:screen_name => "sferik"}).
to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "requests the correct resource" do
@client.unblock("sferik")
a_delete("/1/blocks/destroy.json").
with(:query => {:screen_name => "sferik"}).
should have_been_made
end
it "returns an array of un-blocked users" do
users = @client.unblock("sferik")
users.should be_an Array
users.first.should be_a Twitter::User
users.first.name.should == "Erik Michaels-Ober"
end
end
end