earl 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,19 +1,24 @@
1
- require 'treetop'
2
1
  require 'earl/version'
3
- require 'earl/url_parser'
4
2
 
5
3
  module Earl
6
- autoload :URL, 'earl/url'
7
- autoload :UrlAssembler, 'earl/url_assembler'
8
- autoload :HashInquirer, 'earl/hash_inquirer'
4
+ autoload :EntityBase, 'earl/entity_base'
5
+ autoload :URLEntity, 'earl/url_entity'
6
+ autoload :URLAssembler, 'earl/url_assembler'
7
+ autoload :EmailEntity, 'earl/email_entity'
8
+ autoload :EmailAssembler, 'earl/email_assembler'
9
+ autoload :HashInquirer, 'earl/hash_inquirer'
9
10
  autoload :StringInquirer, 'earl/string_inquirer'
10
11
 
11
12
  class << self
12
- def parse( string )
13
- Earl::URL.new string
13
+ def URL( source )
14
+ Earl::URLEntity.new source
15
+ end
16
+ def Email( source )
17
+ Earl::EmailEntity.new source
14
18
  end
15
19
  end
16
20
 
17
- class EarlError < StandardError; end
21
+ class EarlError < StandardError; end
18
22
  class InvalidURLError < EarlError; end
23
+ class SubclassError < EarlError; end
19
24
  end
@@ -0,0 +1,11 @@
1
+ module Earl
2
+ class EmailAssembler
3
+
4
+ def assemble( parts={} )
5
+ ''.tap do |email|
6
+ email << [ parts[ :username ], parts[ :domain ] ].join( '@' )
7
+ email << " <#{parts[ :contact ]}>" if parts[ :contact ]
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,27 @@
1
+ require 'treetop'
2
+ require 'earl/email_parser'
3
+
4
+ module Earl
5
+ class EmailEntity < EntityBase
6
+
7
+ part_accessor :contact
8
+
9
+ part_accessor :username do |value|
10
+ raise InvalidURLError if value.nil?
11
+ end
12
+
13
+ part_accessor :domain do |value|
14
+ raise InvalidURLError if value.nil?
15
+ end
16
+
17
+ protected
18
+
19
+ def parser
20
+ @parser ||= EmailParser.new
21
+ end
22
+
23
+ def assembler
24
+ @assembler ||= EmailAssembler.new
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,58 @@
1
+ module Earl
2
+ grammar Email
3
+
4
+ rule program
5
+ whitespace v:( email ) whitespace {
6
+ def resolve
7
+ { }.merge v.resolve
8
+ end
9
+ }
10
+ end
11
+
12
+ rule whitespace
13
+ [\s]*
14
+ end
15
+
16
+ rule email
17
+ username '@' domain whitespace contact {
18
+ def resolve
19
+ username.resolve.merge domain.resolve.merge contact.resolve
20
+ end
21
+ }
22
+ /
23
+ username '@' domain {
24
+ def resolve
25
+ username.resolve.merge domain.resolve
26
+ end
27
+ }
28
+ end
29
+
30
+ rule username
31
+ [^@\s]+ {
32
+ def resolve
33
+ { :username => text_value }
34
+ end
35
+ }
36
+ end
37
+
38
+ rule domain
39
+ characters '.' characters {
40
+ def resolve
41
+ { :domain => text_value }
42
+ end
43
+ }
44
+ end
45
+
46
+ rule contact
47
+ '<' [^>]+ '>' {
48
+ def resolve
49
+ { :contact => elements[ 1 ].text_value }
50
+ end
51
+ }
52
+ end
53
+
54
+ rule characters
55
+ [a-zA-Z0-9]+
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,37 @@
1
+ module Earl
2
+ class EntityBase < HashInquirer
3
+ def initialize( source )
4
+ super parser.parse( source ).resolve rescue raise InvalidURLError
5
+ end
6
+
7
+ def to_s
8
+ assembler.assemble self
9
+ end
10
+
11
+ def self.part_accessor( *parts, &block )
12
+ parts.each do |part|
13
+ define_method part do
14
+ if self[ part ].is_a? String
15
+ StringInquirer.new self[ part ]
16
+ else
17
+ self[ part ]
18
+ end
19
+ end
20
+ define_method :"#{part}=" do |value|
21
+ self[ part ] = value
22
+ yield value if block_given?
23
+ end
24
+ end
25
+ end
26
+
27
+ protected
28
+
29
+ def parser
30
+ raise SubclassError
31
+ end
32
+
33
+ def assembler
34
+ raise SubclassError
35
+ end
36
+ end
37
+ end
@@ -7,7 +7,7 @@ module Earl
7
7
 
8
8
  def method_missing( meth, *args, &block )
9
9
  if meth.to_s[ -1 ] == '?'
10
- self[ meth.to_s[ 0..-2 ].to_sym ] || false
10
+ self.has_key? meth.to_s[ 0..-2 ].to_sym
11
11
  else
12
12
  super
13
13
  end
@@ -1,15 +1,14 @@
1
1
  module Earl
2
- class UrlAssembler
2
+ class URLAssembler
3
3
 
4
4
  def assemble( parts={} )
5
5
  ''.tap do |url|
6
6
  url << ( parts[ :scheme ] + '://' ) if parts[ :scheme ]
7
7
  url << ( parts[ :subdomain ] + '.' ) if parts[ :subdomain ]
8
8
  url << ( parts[ :host ] ) if parts[ :host ]
9
- url << ( ':' + parts[ :port ] ) if parts[ :port ]
9
+ url << ( ':' + parts[ :port ].to_s ) if parts[ :port ]
10
10
  url << ( '/' + parts[ :path ] ) if parts[ :path ]
11
11
  url << ( '?' + parts[ :search ] ) if parts[ :search ]
12
- url
13
12
  end
14
13
  end
15
14
  end
@@ -0,0 +1,23 @@
1
+ require 'treetop'
2
+ require 'earl/url_parser'
3
+
4
+ module Earl
5
+ class URLEntity < EntityBase
6
+
7
+ part_accessor :scheme, :subdomain, :port, :path, :search
8
+
9
+ part_accessor :host do |value|
10
+ raise InvalidURLError if value.nil?
11
+ end
12
+
13
+ protected
14
+
15
+ def parser
16
+ @parser ||= URLParser.new
17
+ end
18
+
19
+ def assembler
20
+ @assembler ||= URLAssembler.new
21
+ end
22
+ end
23
+ end
@@ -1,5 +1,5 @@
1
1
  module Earl
2
- grammar Url
2
+ grammar URL
3
3
 
4
4
  rule program
5
5
  whitespace v:( url ) whitespace {
@@ -1,3 +1,3 @@
1
1
  module Earl
2
- VERSION = "0.2.0"
2
+ VERSION = '0.3.0'
3
3
  end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe Earl do
4
+ subject { Earl }
5
+
6
+ it { should respond_to( :URL ) }
7
+ describe '#URL' do
8
+ subject { Earl::URL( 'http://foo.com' ) }
9
+ it { should be_kind_of( Earl::URLEntity ) }
10
+ end
11
+
12
+ it { should respond_to( :Email ) }
13
+ describe '#Email' do
14
+ subject { Earl::Email( 'foo@bar.com' ) }
15
+ it { should be_kind_of( Earl::EmailEntity ) }
16
+ end
17
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe Earl::EmailEntity do
4
+ subject { Earl::EmailEntity }
5
+
6
+ # username
7
+
8
+ it { should produce( 'foo@bar.com' ).from( 'baz@bar.com' ).when_given( :username => 'foo' ) }
9
+ it 'must have a username when parsing an email' do
10
+ expect { Earl::Email( '@bar.com' ) }.to raise_error( Earl::InvalidURLError )
11
+ end
12
+ it 'wont let you set the username to nil' do
13
+ expect { Earl::Email( 'foo@bar.com' ).username = nil }.to raise_error( Earl::InvalidURLError )
14
+ end
15
+
16
+ # domain
17
+
18
+ it { should produce( 'foo@bar.com' ).from( 'foo@baz.com' ).when_given( :domain => 'bar.com' ) }
19
+ it 'must have a domain when parsing an email' do
20
+ expect { Earl::Email( 'foo@' ) }.to raise_error( Earl::InvalidURLError )
21
+ end
22
+ it 'wont let you set the domain to nil' do
23
+ expect { Earl::Email( 'foo@bar.com' ).domain = nil }.to raise_error( Earl::InvalidURLError )
24
+ end
25
+
26
+ # contact
27
+
28
+ it { should produce( 'foo@bar.com <Woot!>' ).from( 'foo@bar.com <Foo Bar>' ).when_given( :contact => 'Woot!' ) }
29
+ it { should produce( 'foo@bar.com <Woot!>' ).from( 'foo@bar.com' ).when_given( :contact => 'Woot!' ) }
30
+ it { should produce( 'foo@bar.com' ).from( 'foo@bar.com <Woot!>' ).when_given( :contact => nil ) }
31
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe Earl do
4
+ let( :parser ){ Earl::EmailParser.new }
5
+ let( :assembler ){ Earl::EmailAssembler.new }
6
+
7
+ [
8
+ [ 'foo@bar.com', {
9
+ :username => 'foo',
10
+ :domain => 'bar.com'
11
+ } ],
12
+ [ 'foo.bar@baz.com', {
13
+ :username => 'foo.bar',
14
+ :domain => 'baz.com'
15
+ } ],
16
+ [ 'foo.bar@baz.com <Foo Bar>', {
17
+ :username => 'foo.bar',
18
+ :domain => 'baz.com',
19
+ :contact => 'Foo Bar'
20
+ } ]
21
+ ].each do |string, parts|
22
+ it "should correctly parse the email parts for #{string}" do
23
+ parser.parse( string ).resolve.should eql( parts )
24
+ end
25
+ it "should correctly assemble the email parts to #{string}" do
26
+ assembler.assemble( parts ).should eql( string )
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe Earl::EntityBase do
4
+
5
+ describe 'the entity dsl' do
6
+ subject { Class.new( Earl::EntityBase ) do
7
+ def initialize; end # so we don't invoke our parser
8
+
9
+ part_accessor :foo, :bar
10
+
11
+ part_accessor :baz do |value|
12
+ raise EarlError if value == 'woot!'
13
+ end
14
+ end.new }
15
+
16
+ it { should be_kind_of( Earl::HashInquirer ) }
17
+
18
+ [ :foo, :foo=, :bar, :bar=, :baz, :baz= ].each do |method|
19
+ it { should respond_to( method ) }
20
+ end
21
+
22
+ it 'should define setters/getters' do
23
+ subject.foo = 'foo!'
24
+ subject.foo.should eq( 'foo!' )
25
+ subject[ :foo ].should eq( 'foo!' )
26
+ subject.foo?.should eq( true )
27
+ end
28
+
29
+ it 'should call the block if given' do
30
+ expect { subject.baz = 'baz!' }.not_to raise_error
31
+ expect { subject.baz = 'woot!' }.to raise_error
32
+ end
33
+
34
+ it 'should return a string inquirer for string attributes' do
35
+ subject.foo = 'sup'
36
+ subject.foo.kind_of?( Earl::StringInquirer ).should == true
37
+ end
38
+ end
39
+ end
@@ -15,7 +15,7 @@ describe Earl::HashInquirer do
15
15
  end
16
16
 
17
17
  describe 'boolean keys' do
18
- its( :woo? ){ should be_false }
18
+ its( :woo? ){ should be_true }
19
19
  end
20
20
 
21
21
  describe 'nonexistant keys' do
@@ -7,11 +7,3 @@ describe Earl::StringInquirer do
7
7
  its( :foo? ){ should be_true }
8
8
  its( :bar? ){ should be_false }
9
9
  end
10
-
11
- describe Earl::URL do
12
- subject { Earl::URL.new 'http://www.foo.com' }
13
-
14
- its( :scheme ){ should be_a( Earl::StringInquirer ) }
15
- its( :subdomain ){ should be_a( Earl::StringInquirer ) }
16
- its( :host ){ should be_a( Earl::StringInquirer ) }
17
- end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe Earl::URLEntity do
4
+ subject { Earl::URLEntity }
5
+
6
+ # scheme
7
+
8
+ it { should produce( 'https://foo.com' ).from( 'http://foo.com' ).when_given( :scheme => 'https' ) }
9
+ it { should produce( 'http://foo.com' ).from( 'foo.com' ).when_given( :scheme => 'http' ) }
10
+ it { should produce( 'foo.com' ).from( 'http://foo.com' ).when_given( :scheme => nil ) }
11
+
12
+ # subdomain
13
+
14
+ it { should produce( 'baz.bar.com' ).from( 'foo.bar.com' ).when_given( :subdomain => 'baz' ) }
15
+ it { should produce( 'bar.foo.com' ).from( 'foo.com' ).when_given( :subdomain => 'bar' ) }
16
+ it { should produce( 'bar.com' ).from( 'foo.bar.com' ).when_given( :subdomain => nil ) }
17
+
18
+ # port
19
+
20
+ it { should produce( 'foo.com:4567' ).from( 'foo.com:80' ).when_given( :port => 4567 ) }
21
+ it { should produce( 'foo.com:4567' ).from( 'foo.com' ).when_given( :port => 4567 ) }
22
+ it { should produce( 'foo.com' ).from( 'foo.com:4567' ).when_given( :port => nil ) }
23
+
24
+ # path
25
+
26
+ it { should produce( 'foo.com/bar' ).from( 'foo.com/baz' ).when_given( :path => 'bar' ) }
27
+ it { should produce( 'foo.com/bar' ).from( 'foo.com' ).when_given( :path => 'bar' ) }
28
+ it { should produce( 'foo.com' ).from( 'foo.com/bar' ).when_given( :path => nil ) }
29
+
30
+ # search
31
+
32
+ it { should produce( 'foo.com?bar=asdf' ).from( 'foo.com?bar=baz' ).when_given( :search => 'bar=asdf' ) }
33
+ it { should produce( 'foo.com?bar=asdf' ).from( 'foo.com' ).when_given( :search => 'bar=asdf' ) }
34
+ it { should produce( 'foo.com' ).from( 'foo.com?bar=asdf' ).when_given( :search => nil ) }
35
+
36
+ # host
37
+
38
+ it { should produce( 'www.foo.edu' ).from( 'www.foo.com' ).when_given( :host => 'foo.edu' ) }
39
+ it 'must have a host when parsing a url' do
40
+ expect { Earl::URL( 'http://' ) }.to raise_error( Earl::InvalidURLError )
41
+ end
42
+ it 'wont let you set the host to nil' do
43
+ expect { Earl::URL( 'www.foo.com' ).host = nil }.to raise_error( Earl::InvalidURLError )
44
+ end
45
+ end
@@ -1,8 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Earl do
4
- let( :parser ){ Earl::UrlParser.new }
5
- let( :assembler ){ Earl::UrlAssembler.new }
4
+ let( :parser ){ Earl::URLParser.new }
5
+ let( :assembler ){ Earl::URLAssembler.new }
6
6
 
7
7
  [
8
8
  [ 'localhost', {
@@ -7,3 +7,28 @@ RSpec.configure do |config|
7
7
  # Change the formatter
8
8
  config.formatter = :documentation
9
9
  end
10
+
11
+ # Custom entity manipulation matcher
12
+ RSpec::Matchers.define :produce do |expected|
13
+
14
+ match do |entity_class|
15
+ entity = entity_class.new @start
16
+ @changes.each do |key, value|
17
+ entity.send :"#{key}=", value
18
+ end
19
+ @actual = entity.to_s
20
+ @actual == expected
21
+ end
22
+
23
+ failure_message_for_should do |entity|
24
+ %Q{expected that "#{@start}" would become "#{expected}" when given #{@changes}, but was "#{@actual}"}
25
+ end
26
+
27
+ chain :from do |start|
28
+ @start = start
29
+ end
30
+
31
+ chain :when_given do |changes|
32
+ @changes = changes
33
+ end
34
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: earl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-16 00:00:00.000000000 Z
12
+ date: 2012-04-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: treetop
16
- requirement: &705960 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: 1.4.10
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *705960
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.4.10
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: rspec
27
- requirement: &705680 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,7 +37,12 @@ dependencies:
32
37
  version: 2.9.0
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *705680
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 2.9.0
36
46
  description: What URI wishes it could look like
37
47
  email:
38
48
  - jeremy.ruppel@gmail.com
@@ -48,18 +58,24 @@ files:
48
58
  - Rakefile
49
59
  - earl.gemspec
50
60
  - lib/earl.rb
61
+ - lib/earl/email_assembler.rb
62
+ - lib/earl/email_entity.rb
63
+ - lib/earl/email_parser.tt
64
+ - lib/earl/entity_base.rb
51
65
  - lib/earl/hash_inquirer.rb
52
66
  - lib/earl/string_inquirer.rb
53
- - lib/earl/url.rb
54
67
  - lib/earl/url_assembler.rb
68
+ - lib/earl/url_entity.rb
55
69
  - lib/earl/url_parser.tt
56
70
  - lib/earl/version.rb
71
+ - spec/earl/earl_spec.rb
72
+ - spec/earl/email_entity_spec.rb
73
+ - spec/earl/email_parser_spec.rb
74
+ - spec/earl/entity_base_spec.rb
57
75
  - spec/earl/hash_inquirer_spec.rb
58
- - spec/earl/parse_spec.rb
59
- - spec/earl/parts_spec.rb
60
76
  - spec/earl/string_inquirer_spec.rb
77
+ - spec/earl/url_entity_spec.rb
61
78
  - spec/earl/url_parser_spec.rb
62
- - spec/earl/url_spec.rb
63
79
  - spec/spec_helper.rb
64
80
  homepage: https://github.com/remind101/earl
65
81
  licenses: []
@@ -81,15 +97,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
97
  version: '0'
82
98
  requirements: []
83
99
  rubyforge_project:
84
- rubygems_version: 1.8.15
100
+ rubygems_version: 1.8.19
85
101
  signing_key:
86
102
  specification_version: 3
87
103
  summary: What URI wishes it could look like
88
104
  test_files:
105
+ - spec/earl/earl_spec.rb
106
+ - spec/earl/email_entity_spec.rb
107
+ - spec/earl/email_parser_spec.rb
108
+ - spec/earl/entity_base_spec.rb
89
109
  - spec/earl/hash_inquirer_spec.rb
90
- - spec/earl/parse_spec.rb
91
- - spec/earl/parts_spec.rb
92
110
  - spec/earl/string_inquirer_spec.rb
111
+ - spec/earl/url_entity_spec.rb
93
112
  - spec/earl/url_parser_spec.rb
94
- - spec/earl/url_spec.rb
95
113
  - spec/spec_helper.rb
@@ -1,35 +0,0 @@
1
- module Earl
2
- class URL < HashInquirer
3
- def initialize( source )
4
- super parser.parse( source ).resolve rescue raise InvalidURLError
5
- end
6
-
7
- %w| scheme subdomain host port path search |.each do |part|
8
- define_method :"#{part}" do
9
- if self[ part.to_sym ].is_a? String
10
- StringInquirer.new self[ part.to_sym ]
11
- else
12
- self[ part.to_sym ]
13
- end
14
- end
15
- define_method :"#{part}=" do |value|
16
- raise InvalidURLError if part.to_sym == :host && value == nil
17
- self[ part.to_sym ] = value
18
- end
19
- end
20
-
21
- def to_s
22
- assembler.assemble self
23
- end
24
-
25
- protected
26
-
27
- def parser
28
- @parser ||= UrlParser.new
29
- end
30
-
31
- def assembler
32
- @assembler ||= UrlAssembler.new
33
- end
34
- end
35
- end
@@ -1,10 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Earl do
4
-
5
- describe '#parse' do
6
- it 'should return an Earl::URL' do
7
- Earl.parse( 'www.foo.com' ).should be_an( Earl::URL )
8
- end
9
- end
10
- end
@@ -1,90 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Earl::URL do
4
-
5
- describe '#scheme' do
6
- context 'when provided' do
7
- subject { Earl::URL.new 'http://www.foo.com' }
8
- its( :scheme ){ should eq( 'http' ) }
9
- its( :scheme? ){ should be_true }
10
-
11
- it 'should be settable' do
12
- subject.scheme = 'https'
13
- subject.scheme.should eq( 'https' )
14
- end
15
- end
16
-
17
- context 'when not provided' do
18
- subject { Earl::URL.new 'www.foo.com' }
19
- its( :scheme ){ should eq( nil ) }
20
- its( :scheme? ){ should be_false }
21
-
22
- it 'should be settable' do
23
- subject.scheme = 'https'
24
- subject.scheme.should eq( 'https' )
25
- end
26
- end
27
- end
28
-
29
- describe '#domain' do
30
- pending
31
- end
32
-
33
- describe '#subdomain' do
34
- context 'when provided' do
35
- subject { Earl::URL.new 'http://www.foo.com' }
36
- its( :subdomain ){ should eq( 'www' ) }
37
- its( :subdomain? ){ should be_true }
38
-
39
- it 'should be settable' do
40
- subject.subdomain = 'secure'
41
- subject.subdomain.should eq( 'secure' )
42
- end
43
- end
44
-
45
- context 'when not provided' do
46
- subject { Earl::URL.new 'foo.com' }
47
- its( :subdomain ){ should eq( nil ) }
48
- its( :subdomain? ){ should be_false }
49
-
50
- it 'should be settable' do
51
- subject.subdomain = 'secure'
52
- subject.subdomain.should eq( 'secure' )
53
- end
54
- end
55
- end
56
-
57
- describe '#host' do
58
- context 'when provided' do
59
- subject { Earl::URL.new 'http://www.foo.com' }
60
- its( :host ){ should eq( 'foo.com' ) }
61
- its( :host? ){ should be_true }
62
-
63
- it 'should be settable' do
64
- subject.host = 'bar.com'
65
- subject.host.should eq( 'bar.com' )
66
- end
67
- end
68
-
69
- context 'when not provided' do
70
- it 'should raise an error' do
71
- expect { Earl::URL.new( 'http://' ).host }.to raise_error( Earl::InvalidURLError )
72
- end
73
- end
74
- end
75
-
76
- describe '#path' do
77
- context 'when provided' do
78
- subject { Earl::URL.new 'http://www.foo.com/bar' }
79
- its( :path ){ should eq( 'bar' ) }
80
- its( :path? ){ should be_true }
81
- end
82
-
83
- context 'when not provided' do
84
- subject { Earl::URL.new 'http://www.foo.com' }
85
-
86
- its( :path ){ should eq( nil ) }
87
- its( :path? ){ should be_false }
88
- end
89
- end
90
- end
@@ -1,49 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Earl::URL do
4
-
5
- it 'should be able to change the scheme' do
6
- url = Earl::URL.new 'http://foo.com'
7
- url.scheme = 'https'
8
- url.to_s.should eq( 'https://foo.com' )
9
- end
10
- it 'should be able to add a scheme' do
11
- url = Earl::URL.new 'foo.com'
12
- url.scheme = 'http'
13
- url.to_s.should eq( 'http://foo.com' )
14
- end
15
- it 'should be able to remove the scheme' do
16
- url = Earl::URL.new 'http://foo.com'
17
- url.scheme = nil
18
- url.to_s.should eq( 'foo.com' )
19
- end
20
-
21
- it 'should be able to change the subdomain' do
22
- url = Earl::URL.new 'foo.bar.com'
23
- url.subdomain = 'baz'
24
- url.to_s.should eq( 'baz.bar.com' )
25
- end
26
- it 'should be able to add a subdomain' do
27
- url = Earl::URL.new 'foo.com'
28
- url.subdomain = 'bar'
29
- url.to_s.should eq( 'bar.foo.com' )
30
- end
31
- it 'should be able to remove the subdomain' do
32
- url = Earl::URL.new 'foo.bar.com'
33
- url.subdomain = nil
34
- url.to_s.should eq( 'bar.com' )
35
- end
36
-
37
- it 'should be able to change the host' do
38
- url = Earl::URL.new 'www.foo.com'
39
- url.host = 'foo.edu'
40
- url.to_s.should eq( 'www.foo.edu' )
41
- end
42
- it 'should not be able to add a host' do
43
- expect { url = Earl::URL.new 'http://' }.to raise_error( Earl::InvalidURLError )
44
- end
45
- it 'should not be able to remove a host' do
46
- url = Earl::URL.new 'http://foo.com'
47
- expect { url.host = nil }.to raise_error( Earl::InvalidURLError )
48
- end
49
- end