tweetwine 0.4.1 → 0.4.2

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.
Files changed (52) hide show
  1. data/CHANGELOG.rdoc +6 -0
  2. data/Rakefile +22 -23
  3. data/lib/tweetwine/cli.rb +167 -165
  4. data/lib/tweetwine/config.rb +3 -2
  5. data/lib/tweetwine/exceptions.rb +1 -0
  6. data/lib/tweetwine/version.rb +1 -1
  7. data/project.rb +16 -16
  8. data/test/fixture/{config_example.yaml → config_integration.yaml} +0 -0
  9. data/test/fixture/oauth.rb +11 -11
  10. data/test/{test_helper.rb → helper.rb} +16 -7
  11. data/test/{example/authorization_example.rb → integration/authorization_test.rb} +17 -17
  12. data/test/integration/global_options_test.rb +67 -0
  13. data/test/integration/helper.rb +70 -0
  14. data/test/integration/invalid_config_file_test.rb +28 -0
  15. data/test/integration/search_statuses_test.rb +81 -0
  16. data/test/integration/show_followers_test.rb +24 -0
  17. data/test/integration/show_friends_test.rb +24 -0
  18. data/test/integration/show_home_test.rb +47 -0
  19. data/test/integration/show_mentions_test.rb +24 -0
  20. data/test/integration/show_user_test.rb +48 -0
  21. data/test/integration/update_status_test.rb +199 -0
  22. data/test/integration/use_http_proxy_test.rb +71 -0
  23. data/test/{example/user_help_example.rb → integration/user_help_test.rb} +36 -36
  24. data/test/unit/character_encoding_test.rb +19 -15
  25. data/test/unit/cli_test.rb +9 -10
  26. data/test/unit/config_test.rb +73 -71
  27. data/test/unit/helper.rb +108 -0
  28. data/test/unit/http_test.rb +39 -39
  29. data/test/unit/oauth_test.rb +15 -16
  30. data/test/unit/obfuscate_test.rb +4 -4
  31. data/test/unit/option_parser_test.rb +12 -12
  32. data/test/unit/promise_test.rb +10 -10
  33. data/test/unit/support_test.rb +44 -45
  34. data/test/unit/tweet_helper.rb +1 -1
  35. data/test/unit/tweet_test.rb +42 -42
  36. data/test/unit/twitter_test.rb +300 -303
  37. data/test/unit/ui_test.rb +310 -312
  38. data/test/unit/uri_test.rb +7 -7
  39. data/test/unit/url_shortener_test.rb +77 -79
  40. data/tweetwine.gemspec +6 -15
  41. metadata +55 -145
  42. data/test/example/example_helper.rb +0 -58
  43. data/test/example/global_options_example.rb +0 -64
  44. data/test/example/search_statuses_example.rb +0 -76
  45. data/test/example/show_followers_example.rb +0 -24
  46. data/test/example/show_friends_example.rb +0 -24
  47. data/test/example/show_home_example.rb +0 -44
  48. data/test/example/show_mentions_example.rb +0 -24
  49. data/test/example/show_user_example.rb +0 -44
  50. data/test/example/update_status_example.rb +0 -183
  51. data/test/example/use_http_proxy_example.rb +0 -68
  52. data/test/unit/unit_helper.rb +0 -111
@@ -1,58 +0,0 @@
1
- # coding: utf-8
2
-
3
- %w{
4
- coulda
5
- matchy
6
- open4
7
- stringio
8
- tempfile
9
- time
10
- timecop
11
- }.each { |lib| require lib }
12
-
13
- Timecop.freeze(Time.parse("2009-10-14 01:56:15 +0300"))
14
-
15
- require "test_helper"
16
-
17
- module Tweetwine::Test
18
- module Helper
19
- include WebMock::API
20
-
21
- CONFIG_FILE = fixture_path('config_example.yaml')
22
- PROJECT_DIR = File.expand_path('../..', File.dirname(__FILE__))
23
- PROXY_HOST = "proxy.net"
24
- PROXY_PORT = 8123
25
- PROXY_URL = "http://#{PROXY_HOST}:#{PROXY_PORT}"
26
- USER = "fooman"
27
-
28
- def start_app(args, &blk)
29
- lib = PROJECT_DIR + '/lib'
30
- executable = PROJECT_DIR + '/bin/tweetwine'
31
- launch_cmd = "env USER='#{USER}' ruby -rubygems -I #{lib} -- #{executable} -f #{CONFIG_FILE} #{args.join(' ')}"
32
- Open4::popen4(launch_cmd, &blk)
33
- end
34
-
35
- def start_cli(args, input = [], options = {:config_file => CONFIG_FILE})
36
- input, output = StringIO.new(input.join("\n")), StringIO.new
37
- options.merge!({ :in => input, :out => output })
38
- CLI.start(args, options)
39
- output.string.split("\n")
40
- end
41
-
42
- def in_temp_dir
43
- Dir.mktmpdir do |tmp_dir|
44
- Dir.chdir(tmp_dir) do |dir|
45
- yield dir
46
- end
47
- end
48
- end
49
-
50
- def read_shorten_config
51
- Support.symbolize_hash_keys(YAML.load_file(CONFIG_FILE))[:shorten_urls]
52
- end
53
- end
54
- end
55
-
56
- include Coulda
57
- include Tweetwine
58
- include Tweetwine::Test::Helper
@@ -1,64 +0,0 @@
1
- # coding: utf-8
2
-
3
- require "example_helper"
4
-
5
- Feature "global options" do
6
- as_a "user"
7
- i_want_to "set global options"
8
- in_order_to "affect general application behavior"
9
-
10
- def setup
11
- super
12
- stub_http_request(:get, %r{https://api.twitter.com/1/statuses/home_timeline\.json\?count=\d+&page=\d+}).to_return(:body => fixture_file('home.json'))
13
- end
14
-
15
- Scenario "colors" do
16
- When "I start the application with '--colors' option" do
17
- @output = start_cli %w{--colors}
18
- end
19
-
20
- Then "the application shows tweets with colors" do
21
- @output[0].should == "\e[32mpelit\e[0m, 11 days ago:"
22
- @output[1].should == "F1-kausi alkaa marraskuussa \e[36mhttp://bit.ly/1qQwjQ\e[0m"
23
- @output[2].should == ""
24
- @output[58].should == "\e[32mradar\e[0m, 15 days ago:"
25
- @output[59].should == "Four short links: 29 September 2009 \e[36mhttp://bit.ly/dYxay\e[0m"
26
- end
27
- end
28
-
29
- Scenario "show reverse" do
30
- When "I start the application with '--reverse' option" do
31
- @output = start_cli %w{--reverse}
32
- end
33
-
34
- Then "the application shows tweets in reverse order" do
35
- @output[0].should == "radar, 15 days ago:"
36
- @output[1].should == "Four short links: 29 September 2009 http://bit.ly/dYxay"
37
- @output[2].should == ""
38
- @output[58].should == "pelit, 11 days ago:"
39
- @output[59].should == "F1-kausi alkaa marraskuussa http://bit.ly/1qQwjQ"
40
- end
41
- end
42
-
43
- Scenario "num" do
44
- When "I start the application with '--num <n>' option" do
45
- @num = 2
46
- @output = start_cli %W{--num #{@num}}
47
- end
48
-
49
- Then "the application requests the specified number of tweets" do
50
- assert_requested(:get, %r{/home_timeline\.json\?count=#{@num}&page=\d+})
51
- end
52
- end
53
-
54
- Scenario "page" do
55
- When "I start the application with '--page <p>' option" do
56
- @page = 2
57
- @output = start_cli %W{--page #{@page}}
58
- end
59
-
60
- Then "the application requests the specified page number for tweets" do
61
- assert_requested(:get, %r{/home_timeline\.json\?count=\d+&page=#{@page}})
62
- end
63
- end
64
- end
@@ -1,76 +0,0 @@
1
- # coding: utf-8
2
-
3
- require "example_helper"
4
-
5
- Feature "search tweets" do
6
- as_a "authenticated user"
7
- i_want_to "search tweets with keywords"
8
- in_order_to "see tweets that interest me"
9
-
10
- SEARCH_BASE_URL = "http://search.twitter.com/search.json"
11
- SEARCH_OR_URL = "#{SEARCH_BASE_URL}?q=braid%20OR%20game&rpp=2&page=1"
12
- SEARCH_AND_URL = "#{SEARCH_BASE_URL}?q=braid%20game&rpp=2&page=1"
13
- SEARCH_FIXTURE = fixture_file('search.json')
14
-
15
- def setup
16
- super
17
- stub_http_request(:get, SEARCH_AND_URL).to_return(:body => SEARCH_FIXTURE)
18
- stub_http_request(:get, SEARCH_OR_URL).to_return(:body => SEARCH_FIXTURE)
19
- end
20
-
21
- Scenario "search tweets matching all words" do
22
- When "I start the application with command 'search', option '-a', and search words" do
23
- @output = start_cli %w{-n 2 search -a braid game}
24
- end
25
-
26
- Then "the application requests tweets matching all the words and shows them" do
27
- assert_requested(:get, SEARCH_AND_URL)
28
- should_output_tweets
29
- end
30
- end
31
-
32
- Scenario "search tweets matching any words" do
33
- When "I start the application with command 'search', option '-o', and search words" do
34
- @output = start_cli %w{-n 2 search -o braid game}
35
- end
36
-
37
- Then "the application requests tweets matching any of the words and shows them" do
38
- assert_requested(:get, SEARCH_OR_URL)
39
- should_output_tweets
40
- end
41
- end
42
-
43
- Scenario "option '-a' is implied unless specified" do
44
- When "I start the application with command 'search' and search words" do
45
- @output = start_cli %w{-n 2 search braid game}
46
- end
47
-
48
- Then "the application requests tweets matching all the words and shows them" do
49
- assert_requested(:get, SEARCH_AND_URL)
50
- should_output_tweets
51
- end
52
- end
53
-
54
- Scenario "search without words" do
55
- When "I start the application with 'search' command without search words" do
56
- @status = start_app %w{-n 2 search} do |_, _, _, stderr|
57
- @output = stderr.gets
58
- end
59
- end
60
-
61
- Then "the application shows error message and exists with error status" do
62
- @output.should == "ERROR: No search words.\n"
63
- @status.exitstatus.should == CommandLineError.status_code
64
- end
65
- end
66
-
67
- private
68
-
69
- def should_output_tweets
70
- @output[0].should == "thatswhatshesaid, in reply to hatguy, 5 hours ago:"
71
- @output[1].should == "@hatguy braid, perhaps the best indie game of 2009"
72
- @output[2].should == ""
73
- @output[3].should == "jillv, 11 hours ago:"
74
- @output[4].should == "braid is even better than of the games i'm in, expect re4"
75
- end
76
- end
@@ -1,24 +0,0 @@
1
- # coding: utf-8
2
-
3
- require "example_helper"
4
-
5
- Feature "show followers" do
6
- as_a "authenticated user"
7
- i_want_to "see my followers"
8
- in_order_to "to see who follows me"
9
-
10
- Scenario "show followers" do
11
- When "I start the application with 'followers' command" do
12
- stub_http_request(:get, "https://api.twitter.com/1/statuses/followers.json?count=20&page=1").to_return(:body => fixture_file('users.json'))
13
- @output = start_cli %w{followers}
14
- end
15
-
16
- Then "the application shows followers and their latest tweets (if any)" do
17
- @output[0].should == "jillv, 12 hours ago:"
18
- @output[1].should == "choosing next target"
19
- @output[2].should == ""
20
- @output[3].should == "ham"
21
- @output[4].should == nil
22
- end
23
- end
24
- end
@@ -1,24 +0,0 @@
1
- # coding: utf-8
2
-
3
- require "example_helper"
4
-
5
- Feature "show friends" do
6
- as_a "authenticated user"
7
- i_want_to "see my friends"
8
- in_order_to "to see who I follow"
9
-
10
- Scenario "show friends" do
11
- When "I start the application with 'followers' command" do
12
- stub_http_request(:get, "https://api.twitter.com/1/statuses/friends.json?count=20&page=1").to_return(:body => fixture_file('users.json'))
13
- @output = start_cli %w{friends}
14
- end
15
-
16
- Then "the application shows friends and their latest tweets (if any)" do
17
- @output[0].should == "jillv, 12 hours ago:"
18
- @output[1].should == "choosing next target"
19
- @output[2].should == ""
20
- @output[3].should == "ham"
21
- @output[4].should == nil
22
- end
23
- end
24
- end
@@ -1,44 +0,0 @@
1
- # coding: utf-8
2
-
3
- require "example_helper"
4
-
5
- Feature "show tweets from home timeline" do
6
- as_a "authenticated user"
7
- i_want_to "see my home timeline"
8
- in_order_to "stay up-to-date of other people's doings"
9
-
10
- def setup
11
- super
12
- stub_http_request(:get, "https://api.twitter.com/1/statuses/home_timeline.json?count=20&page=1").to_return(:body => fixture_file('home.json'))
13
- end
14
-
15
- Scenario "show home timeline" do
16
- When "I start the application with 'home' command" do
17
- @output = start_cli %w{--no-colors home}
18
- end
19
-
20
- Then "the application shows tweets from home timeline" do
21
- should_output_tweets
22
- end
23
- end
24
-
25
- Scenario "show home timeline is default command" do
26
- When "I start the application with no command" do
27
- @output = start_cli %w{--no-colors}
28
- end
29
-
30
- Then "the application shows tweets from home timeline" do
31
- should_output_tweets
32
- end
33
- end
34
-
35
- private
36
-
37
- def should_output_tweets
38
- @output[0].should == "pelit, 11 days ago:"
39
- @output[1].should == "F1-kausi alkaa marraskuussa http://bit.ly/1qQwjQ"
40
- @output[2].should == ""
41
- @output[58].should == "radar, 15 days ago:"
42
- @output[59].should == "Four short links: 29 September 2009 http://bit.ly/dYxay"
43
- end
44
- end
@@ -1,24 +0,0 @@
1
- # coding: utf-8
2
-
3
- require "example_helper"
4
-
5
- Feature "show tweets mentioning the user" do
6
- as_a "authenticated user"
7
- i_want_to "see tweets mentioning me"
8
- in_order_to "know if someone has replied or otherwise mentioned me"
9
-
10
- Scenario "show tweets mentioning me" do
11
- When "I start the application with 'mentions' command" do
12
- stub_http_request(:get, "https://api.twitter.com/1/statuses/mentions.json?count=20&page=1").to_return(:body => fixture_file('mentions.json'))
13
- @output = start_cli %w{mentions}
14
- end
15
-
16
- Then "the application shows tweets mentioning me" do
17
- @output[0].should == "jillv, in reply to fooman, 3 days ago:"
18
- @output[1].should == "@fooman, did you see their eyes glow yellow after sunset?"
19
- @output[2].should == ""
20
- @output[3].should == "redfield, in reply to fooman, 5 days ago:"
21
- @output[4].should == "sometimes it is just best to run, just like @fooman"
22
- end
23
- end
24
- end
@@ -1,44 +0,0 @@
1
- # coding: utf-8
2
-
3
- require "example_helper"
4
-
5
- Feature "show user's tweets" do
6
- as_a "authenticated user"
7
- i_want_to "see a specific user's tweets"
8
- in_order_to "to know what the user has been doing"
9
-
10
- USER_URL = "https://api.twitter.com/1/statuses/user_timeline.json?count=20&page=1&screen_name=%s"
11
- USER_FIXTURE = fixture_file('user.json')
12
-
13
- Scenario "show my tweets" do
14
- When "I start the application with 'user' command without extra arguments" do
15
- stub_http_request(:get, USER_URL % USER).to_return(:body => USER_FIXTURE)
16
- @output = start_cli %w{user}
17
- end
18
-
19
- Then "the application shows my tweets" do
20
- should_output_tweets
21
- end
22
- end
23
-
24
- Scenario "show another user's tweets" do
25
- When "I start the application with 'user' command with the user as argument" do
26
- stub_http_request(:get, USER_URL % 'jillv').to_return(:body => USER_FIXTURE)
27
- @output = start_cli %w{user jillv}
28
- end
29
-
30
- Then "the application shows the user's tweets" do
31
- should_output_tweets
32
- end
33
- end
34
-
35
- private
36
-
37
- def should_output_tweets
38
- @output[0].should == "jillv, in reply to chris, 9 hours ago:"
39
- @output[1].should == "@chris wait me until the garden"
40
- @output[2].should == ""
41
- @output[3].should == "jillv, 3 days ago:"
42
- @output[4].should == "so boring to wait"
43
- end
44
- end
@@ -1,183 +0,0 @@
1
- # coding: utf-8
2
-
3
- require "example_helper"
4
- require "yaml"
5
-
6
- Feature "update my status (send new tweet)" do
7
- as_a "authenticated user"
8
- i_want_to "update my status"
9
- in_order_to "tell something about me to the world"
10
-
11
- RUBYGEMS_FIXTURE = fixture_file('shorten_rubygems.html')
12
- RUBYGEMS_FULL_URL = 'http://rubygems.org/'
13
- RUBYGEMS_FULL_URL_ENC = 'http%3a%2f%2frubygems.org%2f'
14
- RUBYGEMS_SHORT_URL = 'http://is.gd/gGazV'
15
- RUBYGEMS_SHORT_URL_ENC = 'http%3a%2f%2fis.gd%2fgGazV'
16
- RUBYLANG_FIXTURE = fixture_file('shorten_rubylang.html')
17
- RUBYLANG_FULL_URL = 'http://ruby-lang.org/'
18
- RUBYLANG_FULL_URL_ENC = 'http%3a%2f%2fruby-lang.org%2f'
19
- RUBYLANG_SHORT_URL = 'http://is.gd/gGaM3'
20
- RUBYLANG_SHORT_URL_ENC = 'http%3a%2f%2fis.gd%2fgGaM3'
21
- SHORTEN_CONFIG = read_shorten_config
22
- SHORTEN_METHOD = SHORTEN_CONFIG[:method].to_sym
23
- STATUS_WITH_FULL_URLS = "ruby links: #{RUBYGEMS_FULL_URL} #{RUBYLANG_FULL_URL}"
24
- STATUS_WITH_SHORT_URLS = "ruby links: #{RUBYGEMS_SHORT_URL} #{RUBYLANG_SHORT_URL}"
25
- STATUS_WITHOUT_URLS = "bored. going to sleep."
26
- UPDATE_FIXTURE_WITH_URLS = fixture_file('update_with_urls.json')
27
- UPDATE_FIXTURE_WITHOUT_URLS = fixture_file('update_without_urls.json')
28
- UPDATE_FIXTURE_UTF8 = fixture_file('update_utf8.json')
29
- UPDATE_URL = "https://api.twitter.com/1/statuses/update.json"
30
-
31
- BODY_WITH_SHORT_URLS = "status=ruby%20links%3a%20#{RUBYGEMS_SHORT_URL_ENC}%20#{RUBYLANG_SHORT_URL_ENC}"
32
- BODY_WITHOUT_URLS = "status=bored.%20going%20to%20sleep."
33
-
34
- Scenario "update my status from command line with colorization disabled" do
35
- When "I start the application with 'update' command with --no-colors option, give status in single command line argument, and confirm" do
36
- stub_http_request(:post, UPDATE_URL).with(:body => BODY_WITHOUT_URLS).to_return(:body => UPDATE_FIXTURE_WITHOUT_URLS)
37
- @output = start_cli %W{--no-colors update #{STATUS_WITHOUT_URLS}}, %w{y}
38
- end
39
-
40
- Then "the application sends and shows the status" do
41
- @output[5].should == "#{USER}, 9 hours ago:"
42
- @output[6].should == STATUS_WITHOUT_URLS
43
- end
44
- end
45
-
46
- Scenario "update my status from command line with colorization enabled" do
47
- When "I start the application with 'update' command with --colors option, give status in single command line argument, and confirm" do
48
- stub_http_request(:post, UPDATE_URL).with(:body => BODY_WITHOUT_URLS).to_return(:body => UPDATE_FIXTURE_WITHOUT_URLS)
49
- @output = start_cli %W{--colors update #{STATUS_WITHOUT_URLS}}, %w{y}
50
- end
51
-
52
- Then "the application sends and shows the status" do
53
- @output[5].should == "\e[32m#{USER}\e[0m, 9 hours ago:"
54
- @output[6].should == STATUS_WITHOUT_URLS
55
- end
56
- end
57
-
58
- Scenario "update my status from command line when message is spread over multiple arguments" do
59
- When "I start the application with 'update' command, give status in multiple command line arguments, and confirm" do
60
- stub_http_request(:post, UPDATE_URL).with(:body => BODY_WITHOUT_URLS).to_return(:body => UPDATE_FIXTURE_WITHOUT_URLS)
61
- @output = start_cli(%w{--no-colors update} + STATUS_WITHOUT_URLS.split, %w{y})
62
- end
63
-
64
- Then "the application sends and shows the status" do
65
- @output[5].should == "#{USER}, 9 hours ago:"
66
- @output[6].should == STATUS_WITHOUT_URLS
67
- end
68
- end
69
-
70
- Scenario "cancel status update from command line" do
71
- When "I start the application with 'update' command, and cancel" do
72
- @output = start_cli %W{--no-colors update #{STATUS_WITHOUT_URLS}}, %w{n}
73
- end
74
-
75
- Then "the application shows a cancellation message" do
76
- @output[3].should =~ /Cancelled./
77
- end
78
- end
79
-
80
- Scenario "update my status from STDIN" do
81
- When "I start the application with 'update' command, give status from STDIN, and confirm" do
82
- stub_http_request(:post, UPDATE_URL).with(:body => BODY_WITHOUT_URLS).to_return(:body => UPDATE_FIXTURE_WITHOUT_URLS)
83
- @output = start_cli %w{update}, [STATUS_WITHOUT_URLS, 'y']
84
- end
85
-
86
- Then "the application sends and shows the status" do
87
- @output[0].should == "Status update: "
88
- @output[5].should == "#{USER}, 9 hours ago:"
89
- @output[6].should == STATUS_WITHOUT_URLS
90
- end
91
- end
92
-
93
- Scenario "cancel a status update from STDIN" do
94
- When "I start the application with 'update' command, give status from STDIN, and cancel" do
95
- @output = start_cli %w{update}, [STATUS_WITHOUT_URLS, 'n']
96
- end
97
-
98
- Then "the application shows a cancellation message" do
99
- @output[3].should =~ /Cancelled./
100
- end
101
- end
102
-
103
- if defined? Encoding
104
- Scenario "encode status in UTF-8 (String supports encoding)" do
105
- When "I start the application with 'update' command, input latin1 encoded status, and confirm" do
106
- @status_utf8 = "résumé"
107
- @status_latin1 = @status_utf8.encode('ISO-8859-1')
108
- url_encoded_body = "status=r%c3%a9sum%c3%a9"
109
- stub_http_request(:post, UPDATE_URL).with(:body => url_encoded_body).to_return(:body => UPDATE_FIXTURE_UTF8)
110
- @output = start_cli %W{--no-colors update #{@status_latin1}}, %w{y}
111
- end
112
-
113
- Then "the application sends and shows the status" do
114
- # NOTE: Should be in latin-1, but StringIO converts it to UTF-8. At
115
- # least on tty Ruby 1.9.2 outputs it in latin-1.
116
- #@output[1].should == @status_latin1 # preview
117
- @output[5].should == "#{USER}, 9 hours ago:"
118
- @output[6].should == @status_utf8
119
- end
120
- end
121
- else
122
- Scenario "encode status in UTF-8 (String does not support encoding)" do
123
- When "I have latin1 in LANG envar, start the application with 'update' command, input status, and confirm" do
124
- @status_latin1 = "r\xe9sum\xe9"
125
- @status_utf8 = "r\xc3\xa9sum\xc3\xa9"
126
- url_encoded_body = "status=r%c3%a9sum%c3%a9"
127
- stub_http_request(:post, UPDATE_URL).with(:body => url_encoded_body).to_return(:body => UPDATE_FIXTURE_UTF8)
128
- tmp_kcode('NONE') do
129
- tmp_env(:LANG => 'latin1') do
130
- Tweetwine::CharacterEncoding.forget_guess
131
- @output = start_cli %W{--no-colors update #{@status_latin1}}, %w{y}
132
- end
133
- end
134
- end
135
-
136
- Then "the application sends and shows the status" do
137
- @output[1].should == @status_latin1 # preview
138
- @output[5].should == "#{USER}, 9 hours ago:"
139
- @output[6].should == @status_utf8
140
- end
141
- end
142
- end
143
-
144
- Scenario "shorten URLs in status update" do
145
- When "I have configured URL shortening, start the application with 'update' command, input status containing URLs, and confirm" do
146
- @shorten_rubygems_body = "#{SHORTEN_CONFIG[:url_param_name]}=#{RUBYGEMS_FULL_URL_ENC}"
147
- @shorten_rubylang_body = "#{SHORTEN_CONFIG[:url_param_name]}=#{RUBYLANG_FULL_URL_ENC}"
148
- stub_http_request(SHORTEN_METHOD, SHORTEN_CONFIG[:service_url]).
149
- with(:body => @shorten_rubygems_body).
150
- to_return(:body => RUBYGEMS_FIXTURE)
151
- stub_http_request(SHORTEN_METHOD, SHORTEN_CONFIG[:service_url]).
152
- with(:body => @shorten_rubylang_body).
153
- to_return(:body => RUBYLANG_FIXTURE)
154
- stub_http_request(:post, UPDATE_URL).
155
- with(:body => BODY_WITH_SHORT_URLS).
156
- to_return(:body => UPDATE_FIXTURE_WITH_URLS)
157
- @output = start_cli %W{--no-colors update #{STATUS_WITH_FULL_URLS}}, %w{y}
158
- end
159
-
160
- Then "the application shortens the URLs in the status before sending it" do
161
- assert_requested(SHORTEN_METHOD, SHORTEN_CONFIG[:service_url], :body => @shorten_rubygems_body)
162
- assert_requested(SHORTEN_METHOD, SHORTEN_CONFIG[:service_url], :body => @shorten_rubylang_body)
163
- @output[1].should == STATUS_WITH_SHORT_URLS
164
- @output[5].should == "#{USER}, 9 hours ago:"
165
- @output[6].should == STATUS_WITH_SHORT_URLS
166
- end
167
- end
168
-
169
- Scenario "disable URL shortening for status updates" do
170
- When "I have configured URL shortening, start the application with 'update' command with --no-url-shorten option, input status containing URLs, and confirm" do
171
- stub_http_request(:post, UPDATE_URL).
172
- with(:body => BODY_WITH_SHORT_URLS).
173
- to_return(:body => UPDATE_FIXTURE_WITH_URLS)
174
- @output = start_cli %W{--no-colors --no-url-shorten update #{STATUS_WITH_SHORT_URLS}}, %w{y}
175
- end
176
-
177
- Then "the application passes URLs as is in the status" do
178
- @output[1].should == STATUS_WITH_SHORT_URLS
179
- @output[5].should == "#{USER}, 9 hours ago:"
180
- @output[6].should == STATUS_WITH_SHORT_URLS
181
- end
182
- end
183
- end
@@ -1,68 +0,0 @@
1
- # coding: utf-8
2
-
3
- require "example_helper"
4
-
5
- Feature "using HTTP proxy" do
6
- as_a "authenticated user"
7
- i_want_to "use HTTP proxy"
8
- in_order_to "tweet behind a firewall"
9
-
10
- HOME_URL = "https://api.twitter.com/1/statuses/home_timeline.json?count=20&page=1"
11
-
12
- def setup
13
- super
14
- stub_http_request(:get, HOME_URL).to_return(:body => fixture_file('home.json'))
15
- end
16
-
17
- Scenario "enable proxy via environment variable" do
18
- When "I have proxy in envar, and start the application with 'home' command" do
19
- ENV['http_proxy'] = PROXY_URL
20
- @output = start_cli %w{home}
21
- end
22
-
23
- Then "the application uses the proxy to fetch my home timeline" do
24
- should_use_proxy
25
- end
26
- end
27
-
28
- Scenario "enable proxy via command line option" do
29
- When "I start the application with --http-proxy option and 'home' command" do
30
- ENV['http_proxy'] = nil
31
- @output = start_cli %W{--http-proxy #{PROXY_URL} home}
32
- end
33
-
34
- Then "the application uses the proxy to fetch my home timeline" do
35
- should_use_proxy
36
- end
37
- end
38
-
39
- Scenario "disable proxy via command line option" do
40
- When "I have proxy in envar, and start the application with --no-http-proxy option and 'home' command" do
41
- ENV['http_proxy'] = PROXY_URL
42
- @output = start_cli %w{--no-http-proxy home}
43
- end
44
-
45
- Then "the application does not use the proxy to fetch my home timeline" do
46
- should_not_use_proxy
47
- end
48
- end
49
-
50
- private
51
-
52
- def should_use_proxy
53
- nh = net_http
54
- nh.proxy_class?.should == true
55
- nh.instance_variable_get(:@proxy_address).should == PROXY_HOST
56
- nh.instance_variable_get(:@proxy_port).should == PROXY_PORT
57
- assert_requested(:get, HOME_URL)
58
- end
59
-
60
- def should_not_use_proxy
61
- net_http.proxy_class?.should == false
62
- assert_requested(:get, HOME_URL)
63
- end
64
-
65
- def net_http
66
- CLI.http.instance_variable_get(:@http)
67
- end
68
- end