hosts 0.1.0
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.
- data.tar.gz.sig +0 -0
- data/.gitignore +12 -0
- data/.rspec +1 -0
- data/.travis.yml +8 -0
- data/.yardopts +5 -0
- data/Gemfile +23 -0
- data/HISTORY.md +6 -0
- data/LICENSE.md +15 -0
- data/README.md +347 -0
- data/Rakefile +48 -0
- data/hosts.gemspec +57 -0
- data/lib/aef/hosts.rb +51 -0
- data/lib/aef/hosts/comment.rb +73 -0
- data/lib/aef/hosts/element.rb +108 -0
- data/lib/aef/hosts/empty_element.rb +50 -0
- data/lib/aef/hosts/entry.rb +123 -0
- data/lib/aef/hosts/file.rb +252 -0
- data/lib/aef/hosts/helpers.rb +121 -0
- data/lib/aef/hosts/section.rb +141 -0
- data/lib/aef/hosts/version.rb +29 -0
- data/lib/hosts.rb +25 -0
- data/lib/hosts/bare.rb +23 -0
- data/spec/aef/hosts/comment_spec.rb +136 -0
- data/spec/aef/hosts/element_spec.rb +12 -0
- data/spec/aef/hosts/empty_element_spec.rb +96 -0
- data/spec/aef/hosts/entry_spec.rb +252 -0
- data/spec/aef/hosts/file_spec.rb +290 -0
- data/spec/aef/hosts/helpers_spec.rb +103 -0
- data/spec/aef/hosts/section_spec.rb +299 -0
- data/spec/fixtures/linux_hosts +21 -0
- data/spec/fixtures/windows_hosts +14 -0
- data/spec/integration/integration_spec.rb +384 -0
- data/spec/spec_helper.rb +47 -0
- metadata +202 -0
- metadata.gz.sig +4 -0
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
=begin
|
3
|
+
Copyright Alexander E. Fischer <aef@raxys.net>, 2012
|
4
|
+
|
5
|
+
This file is part of Hosts.
|
6
|
+
|
7
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
8
|
+
purpose with or without fee is hereby granted, provided that the above
|
9
|
+
copyright notice and this permission notice appear in all copies.
|
10
|
+
|
11
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
12
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
13
|
+
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
14
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
15
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
16
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
17
|
+
PERFORMANCE OF THIS SOFTWARE.
|
18
|
+
=end
|
19
|
+
|
20
|
+
module Aef
|
21
|
+
module Hosts
|
22
|
+
|
23
|
+
# The currently loaded library version
|
24
|
+
#
|
25
|
+
# Using Semantic Versioning (2.0.0-rc.1) rules
|
26
|
+
# @see http://semver.org/
|
27
|
+
VERSION = '0.1.0'.freeze
|
28
|
+
end
|
29
|
+
end
|
data/lib/hosts.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
=begin
|
3
|
+
Copyright Alexander E. Fischer <aef@raxys.net>, 2012
|
4
|
+
|
5
|
+
This file is part of Hosts.
|
6
|
+
|
7
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
8
|
+
purpose with or without fee is hereby granted, provided that the above
|
9
|
+
copyright notice and this permission notice appear in all copies.
|
10
|
+
|
11
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
12
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
13
|
+
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
14
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
15
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
16
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
17
|
+
PERFORMANCE OF THIS SOFTWARE.
|
18
|
+
=end
|
19
|
+
|
20
|
+
# Helper file to allow loading by gem name. Creates an alias for Aef::Hosts
|
21
|
+
# named simply Hosts if this name isn't used otherwise.
|
22
|
+
|
23
|
+
require 'aef/hosts'
|
24
|
+
|
25
|
+
::Hosts = Aef::Hosts unless defined?(::Hosts)
|
data/lib/hosts/bare.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
=begin
|
3
|
+
Copyright Alexander E. Fischer <aef@raxys.net>, 2012
|
4
|
+
|
5
|
+
This file is part of Hosts.
|
6
|
+
|
7
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
8
|
+
purpose with or without fee is hereby granted, provided that the above
|
9
|
+
copyright notice and this permission notice appear in all copies.
|
10
|
+
|
11
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
12
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
13
|
+
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
14
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
15
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
16
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
17
|
+
PERFORMANCE OF THIS SOFTWARE.
|
18
|
+
=end
|
19
|
+
|
20
|
+
# Require this file if you don't want an alias for Aef::Hosts named simply
|
21
|
+
# Hosts.
|
22
|
+
|
23
|
+
require 'aef/hosts'
|
@@ -0,0 +1,136 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
=begin
|
3
|
+
Copyright Alexander E. Fischer <aef@raxys.net>, 2012
|
4
|
+
|
5
|
+
This file is part of Hosts.
|
6
|
+
|
7
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
8
|
+
purpose with or without fee is hereby granted, provided that the above
|
9
|
+
copyright notice and this permission notice appear in all copies.
|
10
|
+
|
11
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
12
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
13
|
+
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
14
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
15
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
16
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
17
|
+
PERFORMANCE OF THIS SOFTWARE.
|
18
|
+
=end
|
19
|
+
|
20
|
+
require 'spec_helper'
|
21
|
+
|
22
|
+
describe Aef::Hosts::Comment do
|
23
|
+
let(:element) { described_class.new('some comment') }
|
24
|
+
|
25
|
+
describe "comment attribute" do
|
26
|
+
it "should exist" do
|
27
|
+
element.should respond_to(:comment)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should be settable" do
|
31
|
+
element.should respond_to(:comment=)
|
32
|
+
|
33
|
+
element.comment = 'my comment'
|
34
|
+
|
35
|
+
element.comment.should == 'my comment'
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should be settable through the constructor" do
|
39
|
+
element = Aef::Hosts::Comment.new('my comment')
|
40
|
+
|
41
|
+
element.comment.should == 'my comment'
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should be a mandatory argument of the constructor" do
|
45
|
+
expect {
|
46
|
+
element = Aef::Hosts::Comment.new(nil)
|
47
|
+
}.to raise_error(ArgumentError)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should invalidate the cache if modified" do
|
51
|
+
element = Aef::Hosts::Comment.new('some comment', :cache => ' #some comment')
|
52
|
+
|
53
|
+
expect {
|
54
|
+
element.comment = 'my comment'
|
55
|
+
}.to change{ element.cache_filled? }.from(true).to(false)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "cache attribute" do
|
60
|
+
it "should exist" do
|
61
|
+
element.should respond_to(:cache)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should be nil by default" do
|
65
|
+
element.cache.should be_nil
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should not be allowed to be set" do
|
69
|
+
element.should_not respond_to(:cache=)
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should be settable through the constructor" do
|
73
|
+
element = Aef::Hosts::Comment.new('some comment', :cache => " #some comment\n")
|
74
|
+
|
75
|
+
element.cache.should == " #some comment\n"
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should be correctly reported as empty by cache_filled?" do
|
79
|
+
element.should respond_to(:cache_filled?)
|
80
|
+
|
81
|
+
element.cache_filled?.should be_false
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should be correctly reported as filled by cache_filled?" do
|
85
|
+
element = Aef::Hosts::Comment.new('some comment', :cache => " #some comment\n")
|
86
|
+
|
87
|
+
element.should respond_to(:cache_filled?)
|
88
|
+
|
89
|
+
element.cache_filled?.should be_true
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should be invalidatable" do
|
93
|
+
element = Aef::Hosts::Entry.new('some comment', :cache => " #some comment\n")
|
94
|
+
|
95
|
+
element.invalidate_cache!
|
96
|
+
|
97
|
+
element.cache.should be_nil
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
context "#inspect" do
|
102
|
+
it "should be able to generate a debugging String" do
|
103
|
+
element.inspect.should eql %{#<Aef::Hosts::Comment: comment="some comment">}
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should be able to generate a debugging String with cache" do
|
107
|
+
element = Aef::Hosts::Comment.new('some comment', :cache => 'abc')
|
108
|
+
element.inspect.should eql %{#<Aef::Hosts::Comment: comment="some comment" cached!>}
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe "string generation" do
|
113
|
+
it "should generate a new representation if no cache is available" do
|
114
|
+
element = Aef::Hosts::Comment.new('some comment')
|
115
|
+
|
116
|
+
element.to_s.should == "#some comment\n"
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should respond with a duplicate of the cached representation if cache is filled" do
|
120
|
+
element = Aef::Hosts::Comment.new('some comment',
|
121
|
+
:cache => "\t\t\t#some comment\n"
|
122
|
+
)
|
123
|
+
|
124
|
+
element.to_s.should == "\t\t\t#some comment\n"
|
125
|
+
element.to_s.should_not equal(element.cache) # Should not be identical
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should ignore cache and generate a new representation if generation is explicitly forced" do
|
129
|
+
element = Aef::Hosts::Comment.new('some comment',
|
130
|
+
:cache => "\t\t\t#some comment\n"
|
131
|
+
)
|
132
|
+
|
133
|
+
element.to_s(:force_generation => true).should == "#some comment\n"
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Aef::Hosts::Element do
|
4
|
+
let(:element_subclass) { Class.new(Aef::Hosts::Element) }
|
5
|
+
let(:element) { element_subclass.new }
|
6
|
+
|
7
|
+
it "should complain about unimplemented #generate_string method" do
|
8
|
+
expect {
|
9
|
+
element.to_s
|
10
|
+
}.to raise_error(NotImplementedError)
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
=begin
|
3
|
+
Copyright Alexander E. Fischer <aef@raxys.net>, 2012
|
4
|
+
|
5
|
+
This file is part of Hosts.
|
6
|
+
|
7
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
8
|
+
purpose with or without fee is hereby granted, provided that the above
|
9
|
+
copyright notice and this permission notice appear in all copies.
|
10
|
+
|
11
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
12
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
13
|
+
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
14
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
15
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
16
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
17
|
+
PERFORMANCE OF THIS SOFTWARE.
|
18
|
+
=end
|
19
|
+
|
20
|
+
require 'spec_helper'
|
21
|
+
|
22
|
+
describe Aef::Hosts::EmptyElement do
|
23
|
+
let(:element) { described_class.new }
|
24
|
+
|
25
|
+
describe "cache attribute" do
|
26
|
+
it "should exist" do
|
27
|
+
element.should respond_to(:cache)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should be nil by default" do
|
31
|
+
element.cache.should be_nil
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should not be allowed to be set" do
|
35
|
+
element.should_not respond_to(:cache=)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should be settable through the constructor" do
|
39
|
+
element = Aef::Hosts::EmptyElement.new(:cache => " \n")
|
40
|
+
|
41
|
+
element.cache.should == " \n"
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should be correctly reported as empty by cache_filled?" do
|
45
|
+
element.should respond_to(:cache_filled?)
|
46
|
+
|
47
|
+
element.cache_filled?.should be_false
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should be correctly reported as filled by cached_filled?" do
|
51
|
+
element = Aef::Hosts::EmptyElement.new(:cache => " \n")
|
52
|
+
|
53
|
+
element.should respond_to(:cache_filled?)
|
54
|
+
|
55
|
+
element.cache_filled?.should be_true
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should be invalidatable" do
|
59
|
+
element = Aef::Hosts::EmptyElement.new(:cache => " \n")
|
60
|
+
|
61
|
+
element.invalidate_cache!
|
62
|
+
|
63
|
+
element.cache.should be_nil
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context "#inspect" do
|
68
|
+
it "should be able to generate a debugging String" do
|
69
|
+
element.inspect.should eql %{#<Aef::Hosts::EmptyElement>}
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should be able to generate a debugging String with cache filled" do
|
73
|
+
element = Aef::Hosts::EmptyElement.new(:cache => " \n")
|
74
|
+
element.inspect.should eql %{#<Aef::Hosts::EmptyElement: cached!>}
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "string generation" do
|
79
|
+
it "should generate new output if no cache is available" do
|
80
|
+
element.to_s.should == "\n"
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should respond with a duplicate of the cached content if cache is filled" do
|
84
|
+
element = Aef::Hosts::EmptyElement.new(:cache => " \n")
|
85
|
+
|
86
|
+
element.to_s.should == " \n"
|
87
|
+
element.to_s.should_not equal(element.cache) # Should not be identical
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should ignore cache and generate new representation if generation is explicitly forced" do
|
91
|
+
element = Aef::Hosts::EmptyElement.new(:cache => " \n")
|
92
|
+
|
93
|
+
element.to_s(:force_generation => true).should == "\n"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,252 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
=begin
|
3
|
+
Copyright Alexander E. Fischer <aef@raxys.net>, 2012
|
4
|
+
|
5
|
+
This file is part of Hosts.
|
6
|
+
|
7
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
8
|
+
purpose with or without fee is hereby granted, provided that the above
|
9
|
+
copyright notice and this permission notice appear in all copies.
|
10
|
+
|
11
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
12
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
13
|
+
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
14
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
15
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
16
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
17
|
+
PERFORMANCE OF THIS SOFTWARE.
|
18
|
+
=end
|
19
|
+
|
20
|
+
require 'spec_helper'
|
21
|
+
|
22
|
+
describe Aef::Hosts::Entry do
|
23
|
+
let(:element) { described_class.new('192.168.0.1', 'somehost') }
|
24
|
+
|
25
|
+
describe "address attribute" do
|
26
|
+
it "should exist" do
|
27
|
+
element.should respond_to(:address)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should be settable" do
|
31
|
+
element.should respond_to(:address=)
|
32
|
+
|
33
|
+
element.address = '127.0.0.1'
|
34
|
+
|
35
|
+
element.address.should == '127.0.0.1'
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should be settable through the constructor" do
|
39
|
+
element = Aef::Hosts::Entry.new('127.0.0.1', 'localhost')
|
40
|
+
|
41
|
+
element.address.should == '127.0.0.1'
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should be a mandatory argument of the constructor" do
|
45
|
+
expect {
|
46
|
+
element = Aef::Hosts::Entry.new(nil, 'localhost')
|
47
|
+
}.to raise_error(ArgumentError)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should invalidate cache if modified" do
|
51
|
+
element = Aef::Hosts::Entry.new('192.168.0.1', 'somehost', :cache => ' 192.168.0.1 somehost')
|
52
|
+
|
53
|
+
expect {
|
54
|
+
element.address = '127.0.0.1'
|
55
|
+
}.to change{ element.cache_filled? }.from(true).to(false)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "name attribute" do
|
60
|
+
it "should exist" do
|
61
|
+
element.should respond_to(:name)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should be settable" do
|
65
|
+
element.should respond_to(:name=)
|
66
|
+
|
67
|
+
element.name = 'localhost'
|
68
|
+
|
69
|
+
element.name.should == 'localhost'
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should be settable through the constructor" do
|
73
|
+
element = Aef::Hosts::Entry.new('127.0.0.1', 'localhost')
|
74
|
+
|
75
|
+
element.name.should == 'localhost'
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should be a mandatory argument of the constructor" do
|
79
|
+
expect {
|
80
|
+
element = Aef::Hosts::Entry.new('127.0.0.1', nil)
|
81
|
+
}.to raise_error(ArgumentError)
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should invalidate cache if modified" do
|
85
|
+
element = Aef::Hosts::Entry.new('192.168.0.1', 'somehost', :cache => ' 192.168.0.1 somehost')
|
86
|
+
|
87
|
+
expect {
|
88
|
+
element.name = 'localhost'
|
89
|
+
}.to change{ element.cache_filled? }.from(true).to(false)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe "comment attribute" do
|
94
|
+
it "should exist" do
|
95
|
+
element.should respond_to(:comment)
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should be nil by default" do
|
99
|
+
element.comment.should be_nil
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should be settable" do
|
103
|
+
element.should respond_to(:comment=)
|
104
|
+
|
105
|
+
element.comment = 'my comment'
|
106
|
+
|
107
|
+
element.comment.should == 'my comment'
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should be settable through the constructor" do
|
111
|
+
element = Aef::Hosts::Entry.new('127.0.0.1', 'localhost', :comment => 'my comment')
|
112
|
+
|
113
|
+
element.comment.should == 'my comment'
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should invalidate cache if modified" do
|
117
|
+
element = Aef::Hosts::Entry.new('127.0.0.1', 'localhost', :cache => ' 127.0.0.1 localhost')
|
118
|
+
|
119
|
+
expect {
|
120
|
+
element.comment = 'my comment'
|
121
|
+
}.to change{ element.cache_filled? }.from(true).to(false)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
describe "aliases attribute" do
|
126
|
+
it "should exist" do
|
127
|
+
element.should respond_to(:aliases)
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should be an empty array by default" do
|
131
|
+
element.aliases.should == []
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should be settable" do
|
135
|
+
element.should respond_to(:aliases=)
|
136
|
+
|
137
|
+
element.aliases = ['alias1', 'alias2']
|
138
|
+
|
139
|
+
element.aliases.should == ['alias1', 'alias2']
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should be settable through the constructor" do
|
143
|
+
element = Aef::Hosts::Entry.new('127.0.0.1', 'localhost', :aliases => ['alias1', 'alias2'])
|
144
|
+
|
145
|
+
element.aliases.should == ['alias1', 'alias2']
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should invalidate cache if modified" do
|
149
|
+
element = Aef::Hosts::Entry.new('192.168.0.1', 'somehost', :cache => ' 192.168.0.1 somehost')
|
150
|
+
|
151
|
+
expect {
|
152
|
+
element.aliases = ['alias1', 'alias2']
|
153
|
+
}.to change{ element.cache_filled? }.from(true).to(false)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
describe "cache attribute" do
|
158
|
+
it "should exist" do
|
159
|
+
element.should respond_to(:cache)
|
160
|
+
end
|
161
|
+
|
162
|
+
it "should be nil by default" do
|
163
|
+
element.cache.should be_nil
|
164
|
+
end
|
165
|
+
|
166
|
+
it "should not be allowed to be set" do
|
167
|
+
element.should_not respond_to(:cache=)
|
168
|
+
end
|
169
|
+
|
170
|
+
it "should be settable through the constructor" do
|
171
|
+
element = Aef::Hosts::Entry.new('127.0.0.1', 'localhost', :cache => " \n")
|
172
|
+
|
173
|
+
element.cache.should == " \n"
|
174
|
+
end
|
175
|
+
|
176
|
+
it "should be correctly reported as empty by cache_filled?" do
|
177
|
+
element.should respond_to(:cache_filled?)
|
178
|
+
|
179
|
+
element.cache_filled?.should be_false
|
180
|
+
end
|
181
|
+
|
182
|
+
it "should be correctly reported as filled by cache_filled?" do
|
183
|
+
element = Aef::Hosts::Entry.new('127.0.0.1', 'localhost', :cache => " \n")
|
184
|
+
|
185
|
+
element.should respond_to(:cache_filled?)
|
186
|
+
|
187
|
+
element.cache_filled?.should be_true
|
188
|
+
end
|
189
|
+
|
190
|
+
it "should be invalidatable" do
|
191
|
+
element = Aef::Hosts::Entry.new('127.0.0.1', 'localhost', :cache => " \n")
|
192
|
+
|
193
|
+
element.invalidate_cache!
|
194
|
+
|
195
|
+
element.cache.should be_nil
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
context "#inspect" do
|
200
|
+
it "should be able to generate a debugging String" do
|
201
|
+
element.inspect.should eql %{#<Aef::Hosts::Entry: address="192.168.0.1" name="somehost" aliases=[] comment=nil>}
|
202
|
+
end
|
203
|
+
|
204
|
+
it "should be able to generate a debugging String with aliases" do
|
205
|
+
element.aliases << 'fnord'
|
206
|
+
element.aliases << 'eris'
|
207
|
+
element.inspect.should eql %{#<Aef::Hosts::Entry: address="192.168.0.1" name="somehost" aliases=["fnord", "eris"] comment=nil>}
|
208
|
+
end
|
209
|
+
|
210
|
+
it "should be able to generate a debugging String with comment" do
|
211
|
+
element.comment = "This is not the host you're looking for"
|
212
|
+
element.inspect.should eql %{#<Aef::Hosts::Entry: address="192.168.0.1" name="somehost" aliases=[] comment="This is not the host you're looking for">}
|
213
|
+
end
|
214
|
+
|
215
|
+
it "should be able to generate a debugging String with cache filled" do
|
216
|
+
element = Aef::Hosts::Entry.new('192.168.0.1', 'somehost', :cache => 'Some cache...')
|
217
|
+
element.inspect.should eql %{#<Aef::Hosts::Entry: address="192.168.0.1" name="somehost" aliases=[] comment=nil cached!>}
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
describe "string generation" do
|
222
|
+
it "should generate a new representation if no cache is available" do
|
223
|
+
element = Aef::Hosts::Entry.new('127.0.0.1', 'localhost',
|
224
|
+
:comment => 'my comment',
|
225
|
+
:aliases => ['alias1', 'alias2']
|
226
|
+
)
|
227
|
+
|
228
|
+
element.to_s.should == "127.0.0.1 localhost alias1 alias2 #my comment\n"
|
229
|
+
end
|
230
|
+
|
231
|
+
it "should respond with a duplicate of the cached representation if cache is filled" do
|
232
|
+
element = Aef::Hosts::Entry.new('127.0.0.1', 'localhost',
|
233
|
+
:comment => 'my commenbt',
|
234
|
+
:aliases => ['alias1', 'alias2'],
|
235
|
+
:cache => "127.0.0.1\tlocalhost\talias1\talias2\t#my comment\n"
|
236
|
+
)
|
237
|
+
|
238
|
+
element.to_s.should == "127.0.0.1\tlocalhost\talias1\talias2\t#my comment\n"
|
239
|
+
element.to_s.should_not equal(element.cache) # Should not be identical
|
240
|
+
end
|
241
|
+
|
242
|
+
it "should ignore cache and generate a new representation if generation is explicitly forced" do
|
243
|
+
element = Aef::Hosts::Entry.new('127.0.0.1', 'localhost',
|
244
|
+
:comment => 'my comment',
|
245
|
+
:aliases => ['alias1', 'alias2'],
|
246
|
+
:cache => "127.0.0.1\tlocalhost\talias1\talias2\t#my comment\n"
|
247
|
+
)
|
248
|
+
|
249
|
+
element.to_s(:force_generation => true).should == "127.0.0.1 localhost alias1 alias2 #my comment\n"
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|