alias_controller_test.rb
1.67 KB
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
require File.dirname(__FILE__) + '/test_helper'
class Twurl::AliasesController::DispatchTest < Minitest::Test
attr_reader :options, :client
def setup
@options = Twurl::Options.test_exemplar
@client = Twurl::OAuthClient.test_exemplar
# Clean slate
if Twurl::OAuthClient.rcfile.aliases
Twurl::OAuthClient.rcfile.aliases.clear
end
stub(Twurl::OAuthClient.rcfile).save
end
def test_when_no_subcommands_are_provided_and_no_aliases_exist_nothing_is_displayed
assert options.subcommands.empty?
mock(Twurl::CLI).puts(Twurl::AliasesController::NO_ALIASES_MESSAGE).times(1)
controller = Twurl::AliasesController.new(client, options)
controller.dispatch
end
def test_when_no_subcommands_are_provided_and_aliases_exist_they_are_displayed
assert options.subcommands.empty?
Twurl::OAuthClient.rcfile.alias('h', '/1.1/statuses/home_timeline.json')
mock(Twurl::CLI).puts("h: /1.1/statuses/home_timeline.json").times(1)
controller = Twurl::AliasesController.new(client, options)
controller.dispatch
end
def test_when_alias_and_value_are_provided_they_are_added
options.subcommands = ['h']
options.path = '/1.1/statuses/home_timeline.json'
mock(Twurl::OAuthClient.rcfile).alias('h', '/1.1/statuses/home_timeline.json').times(1)
controller = Twurl::AliasesController.new(client, options)
controller.dispatch
end
def test_when_no_path_is_provided_nothing_happens
options.subcommands = ['a']
assert_nil options.path
mock(Twurl::CLI).puts(Twurl::AliasesController::NO_PATH_PROVIDED_MESSAGE).times(1)
controller = Twurl::AliasesController.new(client, options)
controller.dispatch
end
end