tuomas-tweetwine 0.2.2 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,123 +3,156 @@ require "test_helper"
3
3
  module Tweetwine
4
4
 
5
5
  class UrlShortenerTest < Test::Unit::TestCase
6
- context "Upon initialization, an URL shortener" do
7
- should "raise exception if service URL is not given" do
8
- assert_raise(ArgumentError) do
9
- UrlShortener.new({
10
- :service_url => nil,
11
- :url_param_name => "url",
12
- :xpath_selector => "//input[@id='short_url']/@value"
13
- })
14
- end
6
+ context "An UrlShortener instance" do
7
+ setup do
8
+ @rest_client = mock()
15
9
  end
16
10
 
17
- should "raise exception if URL parameter name is not given" do
18
- assert_raise(ArgumentError) do
19
- UrlShortener.new({
20
- :service_url => "http://shorten.it/create",
21
- :url_param_name => nil,
22
- :xpath_selector => "//input[@id='short_url']/@value"
23
- })
11
+ context "upon initialization" do
12
+ should "raise exception if service URL is not given" do
13
+ assert_raise(ArgumentError) do
14
+ UrlShortener.new(
15
+ @rest_client,
16
+ {
17
+ :service_url => nil,
18
+ :url_param_name => "url",
19
+ :xpath_selector => "//input[@id='short_url']/@value"
20
+ }
21
+ )
22
+ end
24
23
  end
25
- end
26
24
 
27
- should "raise exception if XPath selector is not given" do
28
- assert_raise(ArgumentError) do
29
- UrlShortener.new({
30
- :service_url => "http://shorten.it/create",
31
- :url_param_name => "url",
32
- :xpath_selector => nil
33
- })
25
+ should "raise exception if URL parameter name is not given" do
26
+ assert_raise(ArgumentError) do
27
+ UrlShortener.new(
28
+ @rest_client,
29
+ {
30
+ :service_url => "http://shorten.it/create",
31
+ :url_param_name => nil,
32
+ :xpath_selector => "//input[@id='short_url']/@value"
33
+ }
34
+ )
35
+ end
34
36
  end
35
- end
36
37
 
37
- should "fallback to use GET method if not given explicitly" do
38
- url_shortener = UrlShortener.new({
39
- :service_url => "http://shorten.it/create",
40
- :url_param_name => "url",
41
- :xpath_selector => "//input[@id='short_url']/@value"
42
- })
43
- assert_equal(:get, url_shortener.instance_variable_get(:@method))
44
- end
45
- end
46
-
47
- context "At runtime, an URL shortener" do
48
- context "An URL shortener configured for HTTP GET" do
49
- should "use parameters as URL query parameters, with just the URL parameter" do
50
- url_shortener = UrlShortener.new({
51
- :method => "get",
52
- :service_url => "http://shorten.it/create",
53
- :url_param_name => "url",
54
- :xpath_selector => "//input[@id='short_url']/@value"
55
- })
56
- RestClientWrapper.expects(:get) \
57
- .with("http://shorten.it/create?url=http://www.ruby-doc.org/core/")
58
- url_shortener.shorten("http://www.ruby-doc.org/core/")
38
+ should "raise exception if XPath selector is not given" do
39
+ assert_raise(ArgumentError) do
40
+ UrlShortener.new(
41
+ @rest_client,
42
+ {
43
+ :service_url => "http://shorten.it/create",
44
+ :url_param_name => "url",
45
+ :xpath_selector => nil
46
+ }
47
+ )
48
+ end
59
49
  end
60
50
 
61
- should "use parameters as URL query parameters, with additional extra parameters" do
62
- url_shortener = UrlShortener.new({
63
- :method => "get",
64
- :service_url => "http://shorten.it/create",
65
- :url_param_name => "url",
66
- :extra_params => {
67
- :token => "xyz"
68
- },
69
- :xpath_selector => "//input[@id='short_url']/@value"
70
- })
71
- RestClientWrapper.expects(:get) \
72
- .with("http://shorten.it/create?token=xyz&url=http://www.ruby-doc.org/core/")
73
- url_shortener.shorten("http://www.ruby-doc.org/core/")
51
+ should "fallback to use GET method if not given explicitly" do
52
+ url_shortener = UrlShortener.new(
53
+ @rest_client,
54
+ {
55
+ :service_url => "http://shorten.it/create",
56
+ :url_param_name => "url",
57
+ :xpath_selector => "//input[@id='short_url']/@value"
58
+ }
59
+ )
60
+ assert_equal(:get, url_shortener.instance_variable_get(:@method))
74
61
  end
75
62
  end
76
63
 
77
- context "An URL shortener configured for HTTP POST" do
78
- should "use parameters as payload, with just the URL parameter" do
79
- url_shortener = UrlShortener.new({
80
- :method => "post",
81
- :service_url => "http://shorten.it/create",
82
- :url_param_name => "url",
83
- :xpath_selector => "//input[@id='short_url']/@value"
84
- })
85
- RestClientWrapper.expects(:post) \
86
- .with("http://shorten.it/create", {:url => "http://www.ruby-doc.org/core/"})
87
- url_shortener.shorten("http://www.ruby-doc.org/core/")
64
+ context "at runtime" do
65
+ context "configured for HTTP GET" do
66
+ should "use parameters as URL query parameters, with just the URL parameter" do
67
+ url_shortener = UrlShortener.new(
68
+ @rest_client,
69
+ {
70
+ :method => "get",
71
+ :service_url => "http://shorten.it/create",
72
+ :url_param_name => "url",
73
+ :xpath_selector => "//input[@id='short_url']/@value"
74
+ }
75
+ )
76
+ @rest_client.expects(:get) \
77
+ .with("http://shorten.it/create?url=http://www.ruby-doc.org/core/")
78
+ url_shortener.shorten("http://www.ruby-doc.org/core/")
79
+ end
80
+
81
+ should "use parameters as URL query parameters, with additional extra parameters" do
82
+ url_shortener = UrlShortener.new(
83
+ @rest_client,
84
+ {
85
+ :method => "get",
86
+ :service_url => "http://shorten.it/create",
87
+ :url_param_name => "url",
88
+ :extra_params => {
89
+ :token => "xyz"
90
+ },
91
+ :xpath_selector => "//input[@id='short_url']/@value"
92
+ }
93
+ )
94
+ @rest_client.expects(:get) \
95
+ .with("http://shorten.it/create?token=xyz&url=http://www.ruby-doc.org/core/")
96
+ url_shortener.shorten("http://www.ruby-doc.org/core/")
97
+ end
88
98
  end
89
99
 
90
- should "use parameters as payload, with additional extra parameters" do
91
- url_shortener = UrlShortener.new({
92
- :method => "post",
93
- :service_url => "http://shorten.it/create",
94
- :url_param_name => "url",
95
- :extra_params => {
96
- :token => "xyz"
97
- },
98
- :xpath_selector => "//input[@id='short_url']/@value"
99
- })
100
- RestClientWrapper.expects(:post) \
101
- .with("http://shorten.it/create", {
102
- :token => "xyz",
103
- :url => "http://www.ruby-doc.org/core/"
104
- })
105
- url_shortener.shorten("http://www.ruby-doc.org/core/")
100
+ context "configured for HTTP POST" do
101
+ should "use parameters as payload, with just the URL parameter" do
102
+ url_shortener = UrlShortener.new(
103
+ @rest_client,
104
+ {
105
+ :method => "post",
106
+ :service_url => "http://shorten.it/create",
107
+ :url_param_name => "url",
108
+ :xpath_selector => "//input[@id='short_url']/@value"
109
+ }
110
+ )
111
+ @rest_client.expects(:post) \
112
+ .with("http://shorten.it/create", {:url => "http://www.ruby-doc.org/core/"})
113
+ url_shortener.shorten("http://www.ruby-doc.org/core/")
114
+ end
115
+
116
+ should "use parameters as payload, with additional extra parameters" do
117
+ url_shortener = UrlShortener.new(
118
+ @rest_client,
119
+ {
120
+ :method => "post",
121
+ :service_url => "http://shorten.it/create",
122
+ :url_param_name => "url",
123
+ :extra_params => {
124
+ :token => "xyz"
125
+ },
126
+ :xpath_selector => "//input[@id='short_url']/@value"
127
+ }
128
+ )
129
+ @rest_client.expects(:post) \
130
+ .with("http://shorten.it/create", {
131
+ :token => "xyz",
132
+ :url => "http://www.ruby-doc.org/core/"
133
+ })
134
+ url_shortener.shorten("http://www.ruby-doc.org/core/")
135
+ end
106
136
  end
107
- end
108
137
 
109
- context "An URL shortener in erroenous situations" do
110
- should "raise ClientError upon connection error" do
111
- url_shortener = UrlShortener.new({
112
- :method => "post",
113
- :service_url => "http://shorten.it/create",
114
- :url_param_name => "url",
115
- :xpath_selector => "//input[@id='short_url']/@value"
116
- })
117
- RestClientWrapper.expects(:post) \
118
- .with("http://shorten.it/create", {
119
- :url => "http://www.ruby-doc.org/core/"
120
- }) \
121
- .raises(ClientError, "connection error")
122
- assert_raise(ClientError) { url_shortener.shorten("http://www.ruby-doc.org/core/") }
138
+ context "in erroenous situations" do
139
+ should "raise ClientError upon connection error" do
140
+ url_shortener = UrlShortener.new(
141
+ @rest_client,
142
+ {
143
+ :method => "post",
144
+ :service_url => "http://shorten.it/create",
145
+ :url_param_name => "url",
146
+ :xpath_selector => "//input[@id='short_url']/@value"
147
+ }
148
+ )
149
+ @rest_client.expects(:post) \
150
+ .with("http://shorten.it/create", {
151
+ :url => "http://www.ruby-doc.org/core/"
152
+ }) \
153
+ .raises(ClientError, "connection error")
154
+ assert_raise(ClientError) { url_shortener.shorten("http://www.ruby-doc.org/core/") }
155
+ end
123
156
  end
124
157
  end
125
158
  end
@@ -4,24 +4,22 @@ require "time"
4
4
  module Tweetwine
5
5
 
6
6
  class UtilTest < Test::Unit::TestCase
7
- context "The module" do
8
- should "humanize time difference" do
9
- assert_equal [1, "sec"], Util.humanize_time_diff(Time.parse("2009-01-01 00:00:59").to_s, Time.parse("2009-01-01 00:01:00"))
10
- assert_equal [0, "sec"], Util.humanize_time_diff(Time.parse("2009-01-01 01:00:00").to_s, Time.parse("2009-01-01 01:00:00"))
11
- assert_equal [1, "sec"], Util.humanize_time_diff(Time.parse("2009-01-01 01:00:00").to_s, Time.parse("2009-01-01 01:00:01"))
12
- assert_equal [59, "sec"], Util.humanize_time_diff(Time.parse("2009-01-01 01:00:00").to_s, Time.parse("2009-01-01 01:00:59"))
13
- assert_equal [59, "min"], Util.humanize_time_diff(Time.parse("2009-01-01 01:00").to_s, Time.parse("2009-01-01 01:59"))
14
- assert_equal [59, "min"], Util.humanize_time_diff(Time.parse("2009-01-01 01:00:30").to_s, Time.parse("2009-01-01 01:59:00"))
15
- assert_equal [57, "min"], Util.humanize_time_diff(Time.parse("2009-01-01 01:01:00").to_s, Time.parse("2009-01-01 01:58:00"))
16
- assert_equal [56, "min"], Util.humanize_time_diff(Time.parse("2009-01-01 01:01:31").to_s, Time.parse("2009-01-01 01:58:00"))
17
- assert_equal [57, "min"], Util.humanize_time_diff(Time.parse("2009-01-01 01:01:00").to_s, Time.parse("2009-01-01 01:58:29"))
18
- assert_equal [58, "min"], Util.humanize_time_diff(Time.parse("2009-01-01 01:01:00").to_s, Time.parse("2009-01-01 01:58:30"))
19
- assert_equal [1, "hour"], Util.humanize_time_diff(Time.parse("2009-01-01 01:00").to_s, Time.parse("2009-01-01 02:00"))
20
- assert_equal [1, "hour"], Util.humanize_time_diff(Time.parse("2009-01-01 02:00").to_s, Time.parse("2009-01-01 01:00"))
21
- assert_equal [2, "hours"], Util.humanize_time_diff(Time.parse("2009-01-01 01:00").to_s, Time.parse("2009-01-01 03:00"))
22
- assert_equal [1, "day"], Util.humanize_time_diff(Time.parse("2009-01-01 01:00").to_s, Time.parse("2009-01-02 03:00"))
23
- assert_equal [2, "days"], Util.humanize_time_diff(Time.parse("2009-01-01 01:00").to_s, Time.parse("2009-01-03 03:00"))
24
- end
7
+ should "humanize time difference" do
8
+ assert_equal [1, "sec"], Util.humanize_time_diff(Time.parse("2009-01-01 00:00:59").to_s, Time.parse("2009-01-01 00:01:00"))
9
+ assert_equal [0, "sec"], Util.humanize_time_diff(Time.parse("2009-01-01 01:00:00").to_s, Time.parse("2009-01-01 01:00:00"))
10
+ assert_equal [1, "sec"], Util.humanize_time_diff(Time.parse("2009-01-01 01:00:00").to_s, Time.parse("2009-01-01 01:00:01"))
11
+ assert_equal [59, "sec"], Util.humanize_time_diff(Time.parse("2009-01-01 01:00:00").to_s, Time.parse("2009-01-01 01:00:59"))
12
+ assert_equal [59, "min"], Util.humanize_time_diff(Time.parse("2009-01-01 01:00").to_s, Time.parse("2009-01-01 01:59"))
13
+ assert_equal [59, "min"], Util.humanize_time_diff(Time.parse("2009-01-01 01:00:30").to_s, Time.parse("2009-01-01 01:59:00"))
14
+ assert_equal [57, "min"], Util.humanize_time_diff(Time.parse("2009-01-01 01:01:00").to_s, Time.parse("2009-01-01 01:58:00"))
15
+ assert_equal [56, "min"], Util.humanize_time_diff(Time.parse("2009-01-01 01:01:31").to_s, Time.parse("2009-01-01 01:58:00"))
16
+ assert_equal [57, "min"], Util.humanize_time_diff(Time.parse("2009-01-01 01:01:00").to_s, Time.parse("2009-01-01 01:58:29"))
17
+ assert_equal [58, "min"], Util.humanize_time_diff(Time.parse("2009-01-01 01:01:00").to_s, Time.parse("2009-01-01 01:58:30"))
18
+ assert_equal [1, "hour"], Util.humanize_time_diff(Time.parse("2009-01-01 01:00").to_s, Time.parse("2009-01-01 02:00"))
19
+ assert_equal [1, "hour"], Util.humanize_time_diff(Time.parse("2009-01-01 02:00").to_s, Time.parse("2009-01-01 01:00"))
20
+ assert_equal [2, "hours"], Util.humanize_time_diff(Time.parse("2009-01-01 01:00").to_s, Time.parse("2009-01-01 03:00"))
21
+ assert_equal [1, "day"], Util.humanize_time_diff(Time.parse("2009-01-01 01:00").to_s, Time.parse("2009-01-02 03:00"))
22
+ assert_equal [2, "days"], Util.humanize_time_diff(Time.parse("2009-01-01 01:00").to_s, Time.parse("2009-01-03 03:00"))
25
23
  end
26
24
 
27
25
  should "symbolize hash keys" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tuomas-tweetwine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tuomas Kareinen
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-03 00:00:00 -07:00
12
+ date: 2009-09-16 00:00:00 -07:00
13
13
  default_executable: tweetwine
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -59,10 +59,11 @@ files:
59
59
  - test/util_test.rb
60
60
  has_rdoc: false
61
61
  homepage: http://github.com/tuomas/tweetwine
62
+ licenses:
62
63
  post_install_message:
63
64
  rdoc_options:
64
65
  - --title
65
- - tweetwine 0.2.2
66
+ - tweetwine 0.2.4
66
67
  - --main
67
68
  - README.rdoc
68
69
  - --exclude
@@ -85,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
86
  requirements: []
86
87
 
87
88
  rubyforge_project:
88
- rubygems_version: 1.2.0
89
+ rubygems_version: 1.3.5
89
90
  signing_key:
90
91
  specification_version: 3
91
92
  summary: A simple Twitter agent for command line use