Skip to content

Commit

Permalink
Convert specs to RSpec 2.99.0 syntax with Transpec
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Ashley Penney committed Jun 4, 2014
1 parent f9f6e92 commit d65d235
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 58 deletions.
4 changes: 2 additions & 2 deletions spec/unit/facter/facter_dot_d_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
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

Expand All @@ -26,7 +26,7 @@
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
20 changes: 10 additions & 10 deletions spec/unit/facter/pe_version_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,23 @@
(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
Expand All @@ -54,23 +54,23 @@
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
8 changes: 4 additions & 4 deletions spec/unit/facter/root_home_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

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
Expand All @@ -18,15 +18,15 @@

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
before :each 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
Expand All @@ -45,7 +45,7 @@

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

Expand Down
6 changes: 3 additions & 3 deletions spec/unit/facter/util/puppet_settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
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
Expand All @@ -29,7 +29,7 @@ module Puppet; end
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
Expand Down
18 changes: 9 additions & 9 deletions spec/unit/puppet/parser/functions/bool2str_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,42 @@
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
8 changes: 4 additions & 4 deletions spec/unit/puppet/parser/functions/camelcase_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
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
36 changes: 18 additions & 18 deletions spec/unit/puppet/provider/file_line/ruby_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@
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

Expand Down Expand Up @@ -61,9 +61,9 @@
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
Expand All @@ -80,9 +80,9 @@
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
Expand All @@ -103,25 +103,25 @@
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

Expand Down Expand Up @@ -150,7 +150,7 @@

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

Expand Down Expand Up @@ -179,7 +179,7 @@

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
Expand All @@ -203,23 +203,23 @@
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
File.open(@tmpfile, 'w') do |fh|
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
File.open(@tmpfile, 'w') do |fh|
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
2 changes: 1 addition & 1 deletion spec/unit/puppet/type/anchor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

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
14 changes: 7 additions & 7 deletions spec/unit/puppet/type/file_line_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
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 {
Expand All @@ -35,7 +35,7 @@
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/)
Expand All @@ -47,7 +47,7 @@
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
Expand All @@ -59,12 +59,12 @@
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

0 comments on commit d65d235

Please sign in to comment.