forked from jugyo/termtter
/
api_spec.rb
116 lines (98 loc) · 3.22 KB
/
api_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
# -*- coding: utf-8 -*-
require File.expand_path(File.dirname(__FILE__)) + '/../spec_helper'
module Termtter
describe API do
it 'tries authenticate 3 times' do
pending("Not yet implemented")
API.should_receive(:try_auth).
exactly(3).times.
and_return(false)
API.should_receive(:exit!)
API.setup
end
it 'can get twitter when success authentication' do
pending("Not yet implemented")
twitter = mock('twitter')
API.should_receive(:try_auth).and_return(twitter)
API.setup
API.twitter.should == twitter
end
def it_should_examine_with(name, pass, options = {})
config.user_name = name if name
config.password = pass if pass
dummy_out = mock('stdout')
dummy_out.stub(:ask) do |ask, _|
$stdout.puts ask
result = options.delete(
case ask
when /Username/ then :ui_name
when /Password/ then :ui_pass
end
) || ''
result
end
API.stub(:create_highline => dummy_out)
twitter = mock('twitter')
twitter.stub(:verify_credentials) do
if config.user_name.empty? || config.password.empty?
raise Rubytter::APIError.new('error')
end
end
RubytterProxy.stub(:new => twitter)
API.try_auth.should == yield(twitter)
config.__clear__(:user_name)
config.__clear__(:password)
end
it 'can examine username and password (success)' do
pending("Not yet implemented")
it_should_examine_with('test', 'pass') {|twitter| twitter }
end
it 'can examine username and password (only name)' do
pending("Not yet implemented")
result = be_quiet(:stderr => false) {
it_should_examine_with('test', nil) { nil }
}
result[:stdout].should ==
"Please enter your Twitter login:\nUsername: test\nPassword: \n"
end
it 'can examine username and password (only pass)' do
pending("Not yet implemented")
result = be_quiet(:stderr => false) {
it_should_examine_with(nil, 'pass') { nil }
}
result[:stdout].should ==
"Please enter your Twitter login:\nUsername: \n"
end
it 'can examine username and password (both nil)' do
pending("Not yet implemented")
result = be_quiet(:stderr => false) {
it_should_examine_with(nil, nil) { nil }
}
result[:stdout].should ==
"Please enter your Twitter login:\nUsername: \nPassword: \n"
end
it 'can examine username and password (enter password)' do
pending("Not yet implemented")
be_quiet do
args = ['test', nil, {:ui_pass => 'pass'}]
it_should_examine_with(*args) {|twitter| twitter }
end
end
it 'can examine username and password (enter username)' do
pending("Not yet implemented")
be_quiet do
args = [nil, 'pass', {:ui_name => 'test'}]
it_should_examine_with(*args) {|twitter| twitter }
end
end
it 'can examine username and password (enter both)' do
pending("Not yet implemented")
be_quiet do
args = [nil, nil,
{:ui_name => 'test',
:ui_pass => 'pass' }]
it_should_examine_with(*args) {|twitter| twitter }
end
end
end
end