From 0761fcf0433b1c73ff9925d1b8fa20a618f28875 Mon Sep 17 00:00:00 2001 From: Ryan McKern Date: Tue, 13 May 2014 15:33:49 -0700 Subject: (maint) Add bool2str & camelcase spec tests --- spec/unit/puppet/parser/functions/bool2str_spec.rb | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 spec/unit/puppet/parser/functions/bool2str_spec.rb (limited to 'spec/unit/puppet/parser/functions/bool2str_spec.rb') diff --git a/spec/unit/puppet/parser/functions/bool2str_spec.rb b/spec/unit/puppet/parser/functions/bool2str_spec.rb new file mode 100755 index 0000000..c73f7df --- /dev/null +++ b/spec/unit/puppet/parser/functions/bool2str_spec.rb @@ -0,0 +1,34 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the bool2str function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("bool2str").should == "function_bool2str" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_bool2str([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should convert true to 'true'" do + result = scope.function_bool2str([true]) + result.should(eq('true')) + end + + it "should convert true to a string" do + result = scope.function_bool2str([true]) + result.class.should(eq(String)) + end + + it "should convert false to 'false'" do + result = scope.function_bool2str([false]) + result.should(eq('false')) + end + + it "should convert false to a string" do + result = scope.function_bool2str([false]) + result.class.should(eq(String)) + end +end -- cgit v1.2.3 From 557d38bdc63b9b7d418f4bf0ce736406e71380b7 Mon Sep 17 00:00:00 2001 From: Ryan McKern Date: Thu, 15 May 2014 16:45:02 -0700 Subject: (MODULES-905) Extend spec tests for bool2str The extended spec tests validate that the common types of values that could be passed to bool2str() are rejected. --- spec/unit/puppet/parser/functions/bool2str_spec.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'spec/unit/puppet/parser/functions/bool2str_spec.rb') diff --git a/spec/unit/puppet/parser/functions/bool2str_spec.rb b/spec/unit/puppet/parser/functions/bool2str_spec.rb index c73f7df..bed7e68 100755 --- a/spec/unit/puppet/parser/functions/bool2str_spec.rb +++ b/spec/unit/puppet/parser/functions/bool2str_spec.rb @@ -31,4 +31,16 @@ describe "the bool2str function" do result = scope.function_bool2str([false]) result.class.should(eq(String)) end + + it "should not accept a string" do + lambda { scope.function_bool2str(["false"]) }.should( raise_error(Puppet::ParseError)) + end + + it "should not accept a nil value" do + lambda { scope.function_bool2str([nil]) }.should( raise_error(Puppet::ParseError)) + end + + it "should not accept an undef" do + lambda { scope.function_bool2str([:undef]) }.should( raise_error(Puppet::ParseError)) + end end -- cgit v1.2.3 From d65d2354a7458c3281386e7065bd1938d2c2adee Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Wed, 4 Jun 2014 14:37:45 -0400 Subject: Convert specs to RSpec 2.99.0 syntax with Transpec This conversion is done by Transpec 2.2.1 with the following command: transpec spec/unit * 53 conversions from: obj.should to: expect(obj).to * 19 conversions from: == expected to: eq(expected) * 5 conversions from: lambda { }.should to: expect { }.to * 2 conversions from: be_true to: be_truthy For more details: https://github.com/yujinakayama/transpec#supported-conversions --- spec/unit/facter/facter_dot_d_spec.rb | 4 +-- spec/unit/facter/pe_version_spec.rb | 20 ++++++------ spec/unit/facter/root_home_spec.rb | 8 ++--- spec/unit/facter/util/puppet_settings_spec.rb | 6 ++-- spec/unit/puppet/parser/functions/bool2str_spec.rb | 18 +++++------ .../unit/puppet/parser/functions/camelcase_spec.rb | 8 ++--- spec/unit/puppet/provider/file_line/ruby_spec.rb | 36 +++++++++++----------- spec/unit/puppet/type/anchor_spec.rb | 2 +- spec/unit/puppet/type/file_line_spec.rb | 14 ++++----- 9 files changed, 58 insertions(+), 58 deletions(-) (limited to 'spec/unit/puppet/parser/functions/bool2str_spec.rb') diff --git a/spec/unit/facter/facter_dot_d_spec.rb b/spec/unit/facter/facter_dot_d_spec.rb index 2fb72b2..0afadb2 100755 --- a/spec/unit/facter/facter_dot_d_spec.rb +++ b/spec/unit/facter/facter_dot_d_spec.rb @@ -13,7 +13,7 @@ describe Facter::Util::DotD do end it 'should return successfully' do - Facter.fact(:fake_fact).value.should == 'fake fact' + expect(Facter.fact(:fake_fact).value).to eq('fake fact') end end @@ -26,7 +26,7 @@ describe Facter::Util::DotD do end it 'should return successfully' do - Facter.fact(:foo).value.should == '1+1=2' + expect(Facter.fact(:foo).value).to eq('1+1=2') end end end diff --git a/spec/unit/facter/pe_version_spec.rb b/spec/unit/facter/pe_version_spec.rb index 931c6d4..4d0349e 100755 --- a/spec/unit/facter/pe_version_spec.rb +++ b/spec/unit/facter/pe_version_spec.rb @@ -26,23 +26,23 @@ describe "PE Version specs" do (major,minor,patch) = version.split(".") it "Should return true" do - Facter.fact(:is_pe).value.should == true + expect(Facter.fact(:is_pe).value).to eq(true) end it "Should have a version of #{version}" do - Facter.fact(:pe_version).value.should == version + expect(Facter.fact(:pe_version).value).to eq(version) end it "Should have a major version of #{major}" do - Facter.fact(:pe_major_version).value.should == major + expect(Facter.fact(:pe_major_version).value).to eq(major) end it "Should have a minor version of #{minor}" do - Facter.fact(:pe_minor_version).value.should == minor + expect(Facter.fact(:pe_minor_version).value).to eq(minor) end it "Should have a patch version of #{patch}" do - Facter.fact(:pe_patch_version).value.should == patch + expect(Facter.fact(:pe_patch_version).value).to eq(patch) end end end @@ -54,23 +54,23 @@ describe "PE Version specs" do end it "is_pe is false" do - Facter.fact(:is_pe).value.should == false + expect(Facter.fact(:is_pe).value).to eq(false) end it "pe_version is nil" do - Facter.fact(:pe_version).value.should be_nil + expect(Facter.fact(:pe_version).value).to be_nil end it "pe_major_version is nil" do - Facter.fact(:pe_major_version).value.should be_nil + expect(Facter.fact(:pe_major_version).value).to be_nil end it "pe_minor_version is nil" do - Facter.fact(:pe_minor_version).value.should be_nil + expect(Facter.fact(:pe_minor_version).value).to be_nil end it "Should have a patch version" do - Facter.fact(:pe_patch_version).value.should be_nil + expect(Facter.fact(:pe_patch_version).value).to be_nil end end end diff --git a/spec/unit/facter/root_home_spec.rb b/spec/unit/facter/root_home_spec.rb index 73eb3ea..98fe141 100755 --- a/spec/unit/facter/root_home_spec.rb +++ b/spec/unit/facter/root_home_spec.rb @@ -9,7 +9,7 @@ describe Facter::Util::RootHome do it "should return /" do Facter::Util::Resolution.expects(:exec).with("getent passwd root").returns(root_ent) - Facter::Util::RootHome.get_root_home.should == expected_root_home + expect(Facter::Util::RootHome.get_root_home).to eq(expected_root_home) end end context "linux" do @@ -18,7 +18,7 @@ describe Facter::Util::RootHome do it "should return /root" do Facter::Util::Resolution.expects(:exec).with("getent passwd root").returns(root_ent) - Facter::Util::RootHome.get_root_home.should == expected_root_home + expect(Facter::Util::RootHome.get_root_home).to eq(expected_root_home) end end context "windows" do @@ -26,7 +26,7 @@ describe Facter::Util::RootHome do Facter::Util::Resolution.expects(:exec).with("getent passwd root").returns(nil) end it "should be nil on windows" do - Facter::Util::RootHome.get_root_home.should be_nil + expect(Facter::Util::RootHome.get_root_home).to be_nil end end end @@ -45,7 +45,7 @@ describe 'root_home', :type => :fact do it "should return /var/root" do Facter::Util::Resolution.stubs(:exec).with("dscacheutil -q user -a name root").returns(sample_dscacheutil) - Facter.fact(:root_home).value.should == expected_root_home + expect(Facter.fact(:root_home).value).to eq(expected_root_home) end end diff --git a/spec/unit/facter/util/puppet_settings_spec.rb b/spec/unit/facter/util/puppet_settings_spec.rb index e77779b..c06137d 100755 --- a/spec/unit/facter/util/puppet_settings_spec.rb +++ b/spec/unit/facter/util/puppet_settings_spec.rb @@ -11,11 +11,11 @@ describe Facter::Util::PuppetSettings do end it 'should be nil' do - subject.with_puppet { Puppet[:vardir] }.should be_nil + expect(subject.with_puppet { Puppet[:vardir] }).to be_nil end it 'should not yield to the block' do Puppet.expects(:[]).never - subject.with_puppet { Puppet[:vardir] }.should be_nil + expect(subject.with_puppet { Puppet[:vardir] }).to be_nil end end context "With Puppet loaded" do @@ -29,7 +29,7 @@ describe Facter::Util::PuppetSettings do subject.with_puppet { Puppet[:vardir] } end it 'should return the nodes vardir' do - subject.with_puppet { Puppet[:vardir] }.should eq vardir + expect(subject.with_puppet { Puppet[:vardir] }).to eq vardir end end end diff --git a/spec/unit/puppet/parser/functions/bool2str_spec.rb b/spec/unit/puppet/parser/functions/bool2str_spec.rb index bed7e68..b878891 100755 --- a/spec/unit/puppet/parser/functions/bool2str_spec.rb +++ b/spec/unit/puppet/parser/functions/bool2str_spec.rb @@ -5,42 +5,42 @@ describe "the bool2str function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } it "should exist" do - Puppet::Parser::Functions.function("bool2str").should == "function_bool2str" + expect(Puppet::Parser::Functions.function("bool2str")).to eq("function_bool2str") end it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_bool2str([]) }.should( raise_error(Puppet::ParseError)) + expect { scope.function_bool2str([]) }.to( raise_error(Puppet::ParseError)) end it "should convert true to 'true'" do result = scope.function_bool2str([true]) - result.should(eq('true')) + expect(result).to(eq('true')) end it "should convert true to a string" do result = scope.function_bool2str([true]) - result.class.should(eq(String)) + expect(result.class).to(eq(String)) end it "should convert false to 'false'" do result = scope.function_bool2str([false]) - result.should(eq('false')) + expect(result).to(eq('false')) end it "should convert false to a string" do result = scope.function_bool2str([false]) - result.class.should(eq(String)) + expect(result.class).to(eq(String)) end it "should not accept a string" do - lambda { scope.function_bool2str(["false"]) }.should( raise_error(Puppet::ParseError)) + expect { scope.function_bool2str(["false"]) }.to( raise_error(Puppet::ParseError)) end it "should not accept a nil value" do - lambda { scope.function_bool2str([nil]) }.should( raise_error(Puppet::ParseError)) + expect { scope.function_bool2str([nil]) }.to( raise_error(Puppet::ParseError)) end it "should not accept an undef" do - lambda { scope.function_bool2str([:undef]) }.should( raise_error(Puppet::ParseError)) + expect { scope.function_bool2str([:undef]) }.to( raise_error(Puppet::ParseError)) end end diff --git a/spec/unit/puppet/parser/functions/camelcase_spec.rb b/spec/unit/puppet/parser/functions/camelcase_spec.rb index 3b1f1d0..70382ad 100755 --- a/spec/unit/puppet/parser/functions/camelcase_spec.rb +++ b/spec/unit/puppet/parser/functions/camelcase_spec.rb @@ -5,20 +5,20 @@ describe "the camelcase function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } it "should exist" do - Puppet::Parser::Functions.function("camelcase").should == "function_camelcase" + expect(Puppet::Parser::Functions.function("camelcase")).to eq("function_camelcase") end it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_camelcase([]) }.should( raise_error(Puppet::ParseError)) + expect { scope.function_camelcase([]) }.to( raise_error(Puppet::ParseError)) end it "should capitalize the beginning of a normal string" do result = scope.function_camelcase(["abc"]) - result.should(eq("Abc")) + expect(result).to(eq("Abc")) end it "should camelcase an underscore-delimited string" do result = scope.function_camelcase(["aa_bb_cc"]) - result.should(eq("AaBbCc")) + expect(result).to(eq("AaBbCc")) end end diff --git a/spec/unit/puppet/provider/file_line/ruby_spec.rb b/spec/unit/puppet/provider/file_line/ruby_spec.rb index a016b68..d2a129c 100755 --- a/spec/unit/puppet/provider/file_line/ruby_spec.rb +++ b/spec/unit/puppet/provider/file_line/ruby_spec.rb @@ -23,17 +23,17 @@ describe provider_class do File.open(tmpfile, 'w') do |fh| fh.write('foo') end - provider.exists?.should be_true + expect(provider.exists?).to be_truthy end it 'should detect if the line does not exist in the file' do File.open(tmpfile, 'w') do |fh| fh.write('foo1') end - provider.exists?.should be_nil + expect(provider.exists?).to be_nil end it 'should append to an existing file when creating' do provider.create - File.read(tmpfile).chomp.should == 'foo' + expect(File.read(tmpfile).chomp).to eq('foo') end end @@ -61,9 +61,9 @@ describe provider_class do File.open(@tmpfile, 'w') do |fh| fh.write("foo1\nfoo=blah\nfoo2\nfoo=baz") end - @provider.exists?.should be_nil + expect(@provider.exists?).to be_nil expect { @provider.create }.to raise_error(Puppet::Error, /More than one line.*matches/) - File.read(@tmpfile).should eql("foo1\nfoo=blah\nfoo2\nfoo=baz") + expect(File.read(@tmpfile)).to eql("foo1\nfoo=blah\nfoo2\nfoo=baz") end it 'should replace all lines that matches' do @@ -80,9 +80,9 @@ describe provider_class do File.open(@tmpfile, 'w') do |fh| fh.write("foo1\nfoo=blah\nfoo2\nfoo=baz") end - @provider.exists?.should be_nil + expect(@provider.exists?).to be_nil @provider.create - File.read(@tmpfile).chomp.should eql("foo1\nfoo = bar\nfoo2\nfoo = bar") + expect(File.read(@tmpfile).chomp).to eql("foo1\nfoo = bar\nfoo2\nfoo = bar") end it 'should raise an error with invalid values' do @@ -103,25 +103,25 @@ describe provider_class do File.open(@tmpfile, 'w') do |fh| fh.write("foo1\nfoo=blah\nfoo2") end - @provider.exists?.should be_nil + expect(@provider.exists?).to be_nil @provider.create - File.read(@tmpfile).chomp.should eql("foo1\nfoo = bar\nfoo2") + expect(File.read(@tmpfile).chomp).to eql("foo1\nfoo = bar\nfoo2") end it 'should add a new line if no lines match' do File.open(@tmpfile, 'w') do |fh| fh.write("foo1\nfoo2") end - @provider.exists?.should be_nil + expect(@provider.exists?).to be_nil @provider.create - File.read(@tmpfile).should eql("foo1\nfoo2\nfoo = bar\n") + expect(File.read(@tmpfile)).to eql("foo1\nfoo2\nfoo = bar\n") end it 'should do nothing if the exact line already exists' do File.open(@tmpfile, 'w') do |fh| fh.write("foo1\nfoo = bar\nfoo2") end - @provider.exists?.should be_true + expect(@provider.exists?).to be_truthy @provider.create - File.read(@tmpfile).chomp.should eql("foo1\nfoo = bar\nfoo2") + expect(File.read(@tmpfile).chomp).to eql("foo1\nfoo = bar\nfoo2") end end @@ -150,7 +150,7 @@ describe provider_class do it 'inserts the specified line after the line matching the "after" expression' do provider.create - File.read(@tmpfile).chomp.should eql("foo1\ninserted = line\nfoo = blah\nfoo2\nfoo = baz") + expect(File.read(@tmpfile).chomp).to eql("foo1\ninserted = line\nfoo = blah\nfoo2\nfoo = baz") end end @@ -179,7 +179,7 @@ describe provider_class do it 'appends the specified line to the file' do provider.create - File.read(@tmpfile).should eq(content << resource[:line] << "\n") + expect(File.read(@tmpfile)).to eq(content << resource[:line] << "\n") end end end @@ -203,7 +203,7 @@ describe provider_class do fh.write("foo1\nfoo\nfoo2") end @provider.destroy - File.read(@tmpfile).should eql("foo1\nfoo2") + expect(File.read(@tmpfile)).to eql("foo1\nfoo2") end it 'should remove the line without touching the last new line' do @@ -211,7 +211,7 @@ describe provider_class do fh.write("foo1\nfoo\nfoo2\n") end @provider.destroy - File.read(@tmpfile).should eql("foo1\nfoo2\n") + expect(File.read(@tmpfile)).to eql("foo1\nfoo2\n") end it 'should remove any occurence of the line' do @@ -219,7 +219,7 @@ describe provider_class do fh.write("foo1\nfoo\nfoo2\nfoo\nfoo") end @provider.destroy - File.read(@tmpfile).should eql("foo1\nfoo2\n") + expect(File.read(@tmpfile)).to eql("foo1\nfoo2\n") end end end diff --git a/spec/unit/puppet/type/anchor_spec.rb b/spec/unit/puppet/type/anchor_spec.rb index f92065f..c738a27 100755 --- a/spec/unit/puppet/type/anchor_spec.rb +++ b/spec/unit/puppet/type/anchor_spec.rb @@ -6,6 +6,6 @@ anchor = Puppet::Type.type(:anchor).new(:name => "ntp::begin") describe anchor do it "should stringify normally" do - anchor.to_s.should == "Anchor[ntp::begin]" + expect(anchor.to_s).to eq("Anchor[ntp::begin]") end end diff --git a/spec/unit/puppet/type/file_line_spec.rb b/spec/unit/puppet/type/file_line_spec.rb index ab5b81b..9ef49ef 100755 --- a/spec/unit/puppet/type/file_line_spec.rb +++ b/spec/unit/puppet/type/file_line_spec.rb @@ -7,13 +7,13 @@ describe Puppet::Type.type(:file_line) do end it 'should accept a line and path' do file_line[:line] = 'my_line' - file_line[:line].should == 'my_line' + expect(file_line[:line]).to eq('my_line') file_line[:path] = '/my/path' - file_line[:path].should == '/my/path' + expect(file_line[:path]).to eq('/my/path') end it 'should accept a match regex' do file_line[:match] = '^foo.*$' - file_line[:match].should == '^foo.*$' + expect(file_line[:match]).to eq('^foo.*$') end it 'should not accept a match regex that does not match the specified line' do expect { @@ -35,7 +35,7 @@ describe Puppet::Type.type(:file_line) do end it 'should accept posix filenames' do file_line[:path] = '/tmp/path' - file_line[:path].should == '/tmp/path' + expect(file_line[:path]).to eq('/tmp/path') end it 'should not accept unqualified path' do expect { file_line[:path] = 'file' }.to raise_error(Puppet::Error, /File paths must be fully qualified/) @@ -47,7 +47,7 @@ describe Puppet::Type.type(:file_line) do expect { Puppet::Type.type(:file_line).new(:name => 'foo', :line => 'path') }.to raise_error(Puppet::Error, /Both line and path are required attributes/) end it 'should default to ensure => present' do - file_line[:ensure].should eq :present + expect(file_line[:ensure]).to eq :present end it "should autorequire the file it manages" do @@ -59,12 +59,12 @@ describe Puppet::Type.type(:file_line) do relationship = file_line.autorequire.find do |rel| (rel.source.to_s == "File[/tmp/path]") and (rel.target.to_s == file_line.to_s) end - relationship.should be_a Puppet::Relationship + expect(relationship).to be_a Puppet::Relationship end it "should not autorequire the file it manages if it is not managed" do catalog = Puppet::Resource::Catalog.new catalog.add_resource file_line - file_line.autorequire.should be_empty + expect(file_line.autorequire).to be_empty end end -- cgit v1.2.3