tuomas-tweetwine 0.1.11 → 0.2.1

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.
@@ -0,0 +1,19 @@
1
+ require File.dirname(__FILE__) << "/test_helper"
2
+
3
+ module Tweetwine
4
+
5
+ class OptionsTest < Test::Unit::TestCase
6
+ context "Options" do
7
+ should "get the value corresponding to a key or nil (the default value)" do
8
+ assert_equal "alpha", Options.new({:a => "alpha"})[:a]
9
+ assert_equal nil, Options.new({})[:a]
10
+ end
11
+
12
+ should "require missing value (a value that is nil)" do
13
+ assert_equal "alpha", Options.new({:a => "alpha"}).require(:a)
14
+ assert_raises(RuntimeError) { Options.new({}).require(:a) }
15
+ end
16
+ end
17
+ end
18
+
19
+ end
@@ -0,0 +1,24 @@
1
+ require File.dirname(__FILE__) << "/test_helper"
2
+ require "rest_client"
3
+
4
+ module Tweetwine
5
+
6
+ class RestClientWrapperTest < Test::Unit::TestCase
7
+ context "A rest client wrapper" do
8
+ should "raise ClientError for an invalid request" do
9
+ RestClient.expects(:get) \
10
+ .with("https://secret:agent@hushhush.net") \
11
+ .raises(RestClient::Unauthorized)
12
+ assert_raises(ClientError) { RestClientWrapper.get("https://secret:agent@hushhush.net") }
13
+ end
14
+
15
+ should "raise ClientError when connection cannot be established" do
16
+ RestClient.expects(:get) \
17
+ .with("http://www.invalid.net") \
18
+ .raises(Errno::ECONNRESET)
19
+ assert_raises(ClientError) { RestClientWrapper.get("http://www.invalid.net") }
20
+ end
21
+ end
22
+ end
23
+
24
+ end
data/test/test_helper.rb CHANGED
@@ -6,30 +6,33 @@ require "mocha"
6
6
 
7
7
  module Tweetwine
8
8
  module TestHelpers
9
- def create_test_statuses(*records)
10
- statuses = records.map do |record|
9
+ def create_test_statuses(*gen_records)
10
+ status_records = gen_records.map do |gen_record|
11
11
  {
12
- "created_at" => record[:status][:created_at],
13
- "text" => record[:status][:text],
14
- "in_reply_to_screen_name" => record[:status][:in_reply_to],
15
- "user" => { "screen_name" => record[:user] }
12
+ "user" => { "screen_name" => gen_record[:user] },
13
+ "created_at" => gen_record[:status][:created_at],
14
+ "text" => gen_record[:status][:text],
15
+ "in_reply_to_screen_name" => gen_record[:status][:in_reply_to]
16
16
  }
17
17
  end
18
- [statuses, records]
18
+ [status_records, gen_records]
19
19
  end
20
20
 
21
- def create_test_users(*records)
22
- statuses = records.map do |record|
23
- {
24
- "screen_name" => record[:user],
25
- "status" => {
26
- "created_at" => record[:status][:created_at],
27
- "text" => record[:status][:text],
28
- "in_reply_to_screen_name" => record[:status][:in_reply_to],
29
- }
30
- }
21
+ def create_test_users(*gen_records)
22
+ user_records = gen_records.map do |gen_record|
23
+ user_record = { "screen_name" => gen_record[:user] }
24
+ if gen_record[:status]
25
+ user_record.merge!({
26
+ "status" => {
27
+ "created_at" => gen_record[:status][:created_at],
28
+ "text" => gen_record[:status][:text],
29
+ "in_reply_to_screen_name" => gen_record[:status][:in_reply_to],
30
+ }
31
+ })
32
+ end
33
+ user_record
31
34
  end
32
- [statuses, records]
35
+ [user_records, gen_records]
33
36
  end
34
37
  end
35
38
  end
@@ -0,0 +1,68 @@
1
+ require File.dirname(__FILE__) << "/test_helper"
2
+
3
+ module Tweetwine
4
+
5
+ class UrlShortenerTest < Test::Unit::TestCase
6
+ context "An URL shortener configured for HTTP GET" do
7
+ should "use parameters as URL query parameters, with just the URL parameter" do
8
+ url_shortener = UrlShortener.new({
9
+ :method => "get",
10
+ :service_url => "http://shorten.it/create",
11
+ :url_param_name => "url",
12
+ :xpath_selector => "//input[@id='short_url']/@value"
13
+ })
14
+ RestClientWrapper.expects(:get) \
15
+ .with("http://shorten.it/create?url=http://www.ruby-doc.org/core/")
16
+ url_shortener.shorten("http://www.ruby-doc.org/core/")
17
+ end
18
+
19
+ should "use parameters as URL query parameters, with additional extra parameters" do
20
+ url_shortener = UrlShortener.new({
21
+ :method => "get",
22
+ :service_url => "http://shorten.it/create",
23
+ :url_param_name => "url",
24
+ :extra_params => {
25
+ :token => "xyz"
26
+ },
27
+ :xpath_selector => "//input[@id='short_url']/@value"
28
+ })
29
+ RestClientWrapper.expects(:get) \
30
+ .with("http://shorten.it/create?token=xyz&url=http://www.ruby-doc.org/core/")
31
+ url_shortener.shorten("http://www.ruby-doc.org/core/")
32
+ end
33
+ end
34
+
35
+ context "An URL shortener configured for HTTP POST" do
36
+ should "use parameters as payload, with just the URL parameter" do
37
+ url_shortener = UrlShortener.new({
38
+ :method => "post",
39
+ :service_url => "http://shorten.it/create",
40
+ :url_param_name => "url",
41
+ :xpath_selector => "//input[@id='short_url']/@value"
42
+ })
43
+ RestClientWrapper.expects(:post) \
44
+ .with("http://shorten.it/create", {:url => "http://www.ruby-doc.org/core/"})
45
+ url_shortener.shorten("http://www.ruby-doc.org/core/")
46
+ end
47
+
48
+ should "use parameters as payload, with just the URL parameter" do
49
+ url_shortener = UrlShortener.new({
50
+ :method => "post",
51
+ :service_url => "http://shorten.it/create",
52
+ :url_param_name => "url",
53
+ :extra_params => {
54
+ :token => "xyz"
55
+ },
56
+ :xpath_selector => "//input[@id='short_url']/@value"
57
+ })
58
+ RestClientWrapper.expects(:post) \
59
+ .with("http://shorten.it/create", {
60
+ :token => "xyz",
61
+ :url => "http://www.ruby-doc.org/core/"
62
+ })
63
+ url_shortener.shorten("http://www.ruby-doc.org/core/")
64
+ end
65
+ end
66
+ end
67
+
68
+ end
data/test/util_test.rb CHANGED
@@ -23,6 +23,35 @@ class UtilTest < Test::Unit::TestCase
23
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
24
  end
25
25
  end
26
+
27
+ should "symbolize hash keys" do
28
+ given = {
29
+ "alpha" => "A",
30
+ :beta => "B",
31
+ "charlie" => "C",
32
+ "delta" => {
33
+ "echelon" => "E",
34
+ "fox" => "F"
35
+ }
36
+ }
37
+ expected = {
38
+ :alpha => "A",
39
+ :beta => "B",
40
+ :charlie => "C",
41
+ :delta => {
42
+ :echelon => "E",
43
+ :fox => "F"
44
+ }
45
+ }
46
+ assert_equal expected, Util.symbolize_hash_keys(given)
47
+ end
48
+
49
+ should "parse integers from strings, with minimum and default values, and naming parameter" do
50
+ assert_equal 6, Util.parse_int_gt("6", 8, 4, "ethical working hours per day")
51
+ assert_equal 8, Util.parse_int_gt(nil, 8, 4, "ethical working hours per day")
52
+ assert_equal 8, Util.parse_int_gt(false, 8, 4, "ethical working hours per day")
53
+ assert_raises(ArgumentError) { Util.parse_int_gt(3, 8, 4, "ethical working hours per day") }
54
+ end
26
55
  end
27
56
 
28
57
  end
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.1.11
4
+ version: 0.2.1
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-08-10 00:00:00 -07:00
12
+ date: 2009-08-17 00:00:00 -07:00
13
13
  default_executable: tweetwine
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -39,14 +39,21 @@ files:
39
39
  - lib/tweetwine
40
40
  - lib/tweetwine/client.rb
41
41
  - lib/tweetwine/io.rb
42
+ - lib/tweetwine/meta.rb
43
+ - lib/tweetwine/options.rb
44
+ - lib/tweetwine/rest_client_wrapper.rb
42
45
  - lib/tweetwine/startup_config.rb
46
+ - lib/tweetwine/url_shortener.rb
43
47
  - lib/tweetwine/util.rb
44
48
  - lib/tweetwine.rb
45
49
  - test/client_test.rb
46
50
  - test/io_test.rb
51
+ - test/options_test.rb
52
+ - test/rest_client_wrapper_test.rb
47
53
  - test/startup_config_test.rb
48
54
  - test/test_config.yaml
49
55
  - test/test_helper.rb
56
+ - test/url_shortener_test.rb
50
57
  - test/util_test.rb
51
58
  has_rdoc: false
52
59
  homepage: http://github.com/tuomas/tweetwine
@@ -54,7 +61,7 @@ licenses:
54
61
  post_install_message:
55
62
  rdoc_options:
56
63
  - --title
57
- - Tweetwine 0.1.11
64
+ - Tweetwine 0.2.1
58
65
  - --main
59
66
  - README.rdoc
60
67
  - --exclude