]> gitweb.fluxo.info Git - puppet-stdlib.git/commitdiff
Convert specs to RSpec 2.99.0 syntax with Transpec
authorAshley Penney <ashley.penney@puppetlabs.com>
Wed, 4 Jun 2014 18:37:45 +0000 (14:37 -0400)
committerAshley Penney <ashley.penney@puppetlabs.com>
Wed, 4 Jun 2014 18:37:45 +0000 (14:37 -0400)
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
spec/unit/facter/pe_version_spec.rb
spec/unit/facter/root_home_spec.rb
spec/unit/facter/util/puppet_settings_spec.rb
spec/unit/puppet/parser/functions/bool2str_spec.rb
spec/unit/puppet/parser/functions/camelcase_spec.rb
spec/unit/puppet/provider/file_line/ruby_spec.rb
spec/unit/puppet/type/anchor_spec.rb
spec/unit/puppet/type/file_line_spec.rb

index 2fb72b29efb719c1de15e35ab6073b39b617bf44..0afadb25f3eae44da687400601d048c81b94fc50 100755 (executable)
@@ -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
index 931c6d4b0a3cc598cbd45710bd37e29c38d84d55..4d0349e62a4d5ff147b39d9b96ea7ad2ac9a5e13 100755 (executable)
@@ -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
index 73eb3eada8c6e8ee931b70929c8e80eec4314b12..98fe14196dbdf075140858040d41c800e42c2ec9 100755 (executable)
@@ -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
 
index e77779bae1478326a2174a1d875aa08d2956189c..c06137d7e2a93c0a7176fd5d6720f1c2f9c0a700 100755 (executable)
@@ -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
index bed7e68a0e482f358ee12c8cca5e740bf4af50f0..b8788918052f4489fa43bf10376e26331e128e8b 100755 (executable)
@@ -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
index 3b1f1d0208d3ef20167503b6d64b8fbc211f624a..70382adb1c949f588460c5c1cc75e6c35a57a493 100755 (executable)
@@ -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
index a016b685c35df541d862df95cd19d9e6f6bc8a67..d2a129c327d97f42128b47b7a7e6471c640832da 100755 (executable)
@@ -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
index f92065f79ba0ab4398755407153bce48811520ea..c738a272b7f3a5ad09f9640af661e9729af3589d 100755 (executable)
@@ -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
index ab5b81bb96b74c461edb4fc35bbfe9d079b4bcd9..9ef49efbff232b9d28102b3bb0fcca663452cfda 100755 (executable)
@@ -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