gitable 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,17 +1,16 @@
1
1
  require 'bundler'
2
2
  Bundler::GemHelper.install_tasks
3
3
 
4
- require 'spec/rake/spectask'
5
- Spec::Rake::SpecTask.new(:spec) do |spec|
6
- spec.libs << 'lib' << 'spec'
7
- spec.spec_files = FileList['spec/**/*_spec.rb']
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new do |t|
6
+ t.rspec_opts = %w[--color]
7
+ t.pattern = 'spec/**/*_spec.rb'
8
8
  end
9
-
10
9
  task :default => :spec
11
10
 
12
- Spec::Rake::SpecTask.new(:rcov) do |spec|
13
- spec.libs << 'lib' << 'spec'
14
- spec.pattern = 'spec/**/*_spec.rb'
15
- spec.rcov = true
16
- spec.rcov_opts << '--exclude' << 'spec,vendor,Library,.bundle'
11
+ RSpec::Core::RakeTask.new(:rcov) do |t|
12
+ t.rspec_opts = %w[--color]
13
+ t.pattern = 'spec/**/*_spec.rb'
14
+ t.rcov = true
15
+ t.rcov_opts = %w[--exclude spec/,gems/,Library/,.bundle]
17
16
  end
data/gitable.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  Gem::Specification.new do |s|
3
3
  s.name = "gitable"
4
- s.version = "0.1.3"
4
+ s.version = "0.2.0"
5
5
  s.authors = ["Martin Emde"]
6
6
  s.email = ["martin.emde@gmail.com"]
7
7
  s.homepage = "http://github.org/martinemde/gitable"
@@ -9,8 +9,9 @@ Gem::Specification.new do |s|
9
9
  s.description = %q{Addressable::URI for Git URIs with special handling for scp-style URIs that Addressable doesn't like.}
10
10
 
11
11
  s.add_dependency "addressable"
12
- s.add_development_dependency "rspec"
12
+ s.add_development_dependency "rspec", "~>2.0"
13
13
  s.add_development_dependency "rake"
14
+ s.add_development_dependency "rcov"
14
15
 
15
16
  s.files = `git ls-files`.split("\n")
16
17
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -2,6 +2,38 @@ require 'gitable/uri'
2
2
 
3
3
  module Gitable
4
4
  class ScpURI < Gitable::URI
5
+ REGEXP = %r|^([^:/?#]+):([^:?#]*)$|
6
+
7
+ ##
8
+ # Expected to be an scp style URI if Addressable interprets it wrong and
9
+ # it matches our scp regexp
10
+ #
11
+ # nil host is an Addressable misunderstanding (therefore it might be scp style)
12
+ def self.scp?(uri)
13
+ uri && uri.match(REGEXP) && Addressable::URI.parse(uri).normalized_host.nil?
14
+ end
15
+
16
+ ##
17
+ # Parse an Scp style git repository URI into a URI object.
18
+ #
19
+ # @param [Addressable::URI, #to_str] uri URI of a git repository.
20
+ #
21
+ # @return [Gitable::URI, nil] the URI object or nil if nil was passed in.
22
+ #
23
+ # @raise [TypeError] The uri must respond to #to_str.
24
+ # @raise [Gitable::URI::InvalidURIError] When the uri is *total* rubbish.
25
+ #
26
+ def self.parse(uri)
27
+ return uri if uri.nil? || uri.kind_of?(self)
28
+
29
+ if scp?(uri)
30
+ authority, path = uri.scan(REGEXP).flatten
31
+ Gitable::ScpURI.new(:authority => authority, :path => path)
32
+ else
33
+ raise InvalidURIError, "Unable to parse scp style URI: #{uri}"
34
+ end
35
+ end
36
+
5
37
 
6
38
  # Keep URIs like this as they were input:
7
39
  #
@@ -15,8 +47,12 @@ module Gitable
15
47
  # @return [String] The same path passed in.
16
48
  def path=(new_path)
17
49
  super
18
- @path = path.sub(%r|^/|,'') if new_path[0] != ?/ # addressable likes to add a /
19
- @path
50
+ if new_path[0..0] != '/' # addressable adds a / but scp-style uris are altered by this behavior
51
+ @path = path.sub(%r|^/+|,'')
52
+ @normalized_path = normalized_path.sub(%r|^/+|,'')
53
+ validate
54
+ end
55
+ path
20
56
  end
21
57
 
22
58
  # Get the URI as a string in the same form it was input.
@@ -27,7 +63,7 @@ module Gitable
27
63
  def to_s
28
64
  @uri_string ||=
29
65
  begin
30
- uri_string = "#{authority}:#{path}"
66
+ uri_string = "#{normalized_authority}:#{normalized_path}"
31
67
  if uri_string.respond_to?(:force_encoding)
32
68
  uri_string.force_encoding(Encoding::UTF_8)
33
69
  end
@@ -38,28 +74,39 @@ module Gitable
38
74
  # Return the actual scheme even though we don't show it
39
75
  #
40
76
  # @return [String] always 'ssh' for scp style URIs
41
- def normalized_scheme
77
+ def inferred_scheme
42
78
  'ssh'
43
79
  end
44
80
 
81
+ # Scp style URIs are always ssh
82
+ #
83
+ # @return [true] always ssh
84
+ def ssh?
85
+ true
86
+ end
87
+
45
88
  protected
46
89
 
47
90
  def validate
48
91
  return if @validation_deferred
49
92
 
50
- if !scheme.to_s.empty? && host.to_s.empty? && path.to_s.empty?
51
- raise InvalidURIError, "Absolute URI missing hierarchical segment: '#{to_s}'"
93
+ if normalized_host.to_s.empty?
94
+ raise InvalidURIError, "Hostname segment missing: '#{to_s}'"
52
95
  end
53
96
 
54
- if host.nil? && !path_only?
55
- raise InvalidURIError, "Hostname not supplied: '#{to_s}'"
97
+ unless normalized_scheme.to_s.empty?
98
+ raise InvalidURIError, "Scp style URI must not have a scheme: '#{to_s}'"
56
99
  end
57
100
 
58
- nil
59
- end
101
+ if !normalized_port.to_s.empty?
102
+ raise InvalidURIError, "Scp style URI cannot have a port: '#{to_s}'"
103
+ end
104
+
105
+ if normalized_path.to_s.empty?
106
+ raise InvalidURIError, "Absolute URI missing hierarchical segment: '#{to_s}'"
107
+ end
60
108
 
61
- def path_only?
62
- host.nil? && port.nil? && user.nil? && password.nil?
109
+ nil
63
110
  end
64
111
  end
65
112
  end
data/lib/gitable/uri.rb CHANGED
@@ -2,7 +2,6 @@ require 'addressable/uri'
2
2
 
3
3
  module Gitable
4
4
  class URI < Addressable::URI
5
- SCP_URI_REGEXP = %r|^([^:/?#]+):([^:?#]*)$|
6
5
 
7
6
  ##
8
7
  # Parse a git repository URI into a URI object.
@@ -20,13 +19,9 @@ module Gitable
20
19
  # addressable::URI.parse always returns an instance of Addressable::URI.
21
20
  add = super # >:( at inconsistency
22
21
 
23
- authority = uri.scan(SCP_URI_REGEXP).flatten.first
24
-
25
- if add.host.nil? && authority
26
- Gitable::ScpURI.new(
27
- :authority => authority,
28
- :path => add.path
29
- )
22
+ if Gitable::ScpURI.scp?(uri)
23
+ # nil host is an Addressable misunderstanding (therefore it might be scp style)
24
+ Gitable::ScpURI.parse(uri)
30
25
  else
31
26
  new(add.omit(:password,:query,:fragment).to_hash)
32
27
  end
@@ -50,13 +45,30 @@ module Gitable
50
45
  return uri if uri.nil? || uri.kind_of?(self)
51
46
 
52
47
  # Addressable::URI.heuristic_parse _does_ return the correct type :)
53
- add = super # boo inconsistency
48
+ gitable = super # boo inconsistency
54
49
 
55
- if add.extname != ".git"
56
- add.extname = "git"
57
- add.scheme = "git" if add.scheme == "http"
50
+ if gitable.github?
51
+ gitable.extname = "git"
58
52
  end
59
- add
53
+ gitable
54
+ end
55
+
56
+ # Is this uri a github uri?
57
+ #
58
+ # @return [Boolean] github.com is the host?
59
+ def github?
60
+ !!normalized_host.to_s.match(/\.?github.com$/)
61
+ end
62
+
63
+ # Create a web uri for repositories that follow the github pattern.
64
+ # This probably won't work for all git hosts, so it's a good idea to use
65
+ # this in conjunction with #github? to help ensure correct links.
66
+ #
67
+ # @param [String] Scheme of the web uri (smart defaults)
68
+ # @return [Addressable::URI] https://#{host}/#{path_without_git_extension}
69
+ def to_web_uri(uri_scheme='https')
70
+ return nil if normalized_host.to_s.empty?
71
+ Addressable::URI.new(:scheme => uri_scheme, :host => normalized_host, :port => normalized_port, :path => normalized_path.sub(%r#\.git/?#, ''))
60
72
  end
61
73
 
62
74
  # Tries to guess the project name of the repository.
@@ -70,18 +82,32 @@ module Gitable
70
82
  #
71
83
  # @return [Boolean] Is the URI local
72
84
  def local?
73
- scheme == 'file' || host.nil?
85
+ inferred_scheme == 'file'
86
+ end
87
+
88
+ # Scheme inferred by the URI (URIs without hosts or schemes are assumed to be 'file')
89
+ #
90
+ # @return [Boolean] Is the URI local
91
+ def inferred_scheme
92
+ if normalized_scheme == 'file' || (normalized_scheme.to_s.empty? && normalized_host.to_s.empty?)
93
+ 'file'
94
+ else
95
+ normalized_scheme
96
+ end
74
97
  end
75
98
 
76
99
  # Detect URIs that connect over ssh
77
100
  #
78
101
  # @return [Boolean] true if the URI uses ssh?
79
102
  def ssh?
80
- !!(normalized_scheme =~ /ssh/)
103
+ !!normalized_scheme.to_s.match(/ssh/)
81
104
  end
82
105
 
106
+ # Detect URIs that will require some sort of authentication
107
+ #
108
+ # @return [Boolean] true if the URI uses ssh or has a user but no password
83
109
  def authenticated?
84
- ssh? || (!user.nil? && password.nil?)
110
+ ssh? || (!normalized_user.nil? && normalized_password.nil?)
85
111
  end
86
112
 
87
113
  # Set an extension name, replacing one if it exists.
@@ -89,20 +115,30 @@ module Gitable
89
115
  # If there is no basename (i.e. no words in the path) this method call will
90
116
  # be ignored because it is likely to break the uri.
91
117
  #
118
+ # Use the public method #set_git_extname unless you actually need some other ext
119
+ #
92
120
  # @param [String] New extension name
93
121
  # @return [String] extname result
94
- def extname=(ext)
95
- base = basename
96
- return nil if base.nil? || base == ""
97
- self.basename = "#{base}.#{ext.sub(/^\.+/,'')}"
122
+ def extname=(new_ext)
123
+ return nil if basename.to_s.empty?
124
+ self.basename = "#{basename.sub(%r#\.git/?$#, '')}.#{new_ext.sub(/^\.+/,'')}"
98
125
  extname
99
126
  end
100
127
 
128
+ # Set the '.git' extension name, replacing one if it exists.
129
+ #
130
+ # If there is no basename (i.e. no words in the path) this method call will
131
+ # be ignored because it is likely to break the uri.
132
+ #
133
+ # @return [String] extname result
134
+ def set_git_extname
135
+ self.extname = "git"
136
+ end
137
+
101
138
  # Addressable does basename wrong when there's no basename.
102
139
  # It returns "/" for something like "http://host.com/"
103
140
  def basename
104
- base = super
105
- base == "/" ? "" : base
141
+ super == "/" ? "" : super
106
142
  end
107
143
 
108
144
  # Set the basename, replacing it if it exists.
@@ -111,10 +147,10 @@ module Gitable
111
147
  # @return [String] basename result
112
148
  def basename=(new_basename)
113
149
  base = basename
114
- if base.nil? || base == ""
150
+ if base.to_s.empty?
115
151
  self.path += new_basename
116
152
  else
117
- rpath = path.reverse
153
+ rpath = normalized_path.reverse
118
154
  # replace the last occurrence of the basename with basename.ext
119
155
  self.path = rpath.sub(%r|#{Regexp.escape(base.reverse)}|, new_basename.reverse).reverse
120
156
  end
@@ -127,8 +163,8 @@ module Gitable
127
163
  return if @validation_deferred
128
164
  super
129
165
 
130
- if user && scheme != 'ssh'
131
- raise InvalidURIError, "Git does not support URIs with 'user@' other than ssh:// and scp-style"
166
+ if normalized_user && normalized_scheme != 'ssh'
167
+ raise InvalidURIError, "URIs with 'user@' other than ssh:// and scp-style are not supported."
132
168
  end
133
169
  end
134
170
  end
data/spec/gitable_spec.rb CHANGED
@@ -1,18 +1,21 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Gitable::URI do
4
- before do
5
- @uri = "ssh://git@github.com/martinemde/gitable.git"
6
- end
7
-
8
4
  describe_uri "git://github.com/martinemde/gitable" do
9
- it "sets a new extname" do
5
+ it "sets the .git extname" do
10
6
  subject.extname.should == ""
11
- subject.extname = "git"
7
+ subject.set_git_extname
12
8
  subject.extname.should == ".git"
13
9
  subject.to_s.should == @uri + ".git"
14
10
  end
15
11
 
12
+ it "does not duplicate the extname" do
13
+ subject.extname = "git"
14
+ subject.to_s.should == @uri + ".git"
15
+ subject.set_git_extname
16
+ subject.to_s.should == @uri + ".git"
17
+ end
18
+
16
19
  it "sets a new basename" do
17
20
  subject.basename.should == "gitable"
18
21
  subject.basename = "gitable.git"
@@ -24,7 +27,7 @@ describe Gitable::URI do
24
27
  describe_uri "git://github.com/" do
25
28
  it "does not set a new extname" do
26
29
  subject.extname.should == ""
27
- subject.extname = "git"
30
+ subject.set_git_extname
28
31
  subject.extname.should == ""
29
32
  subject.to_s.should == @uri
30
33
  end
@@ -66,6 +69,8 @@ describe Gitable::URI do
66
69
  #
67
70
 
68
71
  describe ".parse" do
72
+ before { @uri = "ssh://git@github.com/martinemde/gitable.git" }
73
+
69
74
  it "returns a Gitable::URI" do
70
75
  Gitable::URI.parse(@uri).should be_a_kind_of(Gitable::URI)
71
76
  end
@@ -87,8 +92,11 @@ describe Gitable::URI do
87
92
 
88
93
  context "(bad uris)" do
89
94
  [
90
- "http://",
91
- "blah:",
95
+ "http://", # nothing but scheme
96
+ "blah:", # pretty much nothing
97
+ "http://user@example.com/path.git", # unsupported http with user part
98
+ "user@:path.git", # no host
99
+ "user@host:", # no path
92
100
  ].each do |uri|
93
101
  it "raises an Gitable::URI::InvalidURIError with #{uri.inspect}" do
94
102
  lambda {
@@ -96,6 +104,38 @@ describe Gitable::URI do
96
104
  }.should raise_error(Gitable::URI::InvalidURIError)
97
105
  end
98
106
  end
107
+
108
+ context "scp uris" do
109
+ it "raises without path" do
110
+ lambda {
111
+ Gitable::ScpURI.parse("http://github.com/path.git")
112
+ }.should raise_error(Gitable::URI::InvalidURIError)
113
+ end
114
+
115
+ it "raises without path" do
116
+ lambda {
117
+ Gitable::ScpURI.new(:user => 'git', :host => 'github.com')
118
+ }.should raise_error(Gitable::URI::InvalidURIError)
119
+ end
120
+
121
+ it "raises without host" do
122
+ lambda {
123
+ Gitable::ScpURI.new(:user => 'git', :path => 'path')
124
+ }.should raise_error(Gitable::URI::InvalidURIError)
125
+ end
126
+
127
+ it "raises with any scheme" do
128
+ lambda {
129
+ Gitable::ScpURI.new(:scheme => 'ssh', :host => 'github.com', :path => 'path')
130
+ }.should raise_error(Gitable::URI::InvalidURIError)
131
+ end
132
+
133
+ it "raises with any port" do
134
+ lambda {
135
+ Gitable::ScpURI.new(:port => 88, :host => 'github.com', :path => 'path')
136
+ }.should raise_error(Gitable::URI::InvalidURIError)
137
+ end
138
+ end
99
139
  end
100
140
 
101
141
  expected = {
@@ -111,6 +151,7 @@ describe Gitable::URI do
111
151
  :local? => false,
112
152
  :ssh? => false,
113
153
  :authenticated? => false,
154
+ :to_web_uri => Addressable::URI.parse("https://host.xz/path/to/repo"),
114
155
  }
115
156
 
116
157
  describe_uri "rsync://host.xz/path/to/repo.git/" do
@@ -138,17 +179,19 @@ describe Gitable::URI do
138
179
  describe_uri "http://host.xz:8888/path/to/repo.git/" do
139
180
  it { subject.to_s.should == @uri }
140
181
  it_sets expected.merge({
141
- :scheme => "http",
142
- :port => 8888,
182
+ :scheme => "http",
183
+ :port => 8888,
184
+ :to_web_uri => Addressable::URI.parse("https://host.xz:8888/path/to/repo")
143
185
  })
144
186
  end
145
187
 
146
188
  describe_uri "http://12.34.56.78:8888/path/to/repo.git/" do
147
189
  it { subject.to_s.should == @uri }
148
190
  it_sets expected.merge({
149
- :scheme => "http",
150
- :host => "12.34.56.78",
151
- :port => 8888,
191
+ :scheme => "http",
192
+ :host => "12.34.56.78",
193
+ :port => 8888,
194
+ :to_web_uri => Addressable::URI.parse("https://12.34.56.78:8888/path/to/repo")
152
195
  })
153
196
  end
154
197
 
@@ -162,8 +205,9 @@ describe Gitable::URI do
162
205
  describe_uri "https://host.xz:8888/path/to/repo.git/" do
163
206
  it { subject.to_s.should == @uri }
164
207
  it_sets expected.merge({
165
- :scheme => "https",
166
- :port => 8888,
208
+ :scheme => "https",
209
+ :port => 8888,
210
+ :to_web_uri => Addressable::URI.parse("https://host.xz:8888/path/to/repo")
167
211
  })
168
212
  end
169
213
 
@@ -186,25 +230,28 @@ describe Gitable::URI do
186
230
  describe_uri "git://host.xz:8888/path/to/repo.git/" do
187
231
  it { subject.to_s.should == @uri }
188
232
  it_sets expected.merge({
189
- :scheme => "git",
190
- :port => 8888,
233
+ :scheme => "git",
234
+ :port => 8888,
235
+ :to_web_uri => Addressable::URI.parse("https://host.xz:8888/path/to/repo")
191
236
  })
192
237
  end
193
238
 
194
239
  describe_uri "git://host.xz/~user/path/to/repo.git/" do
195
240
  it { subject.to_s.should == @uri }
196
241
  it_sets expected.merge({
197
- :scheme => "git",
198
- :path => "/~user/path/to/repo.git/",
242
+ :scheme => "git",
243
+ :path => "/~user/path/to/repo.git/",
244
+ :to_web_uri => Addressable::URI.parse("https://host.xz/~user/path/to/repo")
199
245
  })
200
246
  end
201
247
 
202
248
  describe_uri "git://host.xz:8888/~user/path/to/repo.git/" do
203
249
  it { subject.to_s.should == @uri }
204
250
  it_sets expected.merge({
205
- :scheme => "git",
206
- :path => "/~user/path/to/repo.git/",
207
- :port => 8888,
251
+ :scheme => "git",
252
+ :path => "/~user/path/to/repo.git/",
253
+ :port => 8888,
254
+ :to_web_uri => Addressable::URI.parse("https://host.xz:8888/~user/path/to/repo")
208
255
  })
209
256
  end
210
257
 
@@ -243,6 +290,7 @@ describe Gitable::URI do
243
290
  :port => 8888,
244
291
  :ssh? => true,
245
292
  :authenticated? => true,
293
+ :to_web_uri => Addressable::URI.parse("https://host.xz:8888/path/to/repo")
246
294
  })
247
295
  end
248
296
 
@@ -264,6 +312,7 @@ describe Gitable::URI do
264
312
  :port => 8888,
265
313
  :ssh? => true,
266
314
  :authenticated? => true,
315
+ :to_web_uri => Addressable::URI.parse("https://host.xz:8888/path/to/repo")
267
316
  })
268
317
  end
269
318
 
@@ -275,6 +324,7 @@ describe Gitable::URI do
275
324
  :path => "/~user/path/to/repo.git/",
276
325
  :ssh? => true,
277
326
  :authenticated? => true,
327
+ :to_web_uri => Addressable::URI.parse("https://host.xz/~user/path/to/repo")
278
328
  })
279
329
  end
280
330
 
@@ -286,6 +336,7 @@ describe Gitable::URI do
286
336
  :path => "/~user/path/to/repo.git/",
287
337
  :ssh? => true,
288
338
  :authenticated? => true,
339
+ :to_web_uri => Addressable::URI.parse("https://host.xz/~user/path/to/repo")
289
340
  })
290
341
  end
291
342
 
@@ -296,6 +347,7 @@ describe Gitable::URI do
296
347
  :path => "/~/path/to/repo.git",
297
348
  :ssh? => true,
298
349
  :authenticated? => true,
350
+ :to_web_uri => Addressable::URI.parse("https://host.xz/~/path/to/repo")
299
351
  })
300
352
  end
301
353
 
@@ -307,6 +359,7 @@ describe Gitable::URI do
307
359
  :path => "/~/path/to/repo.git",
308
360
  :ssh? => true,
309
361
  :authenticated? => true,
362
+ :to_web_uri => Addressable::URI.parse("https://host.xz/~/path/to/repo")
310
363
  })
311
364
  end
312
365
 
@@ -314,7 +367,7 @@ describe Gitable::URI do
314
367
  it { subject.to_s.should == @uri }
315
368
  it_sets expected.merge({
316
369
  :scheme => nil,
317
- :normalized_scheme => 'ssh',
370
+ :inferred_scheme => 'ssh',
318
371
  :user => nil,
319
372
  :path => "/path/to/repo.git/",
320
373
  :ssh? => true,
@@ -326,7 +379,7 @@ describe Gitable::URI do
326
379
  it { subject.to_s.should == @uri }
327
380
  it_sets expected.merge({
328
381
  :scheme => nil,
329
- :normalized_scheme => 'ssh',
382
+ :inferred_scheme => 'ssh',
330
383
  :user => "user",
331
384
  :path => "/path/to/repo.git/",
332
385
  :ssh? => true,
@@ -338,11 +391,12 @@ describe Gitable::URI do
338
391
  it { subject.to_s.should == @uri }
339
392
  it_sets expected.merge({
340
393
  :scheme => nil,
341
- :normalized_scheme => 'ssh',
394
+ :inferred_scheme => 'ssh',
342
395
  :user => nil,
343
396
  :path => "~user/path/to/repo.git/",
344
397
  :ssh? => true,
345
398
  :authenticated? => true,
399
+ :to_web_uri => Addressable::URI.parse("https://host.xz/~user/path/to/repo")
346
400
  })
347
401
  end
348
402
 
@@ -350,11 +404,12 @@ describe Gitable::URI do
350
404
  it { subject.to_s.should == @uri }
351
405
  it_sets expected.merge({
352
406
  :scheme => nil,
353
- :normalized_scheme => 'ssh',
407
+ :inferred_scheme => 'ssh',
354
408
  :user => "user",
355
409
  :path => "~user/path/to/repo.git/",
356
410
  :ssh? => true,
357
411
  :authenticated? => true,
412
+ :to_web_uri => Addressable::URI.parse("https://host.xz/~user/path/to/repo")
358
413
  })
359
414
  end
360
415
 
@@ -362,7 +417,7 @@ describe Gitable::URI do
362
417
  it { subject.to_s.should == @uri }
363
418
  it_sets expected.merge({
364
419
  :scheme => nil,
365
- :normalized_scheme => 'ssh',
420
+ :inferred_scheme => 'ssh',
366
421
  :user => nil,
367
422
  :path => "path/to/repo.git",
368
423
  :ssh? => true,
@@ -374,7 +429,7 @@ describe Gitable::URI do
374
429
  it { subject.to_s.should == @uri }
375
430
  it_sets expected.merge({
376
431
  :scheme => nil,
377
- :normalized_scheme => 'ssh',
432
+ :inferred_scheme => "ssh",
378
433
  :user => "user",
379
434
  :path => "path/to/repo.git",
380
435
  :ssh? => true,
@@ -385,64 +440,74 @@ describe Gitable::URI do
385
440
  describe_uri "/path/to/repo.git/" do
386
441
  it { subject.to_s.should == @uri }
387
442
  it_sets expected.merge({
388
- :scheme => nil,
389
- :host => nil,
390
- :path => "/path/to/repo.git/",
391
- :local? => true,
443
+ :scheme => nil,
444
+ :inferred_scheme => "file",
445
+ :host => nil,
446
+ :path => "/path/to/repo.git/",
447
+ :local? => true,
448
+ :to_web_uri => nil,
392
449
  })
393
450
  end
394
451
 
395
452
  describe_uri "file:///path/to/repo.git/" do
396
453
  it { subject.to_s.should == @uri }
397
454
  it_sets expected.merge({
398
- :scheme => "file",
399
- :host => "", # I don't really like this but it doesn't hurt anything.
400
- :path => "/path/to/repo.git/",
401
- :local? => true,
455
+ :scheme => "file",
456
+ :inferred_scheme => "file",
457
+ :host => "",
458
+ :path => "/path/to/repo.git/",
459
+ :local? => true,
460
+ :to_web_uri => nil,
402
461
  })
403
462
  end
404
463
 
405
464
  describe_uri "ssh://git@github.com/martinemde/gitable.git" do
406
465
  it { subject.to_s.should == @uri }
407
466
  it_sets({
408
- :scheme => "ssh",
409
- :user => "git",
410
- :password => nil,
411
- :host => "github.com",
412
- :port => nil,
413
- :path => "/martinemde/gitable.git",
414
- :fragment => nil,
415
- :basename => "gitable.git",
416
- :ssh? => true,
417
- :authenticated? => true,
467
+ :scheme => "ssh",
468
+ :user => "git",
469
+ :password => nil,
470
+ :host => "github.com",
471
+ :port => nil,
472
+ :path => "/martinemde/gitable.git",
473
+ :fragment => nil,
474
+ :basename => "gitable.git",
475
+ :ssh? => true,
476
+ :authenticated? => true,
477
+ :github? => true,
478
+ :to_web_uri => Addressable::URI.parse("https://github.com/martinemde/gitable"),
418
479
  })
419
480
  end
420
481
 
421
- describe_uri "http://github.com/martinemde/gitable.git" do
482
+ describe_uri "https://github.com/martinemde/gitable.git" do
422
483
  it { subject.to_s.should == @uri }
423
484
  it_sets({
424
- :scheme => "http",
425
- :user => nil,
426
- :password => nil,
427
- :host => "github.com",
428
- :port => nil,
429
- :path => "/martinemde/gitable.git",
430
- :fragment => nil,
431
- :basename => "gitable.git",
485
+ :scheme => "https",
486
+ :user => nil,
487
+ :password => nil,
488
+ :host => "github.com",
489
+ :port => nil,
490
+ :path => "/martinemde/gitable.git",
491
+ :fragment => nil,
492
+ :basename => "gitable.git",
493
+ :github? => true,
494
+ :to_web_uri => Addressable::URI.parse("https://github.com/martinemde/gitable"),
432
495
  })
433
496
  end
434
497
 
435
498
  describe_uri "git://github.com/martinemde/gitable.git" do
436
499
  it { subject.to_s.should == @uri }
437
500
  it_sets({
438
- :scheme => "git",
439
- :user => nil,
440
- :password => nil,
441
- :host => "github.com",
442
- :port => nil,
443
- :path => "/martinemde/gitable.git",
444
- :fragment => nil,
445
- :basename => "gitable.git",
501
+ :scheme => "git",
502
+ :user => nil,
503
+ :password => nil,
504
+ :host => "github.com",
505
+ :port => nil,
506
+ :path => "/martinemde/gitable.git",
507
+ :fragment => nil,
508
+ :basename => "gitable.git",
509
+ :github? => true,
510
+ :to_web_uri => Addressable::URI.parse("https://github.com/martinemde/gitable"),
446
511
  })
447
512
  end
448
513
 
@@ -450,7 +515,7 @@ describe Gitable::URI do
450
515
  it { subject.to_s.should == @uri }
451
516
  it_sets({
452
517
  :scheme => nil,
453
- :normalized_scheme => 'ssh',
518
+ :inferred_scheme => 'ssh',
454
519
  :user => "git",
455
520
  :password => nil,
456
521
  :host => "github.com",
@@ -461,6 +526,8 @@ describe Gitable::URI do
461
526
  :project_name => "gitable",
462
527
  :ssh? => true,
463
528
  :authenticated? => true,
529
+ :github? => true,
530
+ :to_web_uri => Addressable::URI.parse("https://github.com/martinemde/gitable"),
464
531
  })
465
532
  end
466
533
  end
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
1
+ require 'spec_helper'
2
2
 
3
3
  describe Gitable::URI, ".heuristic_parse" do
4
4
  it "returns a Gitable::URI" do
@@ -20,21 +20,15 @@ describe Gitable::URI, ".heuristic_parse" do
20
20
  end
21
21
  end
22
22
 
23
- it "guesses git://github.com/martinemde/gitable.git if I pass in the url bar" do
24
- uri = "http://github.com/martinemde/gitable"
23
+ it "guesses https://github.com/martinemde/gitable.git if I pass in the url bar" do
24
+ uri = "https://github.com/martinemde/gitable"
25
25
  gitable = Gitable::URI.heuristic_parse(uri)
26
- gitable.to_s.should == "git://github.com/martinemde/gitable.git"
26
+ gitable.to_s.should == "https://github.com/martinemde/gitable.git"
27
27
  end
28
28
 
29
29
  it "isn't upset by trailing slashes" do
30
- uri = "http://github.com/martinemde/gitable/"
31
- gitable = Gitable::URI.heuristic_parse(uri)
32
- gitable.to_s.should == "git://github.com/martinemde/gitable.git/"
33
- end
34
-
35
- it "handles URIs with the name of the project in the path twice" do
36
- uri = "http://gitorious.org/project/project"
30
+ uri = "https://github.com/martinemde/gitable/"
37
31
  gitable = Gitable::URI.heuristic_parse(uri)
38
- gitable.to_s.should == "git://gitorious.org/project/project.git"
32
+ gitable.to_s.should == "https://github.com/martinemde/gitable.git/"
39
33
  end
40
34
  end
data/spec/spec_helper.rb CHANGED
@@ -1,16 +1,14 @@
1
1
  unless defined? Bundler
2
2
  require 'rubygems'
3
3
  require 'bundler'
4
- Bundler.setup
5
4
  end
6
5
 
7
6
  $LOAD_PATH.unshift(File.dirname(__FILE__))
8
7
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
9
8
  require 'gitable'
10
- require 'spec'
11
- require 'spec/autorun'
9
+ require 'rspec'
12
10
  require 'describe_uri'
13
11
 
14
- Spec::Runner.configure do |config|
12
+ RSpec.configure do |config|
15
13
  config.extend DescribeURI
16
14
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitable
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 3
10
- version: 0.1.3
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Martin Emde
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-16 00:00:00 -08:00
18
+ date: 2011-02-18 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -38,12 +38,13 @@ dependencies:
38
38
  requirement: &id002 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
- - - ">="
41
+ - - ~>
42
42
  - !ruby/object:Gem::Version
43
43
  hash: 3
44
44
  segments:
45
+ - 2
45
46
  - 0
46
- version: "0"
47
+ version: "2.0"
47
48
  type: :development
48
49
  version_requirements: *id002
49
50
  - !ruby/object:Gem::Dependency
@@ -60,6 +61,20 @@ dependencies:
60
61
  version: "0"
61
62
  type: :development
62
63
  version_requirements: *id003
64
+ - !ruby/object:Gem::Dependency
65
+ name: rcov
66
+ prerelease: false
67
+ requirement: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ type: :development
77
+ version_requirements: *id004
63
78
  description: Addressable::URI for Git URIs with special handling for scp-style URIs that Addressable doesn't like.
64
79
  email:
65
80
  - martin.emde@gmail.com
@@ -84,7 +99,6 @@ files:
84
99
  - spec/describe_uri.rb
85
100
  - spec/gitable_spec.rb
86
101
  - spec/heuristic_parse_spec.rb
87
- - spec/spec.opts
88
102
  - spec/spec_helper.rb
89
103
  has_rdoc: true
90
104
  homepage: http://github.org/martinemde/gitable
@@ -124,5 +138,4 @@ test_files:
124
138
  - spec/describe_uri.rb
125
139
  - spec/gitable_spec.rb
126
140
  - spec/heuristic_parse_spec.rb
127
- - spec/spec.opts
128
141
  - spec/spec_helper.rb
data/spec/spec.opts DELETED
@@ -1 +0,0 @@
1
- --color