Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(FM-5739) removes mocha stubbing #1540

Merged
merged 1 commit into from
Oct 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions spec/spec_helper_local.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
RSpec.configure do |config|
config.filter_run focus: true
config.run_all_when_everything_filtered = true
#as soon as psh is updated, the following line can be removed
config.mock_with :rspec
end

shared_examples :compile, :compile => true do
Expand Down
12 changes: 6 additions & 6 deletions spec/unit/apache_version_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
describe 'apache_version' do
context 'with value' do
before :each do
Facter::Util::Resolution.stubs(:which).with('apachectl').returns(true)
Facter::Util::Resolution.stubs(:exec).with('apachectl -v 2>&1').returns('Server version: Apache/2.4.16 (Unix)
Server built: Jul 31 2015 15:53:26')
expect(Facter::Util::Resolution).to receive(:which).with('apachectl') { true }
expect(Facter::Util::Resolution).to receive(:exec).with('apachectl -v 2>&1') {'Server version: Apache/2.4.16 (Unix)
Server built: Jul 31 2015 15:53:26'}
end
it do
expect(Facter.fact(:apache_version).value).to eq('2.4.16')
Expand All @@ -21,9 +21,9 @@
describe 'apache_version with empty OS' do
context 'with value' do
before :each do
Facter::Util::Resolution.stubs(:which).with('apachectl').returns(true)
Facter::Util::Resolution.stubs(:exec).with('apachectl -v 2>&1').returns('Server version: Apache/2.4.6 ()
Server built: Nov 21 2015 05:34:59')
expect(Facter::Util::Resolution).to receive(:which).with('apachectl') { true }
expect(Facter::Util::Resolution).to receive(:exec).with('apachectl -v 2>&1') {'Server version: Apache/2.4.6 ()
Server built: Nov 21 2015 05:34:59' }
end
it do
expect(Facter.fact(:apache_version).value).to eq('2.4.6')
Expand Down
108 changes: 54 additions & 54 deletions spec/unit/provider/a2mod/gentoo_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@

describe "when fetching modules" do
before do
@filetype = mock()
@filetype = double()
end

it "should return a sorted array of the defined parameters" do
@filetype.expects(:read).returns(%Q{APACHE2_OPTS="-D FOO -D BAR -D BAZ"\n})
provider_class.expects(:filetype).returns(@filetype)
expect(@filetype).to receive(:read) { %Q{APACHE2_OPTS="-D FOO -D BAR -D BAZ"\n} }
expect(provider_class).to receive(:filetype) { @filetype }

expect(provider_class.modules).to eq(%w{bar baz foo})
end

it "should cache the module list" do
@filetype.expects(:read).once.returns(%Q{APACHE2_OPTS="-D FOO -D BAR -D BAZ"\n})
provider_class.expects(:filetype).once.returns(@filetype)
expect(@filetype).to receive(:read).once { %Q{APACHE2_OPTS="-D FOO -D BAR -D BAZ"\n} }
expect(provider_class).to receive(:filetype).once { @filetype }

2.times { expect(provider_class.modules).to eq(%w{bar baz foo}) }
end
Expand All @@ -42,121 +42,121 @@

describe "when prefetching" do
it "should match providers to resources" do
provider = mock("ssl_provider", :name => "ssl")
resource = mock("ssl_resource")
provider = double("ssl_provider", :name => "ssl")
resource = double("ssl_resource")
resource.expects(:provider=).with(provider)

provider_class.expects(:instances).returns([provider])
expect(provider_class).to receive(:instances) { [provider] }
provider_class.prefetch("ssl" => resource)
end
end

describe "when flushing" do
before :each do
@filetype = mock()
@filetype.stubs(:backup)
provider_class.expects(:filetype).at_least_once.returns(@filetype)
@filetype = double()
allow(@filetype).to receive(:backup)
allow(provider_class).to receive(:filetype).at_least(:once) { @filetype }

@info = mock()
@info.stubs(:[]).with(:name).returns("info")
@info.stubs(:provider=)
@info = double()
allow(@info).to receive(:[]).with(:name) { "info" }
allow(@info).to receive(:provider=)

@mpm = mock()
@mpm.stubs(:[]).with(:name).returns("mpm")
@mpm.stubs(:provider=)
@mpm = double()
allow(@mpm).to receive(:[]).with(:name) { "mpm" }
allow(@mpm).to receive(:provider=)

@ssl = mock()
@ssl.stubs(:[]).with(:name).returns("ssl")
@ssl.stubs(:provider=)
@ssl = double()
allow(@ssl).to receive(:[]).with(:name) { "ssl" }
allow(@ssl).to receive(:provider=)
end

it "should add modules whose ensure is present" do
@filetype.expects(:read).at_least_once.returns(%Q{APACHE2_OPTS=""})
@filetype.expects(:write).with(%Q{APACHE2_OPTS="-D INFO"})
expect(@filetype).to receive(:read).at_least(:once) { %Q{APACHE2_OPTS=""} }
expect(@filetype).to receive(:write).with(%Q{APACHE2_OPTS="-D INFO"})

@info.stubs(:should).with(:ensure).returns(:present)
allow(@info).to receive(:should).with(:ensure) { :present }
provider_class.prefetch("info" => @info)

provider_class.flush
end

it "should remove modules whose ensure is present" do
@filetype.expects(:read).at_least_once.returns(%Q{APACHE2_OPTS="-D INFO"})
@filetype.expects(:write).with(%Q{APACHE2_OPTS=""})
expect(@filetype).to receive(:read).at_least(:once) { %Q{APACHE2_OPTS="-D INFO"} }
expect(@filetype).to receive(:write).with(%Q{APACHE2_OPTS=""})

@info.stubs(:should).with(:ensure).returns(:absent)
@info.stubs(:provider=)
allow(@info).to receive(:should).with(:ensure) { :absent }
allow(@info).to receive(:provider=)
provider_class.prefetch("info" => @info)

provider_class.flush
end

it "should not modify providers without resources" do
@filetype.expects(:read).at_least_once.returns(%Q{APACHE2_OPTS="-D INFO -D MPM"})
@filetype.expects(:write).with(%Q{APACHE2_OPTS="-D MPM -D SSL"})
expect(@filetype).to receive(:read).at_least(:once) { %Q{APACHE2_OPTS="-D INFO -D MPM"} }
expect(@filetype).to receive(:write).with(%Q{APACHE2_OPTS="-D MPM -D SSL"})

@info.stubs(:should).with(:ensure).returns(:absent)
allow(@info).to receive(:should).with(:ensure) { :absent }
provider_class.prefetch("info" => @info)

@ssl.stubs(:should).with(:ensure).returns(:present)
allow(@ssl).to receive(:should).with(:ensure) { :present }
provider_class.prefetch("ssl" => @ssl)

provider_class.flush
end

it "should write the modules in sorted order" do
@filetype.expects(:read).at_least_once.returns(%Q{APACHE2_OPTS=""})
@filetype.expects(:write).with(%Q{APACHE2_OPTS="-D INFO -D MPM -D SSL"})
expect(@filetype).to receive(:read).at_least(:once) { %Q{APACHE2_OPTS=""} }
expect(@filetype).to receive(:write).with(%Q{APACHE2_OPTS="-D INFO -D MPM -D SSL"})

@mpm.stubs(:should).with(:ensure).returns(:present)
allow(@mpm).to receive(:should).with(:ensure) { :present }
provider_class.prefetch("mpm" => @mpm)
@info.stubs(:should).with(:ensure).returns(:present)
allow(@info).to receive(:should).with(:ensure) { :present }
provider_class.prefetch("info" => @info)
@ssl.stubs(:should).with(:ensure).returns(:present)
allow(@ssl).to receive(:should).with(:ensure) { :present }
provider_class.prefetch("ssl" => @ssl)

provider_class.flush
end

it "should write the records back once" do
@filetype.expects(:read).at_least_once.returns(%Q{APACHE2_OPTS=""})
@filetype.expects(:write).once.with(%Q{APACHE2_OPTS="-D INFO -D SSL"})
expect(@filetype).to receive(:read).at_least(:once) { %Q{APACHE2_OPTS=""} }
expect(@filetype).to receive(:write).once.with(%Q{APACHE2_OPTS="-D INFO -D SSL"})

@info.stubs(:should).with(:ensure).returns(:present)
allow(@info).to receive(:should).with(:ensure) { :present }
provider_class.prefetch("info" => @info)

@ssl.stubs(:should).with(:ensure).returns(:present)
allow(@ssl).to receive(:should).with(:ensure) { :present }
provider_class.prefetch("ssl" => @ssl)

provider_class.flush
end

it "should only modify the line containing APACHE2_OPTS" do
@filetype.expects(:read).at_least_once.returns(%Q{# Comment\nAPACHE2_OPTS=""\n# Another comment})
@filetype.expects(:write).once.with(%Q{# Comment\nAPACHE2_OPTS="-D INFO"\n# Another comment})
expect(@filetype).to receive(:read).at_least(:once) { %Q{# Comment\nAPACHE2_OPTS=""\n# Another comment} }
expect(@filetype).to receive(:write).once.with(%Q{# Comment\nAPACHE2_OPTS="-D INFO"\n# Another comment})

@info.stubs(:should).with(:ensure).returns(:present)
allow(@info).to receive(:should).with(:ensure) { :present }
provider_class.prefetch("info" => @info)
provider_class.flush
end

it "should restore any arbitrary arguments" do
@filetype.expects(:read).at_least_once.returns(%Q{APACHE2_OPTS="-Y -D MPM -X"})
@filetype.expects(:write).once.with(%Q{APACHE2_OPTS="-Y -X -D INFO -D MPM"})
expect(@filetype).to receive(:read).at_least(:once) { %Q{APACHE2_OPTS="-Y -D MPM -X"} }
expect(@filetype).to receive(:write).once.with(%Q{APACHE2_OPTS="-Y -X -D INFO -D MPM"})

@info.stubs(:should).with(:ensure).returns(:present)
allow(@info).to receive(:should).with(:ensure) { :present }
provider_class.prefetch("info" => @info)
provider_class.flush
end

it "should backup the file once if changes were made" do
@filetype.expects(:read).at_least_once.returns(%Q{APACHE2_OPTS=""})
@filetype.expects(:write).once.with(%Q{APACHE2_OPTS="-D INFO -D SSL"})
expect(@filetype).to receive(:read).at_least(:once) { %Q{APACHE2_OPTS=""} }
expect(@filetype).to receive(:write).once.with(%Q{APACHE2_OPTS="-D INFO -D SSL"})

@info.stubs(:should).with(:ensure).returns(:present)
allow(@info).to receive(:should).with(:ensure) { :present }
provider_class.prefetch("info" => @info)

@ssl.stubs(:should).with(:ensure).returns(:present)
allow(@ssl).to receive(:should).with(:ensure) { :present }
provider_class.prefetch("ssl" => @ssl)

@filetype.unstub(:backup)
Expand All @@ -165,13 +165,13 @@
end

it "should not write the file or run backups if no changes were made" do
@filetype.expects(:read).at_least_once.returns(%Q{APACHE2_OPTS="-X -D INFO -D SSL -Y"})
@filetype.expects(:write).never
expect(@filetype).to receive(:read).at_least(:once) { %Q{APACHE2_OPTS="-X -D INFO -D SSL -Y"} }
expect(@filetype).to receive(:write).never

@info.stubs(:should).with(:ensure).returns(:present)
allow(@info).to receive(:should).with(:ensure) { :present }
provider_class.prefetch("info" => @info)

@ssl.stubs(:should).with(:ensure).returns(:present)
allow(@ssl).to receive(:should).with(:ensure) { :present }
provider_class.prefetch("ssl" => @ssl)

@filetype.unstub(:backup)
Expand Down