tweetwine 0.2.12 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.rdoc +7 -0
- data/Gemfile +17 -0
- data/README.md +57 -47
- data/Rakefile +17 -26
- data/bin/tweetwine +11 -12
- data/contrib/tweetwine-completion.bash +2 -3
- data/example/application_behavior_example.rb +173 -0
- data/example/example_helper.rb +44 -28
- data/example/fixture/config.yaml +8 -0
- data/example/fixture/shorten_rubygems.html +5 -0
- data/example/fixture/shorten_rubylang.html +5 -0
- data/example/fixture/update_utf8.json +1 -0
- data/example/fixture/update_with_urls.json +1 -0
- data/example/fixture/{update.json → update_without_urls.json} +0 -0
- data/example/search_statuses_example.rb +49 -16
- data/example/show_followers_example.rb +7 -8
- data/example/show_friends_example.rb +7 -8
- data/example/show_home_example.rb +19 -16
- data/example/show_mentions_example.rb +8 -9
- data/example/show_user_example.rb +16 -13
- data/example/update_status_example.rb +143 -26
- data/example/use_http_proxy_example.rb +40 -20
- data/lib/tweetwine/basic_object.rb +19 -0
- data/lib/tweetwine/character_encoding.rb +59 -0
- data/lib/tweetwine/cli.rb +354 -230
- data/lib/tweetwine/config.rb +65 -0
- data/lib/tweetwine/http.rb +120 -0
- data/lib/tweetwine/oauth.rb +104 -0
- data/lib/tweetwine/obfuscate.rb +21 -0
- data/lib/tweetwine/option_parser.rb +31 -0
- data/lib/tweetwine/promise.rb +39 -0
- data/lib/tweetwine/twitter.rb +211 -0
- data/lib/tweetwine/{io.rb → ui.rb} +30 -21
- data/lib/tweetwine/url_shortener.rb +15 -9
- data/lib/tweetwine/util.rb +30 -15
- data/lib/tweetwine.rb +72 -12
- data/man/tweetwine.7 +43 -69
- data/man/tweetwine.7.ronn +57 -47
- data/test/character_encoding_test.rb +87 -0
- data/test/cli_test.rb +19 -6
- data/test/config_test.rb +244 -0
- data/test/fixture/oauth.rb +21 -0
- data/test/fixture/test_config.yaml +4 -4
- data/test/http_test.rb +199 -0
- data/test/oauth_test.rb +77 -0
- data/test/obfuscate_test.rb +16 -0
- data/test/option_parser_test.rb +60 -0
- data/test/promise_test.rb +56 -0
- data/test/test_helper.rb +76 -8
- data/test/twitter_test.rb +625 -0
- data/test/{io_test.rb → ui_test.rb} +92 -74
- data/test/url_shortener_test.rb +115 -135
- data/test/util_test.rb +136 -85
- data/tweetwine.gemspec +53 -0
- metadata +112 -56
- data/example/show_metadata_example.rb +0 -86
- data/lib/tweetwine/client.rb +0 -187
- data/lib/tweetwine/meta.rb +0 -5
- data/lib/tweetwine/options.rb +0 -24
- data/lib/tweetwine/retrying_http.rb +0 -99
- data/lib/tweetwine/startup_config.rb +0 -50
- data/man/tweetwine.1 +0 -109
- data/man/tweetwine.1.ronn +0 -69
- data/test/client_test.rb +0 -544
- data/test/options_test.rb +0 -45
- data/test/retrying_http_test.rb +0 -147
- data/test/startup_config_test.rb +0 -162
@@ -0,0 +1,60 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require "test_helper"
|
4
|
+
|
5
|
+
module Tweetwine::Test
|
6
|
+
|
7
|
+
class OptionParserTest < UnitTestCase
|
8
|
+
setup do
|
9
|
+
@parser = OptionParser.new do |parser, options|
|
10
|
+
parser.on '-c', '--colors', 'Enable colors.' do
|
11
|
+
options[:colors] = true
|
12
|
+
end
|
13
|
+
parser.on '-u', '--username <user>', 'Specify user.' do |arg|
|
14
|
+
options[:username] = arg
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
should "return empty options if no options (no default values)" do
|
20
|
+
options = @parser.parse %w{}
|
21
|
+
assert options.empty?
|
22
|
+
end
|
23
|
+
|
24
|
+
should "return only options that occurred (no default values)" do
|
25
|
+
options = @parser.parse %w{-u jack}
|
26
|
+
assert_equal({:username => 'jack'}, options)
|
27
|
+
end
|
28
|
+
|
29
|
+
should "return copy of options after parsing" do
|
30
|
+
options1 = @parser.parse %w{-u jack}
|
31
|
+
options2 = @parser.parse %w{-c}
|
32
|
+
assert_equal({:username => 'jack'}, options1)
|
33
|
+
assert_equal({:colors => true}, options2)
|
34
|
+
end
|
35
|
+
|
36
|
+
should "parse from beginning, removing recognized options" do
|
37
|
+
args = %w{-u jack foo bar}
|
38
|
+
options = @parser.parse args
|
39
|
+
assert_equal(%w{foo bar}, args)
|
40
|
+
end
|
41
|
+
|
42
|
+
should "parse from beginning, leaving option-like arguments after non-option arguments in place" do
|
43
|
+
args = %w{-c foo -u jack bar}
|
44
|
+
options = @parser.parse args
|
45
|
+
assert_equal(%w{foo -u jack bar}, args)
|
46
|
+
assert_equal({:colors => true}, options)
|
47
|
+
end
|
48
|
+
|
49
|
+
should "raise exception upon unrecognized option" do
|
50
|
+
assert_raise(CommandLineError) { @parser.parse %w{-d} }
|
51
|
+
end
|
52
|
+
|
53
|
+
should "describe option syntax" do
|
54
|
+
description = @parser.help.split("\n")
|
55
|
+
assert_match(/\A\s+\-c, \-\-colors\s+Enable colors.\z/, description[0])
|
56
|
+
assert_match(/\A\s+\-u, \-\-username <user>\s+Specify user.\z/, description[1])
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require "test_helper"
|
4
|
+
|
5
|
+
module Tweetwine::Test
|
6
|
+
|
7
|
+
class PromiseTest < UnitTestCase
|
8
|
+
setup do
|
9
|
+
@result = nil
|
10
|
+
@action_called = 0
|
11
|
+
@promise = Promise.new do
|
12
|
+
@action_called += 1
|
13
|
+
@result = rand 10
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
should "evaluate action when calling a method" do
|
18
|
+
result = @promise.to_i
|
19
|
+
assert_same(@result, result)
|
20
|
+
assert_equal(1, @action_called)
|
21
|
+
end
|
22
|
+
|
23
|
+
should "memoize already evaluated action" do
|
24
|
+
result = @promise.to_i
|
25
|
+
assert_same(@result, result)
|
26
|
+
result = @promise.to_i
|
27
|
+
assert_same(@result, result)
|
28
|
+
assert_equal(1, @action_called)
|
29
|
+
end
|
30
|
+
|
31
|
+
should "inspect the proxy object if action is not evaluated" do
|
32
|
+
assert_match(/^#<Tweetwine::Promise/, @promise.inspect)
|
33
|
+
assert_equal(0, @action_called)
|
34
|
+
end
|
35
|
+
|
36
|
+
should "inspect the evaluated object if action is evaluated" do
|
37
|
+
eval_action
|
38
|
+
assert_match(/^\d$/, @promise.inspect)
|
39
|
+
end
|
40
|
+
|
41
|
+
should "pass #object_id call to the evaluation result" do
|
42
|
+
eval_action # in order to have @result set
|
43
|
+
assert_equal(@result.object_id, @promise.object_id)
|
44
|
+
end
|
45
|
+
|
46
|
+
should "pass #to_s call to the evaluation result" do
|
47
|
+
eval_action # in order to have @result set
|
48
|
+
assert_equal(@result.to_s, @promise.to_s)
|
49
|
+
end
|
50
|
+
|
51
|
+
def eval_action
|
52
|
+
@promise * 42 # just do something with it
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -2,14 +2,17 @@
|
|
2
2
|
|
3
3
|
require "tweetwine"
|
4
4
|
require "contest"
|
5
|
+
require "json" # for webmock
|
5
6
|
require "mocha"
|
7
|
+
require "webmock/test_unit"
|
6
8
|
|
7
9
|
Mocha::Configuration.prevent(:stubbing_non_existent_method)
|
10
|
+
WebMock.disable_net_connect!
|
8
11
|
|
9
12
|
module Tweetwine
|
10
13
|
module Test
|
11
14
|
module Helper
|
12
|
-
|
15
|
+
extend self
|
13
16
|
|
14
17
|
def create_test_twitter_status_records_from_rest_api(*internal_records)
|
15
18
|
twitter_records = internal_records.map do |internal_record|
|
@@ -55,12 +58,76 @@ module Tweetwine
|
|
55
58
|
[twitter_records, internal_records]
|
56
59
|
end
|
57
60
|
|
61
|
+
def file_mode(file)
|
62
|
+
File.stat(file).mode & 0777
|
63
|
+
end
|
64
|
+
|
58
65
|
def fixture_file(filename)
|
59
66
|
File.dirname(__FILE__) << "/fixture/" << filename
|
60
67
|
end
|
68
|
+
|
69
|
+
def tmp_env(vars = {})
|
70
|
+
originals = {}
|
71
|
+
vars.each_pair do |key, value|
|
72
|
+
key = key.to_s
|
73
|
+
originals[key] = ENV[key]
|
74
|
+
ENV[key] = value
|
75
|
+
end
|
76
|
+
yield
|
77
|
+
ensure
|
78
|
+
originals.each_pair do |key, value|
|
79
|
+
ENV[key] = value
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def tmp_kcode(val)
|
84
|
+
original = $KCODE
|
85
|
+
$KCODE = val
|
86
|
+
yield
|
87
|
+
ensure
|
88
|
+
$KCODE = original
|
89
|
+
end
|
61
90
|
end
|
62
91
|
|
63
|
-
module
|
92
|
+
module Doubles
|
93
|
+
def mock_config
|
94
|
+
@config = mock('Config')
|
95
|
+
CLI.stubs(:config).returns(@config)
|
96
|
+
end
|
97
|
+
|
98
|
+
def mock_http
|
99
|
+
@http = mock('Http')
|
100
|
+
CLI.stubs(:http).returns(@http)
|
101
|
+
end
|
102
|
+
|
103
|
+
def mock_oauth
|
104
|
+
@oauth = mock('OAuth')
|
105
|
+
CLI.stubs(:oauth).returns(@oauth)
|
106
|
+
end
|
107
|
+
|
108
|
+
def mock_ui
|
109
|
+
@ui = mock('UI')
|
110
|
+
CLI.stubs(:ui).returns(@ui)
|
111
|
+
end
|
112
|
+
|
113
|
+
def mock_url_shortener
|
114
|
+
@url_shortener = mock('UrlShortener')
|
115
|
+
CLI.stubs(:url_shortener).returns(@url_shortener)
|
116
|
+
end
|
117
|
+
|
118
|
+
def stub_config(options = {})
|
119
|
+
@config = options
|
120
|
+
CLI.stubs(:config).returns(@config)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
module Assertions
|
125
|
+
def assert_contains_in_order(expected, actual, msg = "", &sorter)
|
126
|
+
expected = block_given? ? expected.sort(&sorter) : expected.sort
|
127
|
+
actual = block_given? ? actual.sort(&sorter) : actual.sort
|
128
|
+
assert_equal(expected, actual, msg)
|
129
|
+
end
|
130
|
+
|
64
131
|
def assert_full_match(regex, str, msg = "")
|
65
132
|
match_data = regex.match(str)
|
66
133
|
assert(str == match_data.to_s, msg)
|
@@ -71,12 +138,13 @@ module Tweetwine
|
|
71
138
|
assert(str != match_data.to_s, msg)
|
72
139
|
end
|
73
140
|
end
|
74
|
-
end
|
75
141
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
142
|
+
class UnitTestCase < ::Test::Unit::TestCase
|
143
|
+
include WebMock::API
|
144
|
+
include Tweetwine
|
145
|
+
include Helper
|
146
|
+
include Doubles
|
147
|
+
include Assertions
|
148
|
+
end
|
81
149
|
end
|
82
150
|
end
|