/
set_spec.rb
154 lines (142 loc) · 6.24 KB
/
set_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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# encoding: utf-8
require 'helper'
describe T::Set do
before :each do
T::RCFile.instance.path = fixture_path + "/.trc"
@set = T::Set.new
@old_stderr = $stderr
$stderr = StringIO.new
@old_stdout = $stdout
$stdout = StringIO.new
end
after :each do
T::RCFile.instance.reset
$stderr = @old_stderr
$stdout = @old_stdout
end
describe "#active" do
before do
@set.options = @set.options.merge("profile" => fixture_path + "/.trc_set")
end
it "should have the correct output" do
@set.active("testcli", "abc123")
expect($stdout.string.chomp).to eq "Active account has been updated to testcli."
end
it "should accept an account name without a consumer key" do
@set.active("testcli")
expect($stdout.string.chomp).to eq "Active account has been updated to testcli."
end
it "should be case insensitive" do
@set.active("TestCLI", "abc123")
expect($stdout.string.chomp).to eq "Active account has been updated to testcli."
end
it "should raise an error if username is ambiguous" do
expect do
@set.active("test", "abc123")
end.to raise_error(ArgumentError, /Username test is ambiguous/)
end
it "should raise an error if the username is not found" do
expect do
@set.active("clitest")
end.to raise_error(ArgumentError, /Username clitest is not found/)
end
end
describe "#bio" do
before do
@set.options = @set.options.merge("profile" => fixture_path + "/.trc")
stub_post("/1.1/account/update_profile.json").with(:body => {:description => "Vagabond."}).to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "should request the correct resource" do
@set.bio("Vagabond.")
expect(a_post("/1.1/account/update_profile.json").with(:body => {:description => "Vagabond."})).to have_been_made
end
it "should have the correct output" do
@set.bio("Vagabond.")
expect($stdout.string.chomp).to eq "@testcli's bio has been updated."
end
end
describe "#language" do
before do
@set.options = @set.options.merge("profile" => fixture_path + "/.trc")
stub_post("/1.1/account/settings.json").with(:body => {:lang => "en"}).to_return(:body => fixture("settings.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "should request the correct resource" do
@set.language("en")
expect(a_post("/1.1/account/settings.json").with(:body => {:lang => "en"})).to have_been_made
end
it "should have the correct output" do
@set.language("en")
expect($stdout.string.chomp).to eq "@testcli's language has been updated."
end
end
describe "#location" do
before do
@set.options = @set.options.merge("profile" => fixture_path + "/.trc")
stub_post("/1.1/account/update_profile.json").with(:body => {:location => "San Francisco"}).to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "should request the correct resource" do
@set.location("San Francisco")
expect(a_post("/1.1/account/update_profile.json").with(:body => {:location => "San Francisco"})).to have_been_made
end
it "should have the correct output" do
@set.location("San Francisco")
expect($stdout.string.chomp).to eq "@testcli's location has been updated."
end
end
describe "#name" do
before do
@set.options = @set.options.merge("profile" => fixture_path + "/.trc")
stub_post("/1.1/account/update_profile.json").with(:body => {:name => "Erik Michaels-Ober"}).to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "should request the correct resource" do
@set.name("Erik Michaels-Ober")
expect(a_post("/1.1/account/update_profile.json").with(:body => {:name => "Erik Michaels-Ober"})).to have_been_made
end
it "should have the correct output" do
@set.name("Erik Michaels-Ober")
expect($stdout.string.chomp).to eq "@testcli's name has been updated."
end
end
describe "#profile_background_image" do
before do
@set.options = @set.options.merge("profile" => fixture_path + "/.trc")
stub_post("/1.1/account/update_profile_background_image.json").to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "should request the correct resource" do
@set.profile_background_image(fixture_path + "/we_concept_bg2.png")
expect(a_post("/1.1/account/update_profile_background_image.json")).to have_been_made
end
it "should have the correct output" do
@set.profile_background_image(fixture_path + "/we_concept_bg2.png")
expect($stdout.string.chomp).to eq "@testcli's background image has been updated."
end
end
describe "#profile_image" do
before do
@set.options = @set.options.merge("profile" => fixture_path + "/.trc")
stub_post("/1.1/account/update_profile_image.json").to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "should request the correct resource" do
@set.profile_image(fixture_path + "/me.jpg")
expect(a_post("/1.1/account/update_profile_image.json")).to have_been_made
end
it "should have the correct output" do
@set.profile_image(fixture_path + "/me.jpg")
expect($stdout.string.chomp).to eq "@testcli's image has been updated."
end
end
describe "#url" do
before do
@set.options = @set.options.merge("profile" => fixture_path + "/.trc")
stub_post("/1.1/account/update_profile.json").with(:body => {:url => "https://github.com/sferik"}).to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "should request the correct resource" do
@set.url("https://github.com/sferik")
expect(a_post("/1.1/account/update_profile.json").with(:body => {:url => "https://github.com/sferik"})).to have_been_made
end
it "should have the correct output" do
@set.url("https://github.com/sferik")
expect($stdout.string.chomp).to eq "@testcli's URL has been updated."
end
end
end