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 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 (http://www.nambu.com/).
9
+ a product of The Nambu Network: http://www.nambu.com/.
10
10
 
11
11
  == Installation
12
12
 
13
- sudo gem install trim
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 (mailto:sven.aas@gmail.com)
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["test/**/*_test.rb"]
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
@@ -3,7 +3,7 @@ module Trim
3
3
 
4
4
  MAJOR = 0
5
5
  MINOR = 1
6
- TINY = 2
6
+ TINY = 3
7
7
 
8
8
  def self.to_s # :nodoc:
9
9
  [MAJOR, MINOR, TINY].join('.')
@@ -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
@@ -1,10 +1,10 @@
1
1
  require File.dirname(__FILE__) + '/../test_helper'
2
- require 'net/http'
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
- 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 "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
- context "An invalid URL" do
35
-
36
- setup do
37
- @long_url = 'www'
38
- end
39
-
40
- context "A trim_simple request" do
41
- should "return nil" do
42
- trimmed_url = Trim.trim @long_url
43
- assert_nil trimmed_url
44
- end
45
- end
46
-
47
- context "A trim_url request" do
48
- should "return nil" do
49
- trimmed_url = Trim.trim @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
- trimmed_url = Trim.trim @long_url
65
- assert_nil trimmed_url
66
- end
67
- end
68
-
69
- context "A trim_url request" do
70
- should "return nil" do
71
- trimmed_url = Trim.trim @long_url
72
- assert_nil trimmed_url
73
- end
74
- end
75
-
76
- end
77
-
78
- context "A nil URL" do
79
-
80
- setup do
81
- @long_url = nil
82
- end
83
-
84
- context "A trim_simple request" do
85
- should "return nil" do
86
- trimmed_url = Trim.trim @long_url
87
- assert_nil trimmed_url
88
- end
89
- end
90
-
91
- context "A trim_url request" do
92
- should "return nil" do
93
- trimmed_url = Trim.trim @long_url
94
- assert_nil trimmed_url
95
- end
96
- end
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.2
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-02 00:00:00 -08:00
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/