svenaas-trim 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +36 -3
- data/Rakefile +7 -1
- data/lib/trim/version.rb +1 -1
- data/test/unit/online_trim_test.rb +34 -0
- data/test/unit/trim_test.rb +82 -80
- metadata +3 -2
data/README.rdoc
CHANGED
@@ -6,11 +6,24 @@ The trim gem is a wrapper for the tr.im URL shortening service,
|
|
6
6
|
which can be found at http://tr.im/
|
7
7
|
|
8
8
|
This software is not affiliated with tr.im in any way. tr.im is
|
9
|
-
a product of The Nambu Network
|
9
|
+
a product of The Nambu Network: http://www.nambu.com/.
|
10
10
|
|
11
11
|
== Installation
|
12
12
|
|
13
|
-
|
13
|
+
First, if you do not already have GitHub in your gem sources,
|
14
|
+
execute the following command to add it:
|
15
|
+
|
16
|
+
sudo gem sources -a http://gems.github.com
|
17
|
+
|
18
|
+
Then you can install this gem with:
|
19
|
+
|
20
|
+
sudo gem install svenaas-trim
|
21
|
+
|
22
|
+
If you prefer not to add GitHub to your gem sources, install via:
|
23
|
+
|
24
|
+
sudo gem install svenaas-trim -s http://gems.github.com
|
25
|
+
|
26
|
+
Windows users should omit the sudo, of course.
|
14
27
|
|
15
28
|
== Usage
|
16
29
|
|
@@ -18,9 +31,29 @@ a product of The Nambu Network (http://www.nambu.com/).
|
|
18
31
|
|
19
32
|
Trim.trim('http://www.google.com') # Returns trimmed URL, or nil if any error occurs
|
20
33
|
|
34
|
+
== Testing
|
35
|
+
|
36
|
+
The standard tests run via
|
37
|
+
|
38
|
+
rake test
|
39
|
+
|
40
|
+
use mock code to verify functionality instead of depending on
|
41
|
+
online interaction with tr.im's servers. This is done for several
|
42
|
+
reasons, primarily because the service provider deserves this basic
|
43
|
+
consideration, but also because tr.im limits the number of URLs
|
44
|
+
which can be shortened during a particular amount of time.
|
45
|
+
|
46
|
+
If you need to verify online functionality you can run
|
47
|
+
|
48
|
+
rake test:online
|
49
|
+
|
50
|
+
for simple-case testing that the servers are reachable via the
|
51
|
+
expected address and API. Please note that this test consumes
|
52
|
+
online resources, and use it sparingly.
|
53
|
+
|
21
54
|
== License
|
22
55
|
|
23
|
-
Copyright (c) 2009 Sven Aas
|
56
|
+
Copyright (c) 2009 Sven Aas
|
24
57
|
|
25
58
|
Permission is hereby granted, free of charge, to any person
|
26
59
|
obtaining a copy of this software and associated documentation
|
data/Rakefile
CHANGED
@@ -29,7 +29,13 @@ end
|
|
29
29
|
|
30
30
|
Rake::TestTask.new do |t|
|
31
31
|
t.libs << 'test'
|
32
|
-
t.test_files = FileList
|
32
|
+
t.test_files = FileList.new("test/**/*_test.rb") { |fl| fl.exclude /online/ }
|
33
|
+
t.verbose = true
|
34
|
+
end
|
35
|
+
|
36
|
+
Rake::TestTask.new("test:online") do |t|
|
37
|
+
t.libs << 'test'
|
38
|
+
t.test_files = FileList.new("test/**/online_*_test.rb")
|
33
39
|
t.verbose = true
|
34
40
|
end
|
35
41
|
|
data/lib/trim/version.rb
CHANGED
@@ -0,0 +1,34 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
require 'net/http'
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
|
6
|
+
class TrimTest < Test::Unit::TestCase
|
7
|
+
|
8
|
+
context "A valid URL" do
|
9
|
+
|
10
|
+
setup do
|
11
|
+
@long_url = 'http://www.google.com/'
|
12
|
+
end
|
13
|
+
|
14
|
+
context "An online trim_simple request" do
|
15
|
+
should "provide a working shortened URL" do
|
16
|
+
trimmed_url = Trim.trim_simple @long_url
|
17
|
+
response = Net::HTTP.get_response(URI.parse(trimmed_url))
|
18
|
+
assert response.kind_of?(Net::HTTPRedirection)
|
19
|
+
assert_equal @long_url, response['location']
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "An online trim_url request" do
|
24
|
+
should "provide a working shortened URL" do
|
25
|
+
trimmed_url = Trim.trim_url @long_url
|
26
|
+
response = Net::HTTP.get_response(URI.parse(trimmed_url))
|
27
|
+
assert response.kind_of?(Net::HTTPRedirection)
|
28
|
+
assert_equal @long_url, response['location']
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
data/test/unit/trim_test.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
-
require '
|
3
|
-
require 'uri'
|
4
|
-
|
2
|
+
require 'mocha'
|
5
3
|
|
6
4
|
class TrimTest < Test::Unit::TestCase
|
7
5
|
|
6
|
+
VALID_SHORTENED_URL = "http://tr.im/OK"
|
7
|
+
|
8
8
|
context "A valid URL" do
|
9
9
|
|
10
10
|
setup do
|
@@ -13,88 +13,90 @@ class TrimTest < Test::Unit::TestCase
|
|
13
13
|
|
14
14
|
context "A trim_simple request" do
|
15
15
|
should "provide a working shortened URL" do
|
16
|
+
Trim.expects(:trim_simple).with(@long_url).returns(VALID_SHORTENED_URL)
|
16
17
|
trimmed_url = Trim.trim_simple @long_url
|
17
|
-
|
18
|
-
assert response.kind_of?(Net::HTTPRedirection)
|
19
|
-
assert_equal @long_url, response['location']
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
context "A trim_url request" do
|
24
|
-
should "provide a working shortened URL" do
|
25
|
-
trimmed_url = Trim.trim_url @long_url
|
26
|
-
response = Net::HTTP.get_response(URI.parse(trimmed_url))
|
27
|
-
assert response.kind_of?(Net::HTTPRedirection)
|
28
|
-
assert_equal @long_url, response['location']
|
18
|
+
assert_equal VALID_SHORTENED_URL, trimmed_url
|
29
19
|
end
|
30
20
|
end
|
31
21
|
|
22
|
+
context "A trim_url request" do
|
23
|
+
should "provide a working shortened URL" do
|
24
|
+
Trim.expects(:trim_url).with(@long_url).returns(VALID_SHORTENED_URL)
|
25
|
+
trimmed_url = Trim.trim_url @long_url
|
26
|
+
assert_equal VALID_SHORTENED_URL, trimmed_url
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
32
30
|
end
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
31
|
+
|
32
|
+
context "An invalid URL" do
|
33
|
+
|
34
|
+
setup do
|
35
|
+
@long_url = 'www'
|
36
|
+
end
|
37
|
+
|
38
|
+
context "A trim_simple request" do
|
39
|
+
should "return nil" do
|
40
|
+
Trim.expects(:trim_simple).with(@long_url).returns(nil)
|
41
|
+
trimmed_url = Trim.trim_simple @long_url
|
42
|
+
assert_nil trimmed_url
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context "A trim_url request" do
|
47
|
+
should "return nil" do
|
48
|
+
Trim.expects(:trim_url).with(@long_url).returns(nil)
|
49
|
+
trimmed_url = Trim.trim_url @long_url
|
50
|
+
assert_nil trimmed_url
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
context "An empty URL" do
|
57
|
+
|
58
|
+
setup do
|
59
|
+
@long_url = ''
|
60
|
+
end
|
61
|
+
|
62
|
+
context "A trim_simple request" do
|
63
|
+
should "return nil" do
|
64
|
+
Trim.expects(:trim_simple).with('').returns(nil)
|
65
|
+
trimmed_url = Trim.trim_simple @long_url
|
66
|
+
assert_nil trimmed_url
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context "A trim_url request" do
|
71
|
+
should "return nil" do
|
72
|
+
Trim.expects(:trim_url).with('').returns(nil)
|
73
|
+
trimmed_url = Trim.trim_url @long_url
|
74
|
+
assert_nil trimmed_url
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
context "A nil URL" do
|
81
|
+
|
82
|
+
setup do
|
83
|
+
@long_url = nil
|
84
|
+
end
|
85
|
+
|
86
|
+
context "A trim_simple request" do
|
87
|
+
should "return nil" do
|
88
|
+
trimmed_url = Trim.trim @long_url
|
89
|
+
assert_nil trimmed_url
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context "A trim_url request" do
|
94
|
+
should "return nil" do
|
95
|
+
trimmed_url = Trim.trim @long_url
|
96
|
+
assert_nil trimmed_url
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
98
100
|
end
|
99
101
|
|
100
102
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: svenaas-trim
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sven Aas
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-03-
|
12
|
+
date: 2009-03-03 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -38,6 +38,7 @@ files:
|
|
38
38
|
- lib/trim.rb
|
39
39
|
- test/test_helper.rb
|
40
40
|
- test/unit
|
41
|
+
- test/unit/online_trim_test.rb
|
41
42
|
- test/unit/trim_test.rb
|
42
43
|
has_rdoc: true
|
43
44
|
homepage: http://github.com/svenaas/trim/
|