aboutsummaryrefslogtreecommitdiff
path: root/spec/unit/provider/host/parsed_spec.rb
diff options
context:
space:
mode:
authorJosh Cooper <josh@puppet.com>2018-07-09 19:50:03 -0700
committerJosh Cooper <josh@puppet.com>2018-07-09 19:50:03 -0700
commit59f4a9e49d397556a60f060faffdc14b734856da (patch)
tree8b630a7d02fc4e6e207fc3d84b9d78c1f6637191 /spec/unit/provider/host/parsed_spec.rb
parent34e83e11a5fc344195217d9cd159d022b5d89ec1 (diff)
downloadpuppet-hosts_core-59f4a9e49d397556a60f060faffdc14b734856da.tar.gz
puppet-hosts_core-59f4a9e49d397556a60f060faffdc14b734856da.tar.bz2
Automatic validation updates
Updated rubocop violations using `pdk validate -a`.
Diffstat (limited to 'spec/unit/provider/host/parsed_spec.rb')
-rw-r--r--spec/unit/provider/host/parsed_spec.rb183
1 files changed, 86 insertions, 97 deletions
diff --git a/spec/unit/provider/host/parsed_spec.rb b/spec/unit/provider/host/parsed_spec.rb
index b2cba76..961dc7b 100644
--- a/spec/unit/provider/host/parsed_spec.rb
+++ b/spec/unit/provider/host/parsed_spec.rb
@@ -9,7 +9,7 @@ provider_class = Puppet::Type.type(:host).provider(:parsed)
describe provider_class do
include PuppetSpec::Files
- before do
+ before(:each) do
@host_class = Puppet::Type.type(:host)
@provider = @host_class.provider(:parsed)
@hostfile = tmpfile('hosts')
@@ -21,7 +21,7 @@ describe provider_class do
end
def mkhost(args)
- hostresource = Puppet::Type::Host.new(:name => args[:name])
+ hostresource = Puppet::Type::Host.new(name: args[:name])
hostresource.stubs(:should).with(:target).returns @hostfile
# Using setters of provider to build our testobject
@@ -29,8 +29,8 @@ describe provider_class do
# the provider setter "host_aliases=(value)" will be
# called with the joined array, so we just simulate that
host = @provider.new(hostresource)
- args.each do |property,value|
- value = value.join(" ") if property == :host_aliases and value.is_a?(Array)
+ args.each do |property, value|
+ value = value.join(' ') if property == :host_aliases && value.is_a?(Array)
host.send("#{property}=", value)
end
host
@@ -45,189 +45,178 @@ describe provider_class do
@provider.target_object(@hostfile).read
end
- describe "when parsing on incomplete line" do
-
- it "should work for only ip" do
- expect(@provider.parse_line("127.0.0.1")[:line]).to eq("127.0.0.1")
+ describe 'when parsing on incomplete line' do
+ it 'works for only ip' do
+ expect(@provider.parse_line('127.0.0.1')[:line]).to eq('127.0.0.1')
end
- it "should work for only hostname" do
- expect(@provider.parse_line("www.example.com")[:line]).to eq("www.example.com")
+ it 'works for only hostname' do
+ expect(@provider.parse_line('www.example.com')[:line]).to eq('www.example.com')
end
- it "should work for ip and space" do
- expect(@provider.parse_line("127.0.0.1 ")[:line]).to eq("127.0.0.1 ")
+ it 'works for ip and space' do
+ expect(@provider.parse_line('127.0.0.1 ')[:line]).to eq('127.0.0.1 ')
end
- it "should work for hostname and space" do
- expect(@provider.parse_line("www.example.com ")[:line]).to eq("www.example.com ")
+ it 'works for hostname and space' do
+ expect(@provider.parse_line('www.example.com ')[:line]).to eq('www.example.com ')
end
- it "should work for hostname and host_aliases" do
- expect(@provider.parse_line("www.example.com www xyz")[:line]).to eq("www.example.com www xyz")
+ it 'works for hostname and host_aliases' do
+ expect(@provider.parse_line('www.example.com www xyz')[:line]).to eq('www.example.com www xyz')
end
- it "should work for ip and comment" do
- expect(@provider.parse_line("127.0.0.1 #www xyz")[:line]).to eq("127.0.0.1 #www xyz")
+ it 'works for ip and comment' do
+ expect(@provider.parse_line('127.0.0.1 #www xyz')[:line]).to eq('127.0.0.1 #www xyz')
end
- it "should work for hostname and comment" do
- expect(@provider.parse_line("xyz #www test123")[:line]).to eq("xyz #www test123")
+ it 'works for hostname and comment' do
+ expect(@provider.parse_line('xyz #www test123')[:line]).to eq('xyz #www test123')
end
- it "should work for crazy incomplete lines" do
+ it 'works for crazy incomplete lines' do
expect(@provider.parse_line("%th1s is a\t cr$zy !incompl1t line")[:line]).to eq("%th1s is a\t cr$zy !incompl1t line")
end
-
end
- describe "when parsing a line with ip and hostname" do
-
- it "should parse an ipv4 from the first field" do
- expect(@provider.parse_line("127.0.0.1 localhost")[:ip]).to eq("127.0.0.1")
+ describe 'when parsing a line with ip and hostname' do
+ it 'parses an ipv4 from the first field' do
+ expect(@provider.parse_line('127.0.0.1 localhost')[:ip]).to eq('127.0.0.1')
end
- it "should parse an ipv6 from the first field" do
- expect(@provider.parse_line("::1 localhost")[:ip]).to eq("::1")
+ it 'parses an ipv6 from the first field' do
+ expect(@provider.parse_line('::1 localhost')[:ip]).to eq('::1')
end
- it "should parse the name from the second field" do
- expect(@provider.parse_line("::1 localhost")[:name]).to eq("localhost")
+ it 'parses the name from the second field' do
+ expect(@provider.parse_line('::1 localhost')[:name]).to eq('localhost')
end
- it "should set an empty comment" do
- expect(@provider.parse_line("::1 localhost")[:comment]).to eq("")
+ it 'sets an empty comment' do
+ expect(@provider.parse_line('::1 localhost')[:comment]).to eq('')
end
- it "should set host_aliases to :absent" do
- expect(@provider.parse_line("::1 localhost")[:host_aliases]).to eq(:absent)
+ it 'sets host_aliases to :absent' do
+ expect(@provider.parse_line('::1 localhost')[:host_aliases]).to eq(:absent)
end
-
end
- describe "when parsing a line with ip, hostname and comment" do
- before do
- @testline = "127.0.0.1 localhost # A comment with a #-char"
+ describe 'when parsing a line with ip, hostname and comment' do
+ before(:each) do
+ @testline = '127.0.0.1 localhost # A comment with a #-char'
end
- it "should parse the ip from the first field" do
- expect(@provider.parse_line(@testline)[:ip]).to eq("127.0.0.1")
+ it 'parses the ip from the first field' do
+ expect(@provider.parse_line(@testline)[:ip]).to eq('127.0.0.1')
end
- it "should parse the hostname from the second field" do
- expect(@provider.parse_line(@testline)[:name]).to eq("localhost")
+ it 'parses the hostname from the second field' do
+ expect(@provider.parse_line(@testline)[:name]).to eq('localhost')
end
- it "should parse the comment after the first '#' character" do
+ it "parses the comment after the first '#' character" do
expect(@provider.parse_line(@testline)[:comment]).to eq('A comment with a #-char')
end
-
end
- describe "when parsing a line with ip, hostname and aliases" do
-
- it "should parse alias from the third field" do
- expect(@provider.parse_line("127.0.0.1 localhost localhost.localdomain")[:host_aliases]).to eq("localhost.localdomain")
+ describe 'when parsing a line with ip, hostname and aliases' do
+ it 'parses alias from the third field' do
+ expect(@provider.parse_line('127.0.0.1 localhost localhost.localdomain')[:host_aliases]).to eq('localhost.localdomain')
end
- it "should parse multiple aliases" do
- expect(@provider.parse_line("127.0.0.1 host alias1 alias2")[:host_aliases]).to eq('alias1 alias2')
+ it 'parses multiple aliases' do
+ expect(@provider.parse_line('127.0.0.1 host alias1 alias2')[:host_aliases]).to eq('alias1 alias2')
expect(@provider.parse_line("127.0.0.1 host alias1\talias2")[:host_aliases]).to eq('alias1 alias2')
expect(@provider.parse_line("127.0.0.1 host alias1\talias2 alias3")[:host_aliases]).to eq('alias1 alias2 alias3')
end
-
end
- describe "when parsing a line with ip, hostname, aliases and comment" do
-
- before do
+ describe 'when parsing a line with ip, hostname, aliases and comment' do
+ before(:each) do
# Just playing with a few different delimiters
@testline = "127.0.0.1\t host alias1\talias2 alias3 # A comment with a #-char"
end
- it "should parse the ip from the first field" do
- expect(@provider.parse_line(@testline)[:ip]).to eq("127.0.0.1")
+ it 'parses the ip from the first field' do
+ expect(@provider.parse_line(@testline)[:ip]).to eq('127.0.0.1')
end
- it "should parse the hostname from the second field" do
- expect(@provider.parse_line(@testline)[:name]).to eq("host")
+ it 'parses the hostname from the second field' do
+ expect(@provider.parse_line(@testline)[:name]).to eq('host')
end
- it "should parse all host_aliases from the third field" do
+ it 'parses all host_aliases from the third field' do
expect(@provider.parse_line(@testline)[:host_aliases]).to eq('alias1 alias2 alias3')
end
- it "should parse the comment after the first '#' character" do
+ it "parses the comment after the first '#' character" do
expect(@provider.parse_line(@testline)[:comment]).to eq('A comment with a #-char')
end
-
end
- describe "when operating on /etc/hosts like files" do
- it_should_behave_like "all parsedfile providers",
- provider_class, my_fixtures('valid*')
+ describe 'when operating on /etc/hosts like files' do
+ it_behaves_like 'all parsedfile providers',
+ provider_class, my_fixtures('valid*')
- it "should be able to generate a simple hostfile entry" do
+ it 'is able to generate a simple hostfile entry' do
host = mkhost(
- :name => 'localhost',
- :ip => '127.0.0.1',
- :ensure => :present
+ name: 'localhost',
+ ip: '127.0.0.1',
+ ensure: :present,
)
expect(genhost(host)).to eq("127.0.0.1\tlocalhost\n")
end
- it "should be able to generate an entry with one alias" do
+ it 'is able to generate an entry with one alias' do
host = mkhost(
- :name => 'localhost.localdomain',
- :ip => '127.0.0.1',
- :host_aliases => 'localhost',
- :ensure => :present
+ name: 'localhost.localdomain',
+ ip: '127.0.0.1',
+ host_aliases: 'localhost',
+ ensure: :present,
)
expect(genhost(host)).to eq("127.0.0.1\tlocalhost.localdomain\tlocalhost\n")
end
- it "should be able to generate an entry with more than one alias" do
+ it 'is able to generate an entry with more than one alias' do
host = mkhost(
- :name => 'host',
- :ip => '192.0.0.1',
- :host_aliases => [ 'a1','a2','a3','a4' ],
- :ensure => :present
+ name: 'host',
+ ip: '192.0.0.1',
+ host_aliases: ['a1', 'a2', 'a3', 'a4'],
+ ensure: :present,
)
expect(genhost(host)).to eq("192.0.0.1\thost\ta1 a2 a3 a4\n")
end
- it "should be able to generate a simple hostfile entry with comments" do
+ it 'is able to generate a simple hostfile entry with comments' do
host = mkhost(
- :name => 'localhost',
- :ip => '127.0.0.1',
- :comment => 'Bazinga!',
- :ensure => :present
+ name: 'localhost',
+ ip: '127.0.0.1',
+ comment: 'Bazinga!',
+ ensure: :present,
)
expect(genhost(host)).to eq("127.0.0.1\tlocalhost\t# Bazinga!\n")
end
- it "should be able to generate an entry with one alias and a comment" do
+ it 'is able to generate an entry with one alias and a comment' do
host = mkhost(
- :name => 'localhost.localdomain',
- :ip => '127.0.0.1',
- :host_aliases => 'localhost',
- :comment => 'Bazinga!',
- :ensure => :present
+ name: 'localhost.localdomain',
+ ip: '127.0.0.1',
+ host_aliases: 'localhost',
+ comment: 'Bazinga!',
+ ensure: :present,
)
expect(genhost(host)).to eq("127.0.0.1\tlocalhost.localdomain\tlocalhost\t# Bazinga!\n")
end
- it "should be able to generate an entry with more than one alias and a comment" do
+ it 'is able to generate an entry with more than one alias and a comment' do
host = mkhost(
- :name => 'host',
- :ip => '192.0.0.1',
- :host_aliases => [ 'a1','a2','a3','a4' ],
- :comment => 'Bazinga!',
- :ensure => :present
+ name: 'host',
+ ip: '192.0.0.1',
+ host_aliases: ['a1', 'a2', 'a3', 'a4'],
+ comment: 'Bazinga!',
+ ensure: :present,
)
expect(genhost(host)).to eq("192.0.0.1\thost\ta1 a2 a3 a4\t# Bazinga!\n")
end
-
end
-
end