diff --git a/.rubocop.yml b/.rubocop.yml index 53ac189..ea22bff 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,4 +1,6 @@ --- +inherit_from: .rubocop_todo.yml + # Managed by modulesync - DO NOT EDIT # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..b551bec --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,25 @@ +# This configuration was generated by +# `rubocop --auto-gen-config --no-auto-gen-timestamp` +# using RuboCop version 1.50.2. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 16 +# Configuration parameters: . +# SupportedStyles: have_received, receive +RSpec/MessageSpies: + EnforcedStyle: receive + +# Offense count: 8 +RSpec/StubbedMock: + Exclude: + - 'spec/unit/provider/alternatives/chkconfig_spec.rb' + - 'spec/unit/provider/alternatives/dpkg_spec.rb' + +# Offense count: 8 +RSpec/SubjectStub: + Exclude: + - 'spec/unit/provider/alternatives/chkconfig_spec.rb' + - 'spec/unit/provider/alternatives/dpkg_spec.rb' diff --git a/.sync.yml b/.sync.yml index 872928e..130aaeb 100644 --- a/.sync.yml +++ b/.sync.yml @@ -3,9 +3,3 @@ enabled_lint_checks: - parameter_documentation - parameter_types -Gemfile: - optional: - ':test': - - gem: 'mocha' -spec/spec_helper.rb: - mock_with: ':mocha' diff --git a/Gemfile b/Gemfile index b149e6c..ddd05cc 100644 --- a/Gemfile +++ b/Gemfile @@ -6,7 +6,6 @@ source ENV['GEM_SOURCE'] || 'https://rubygems.org' group :test do gem 'voxpupuli-test', '~> 11.0', :require => false gem 'puppet_metadata', '~> 5.0', :require => false - gem 'mocha', :require => false end group :development do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3226b22..58c9b66 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -11,7 +11,6 @@ RSpec.configure do |c| c.facterdb_string_keys = false - c.mock_with :mocha end add_mocked_facts! diff --git a/spec/unit/provider/alternatives/chkconfig_spec.rb b/spec/unit/provider/alternatives/chkconfig_spec.rb index b2cfd6d..f3cbc1f 100644 --- a/spec/unit/provider/alternatives/chkconfig_spec.rb +++ b/spec/unit/provider/alternatives/chkconfig_spec.rb @@ -24,9 +24,9 @@ def my_fixture_read(type, path) describe '.all' do it 'List all alternatives in folder /var/lib/alternatives' do - described_class.expects(:list_alternatives).returns my_fixture_alternatives - described_class.expects(:update).with('--display', 'sample').returns my_fixture_read('display', 'sample') - described_class.expects(:update).with('--display', 'testcmd').returns my_fixture_read('display', 'testcmd') + expect(described_class).to receive(:list_alternatives).and_return(my_fixture_alternatives) + expect(described_class).to receive(:update).with('--display', 'sample').and_return(my_fixture_read('display', 'sample')) + expect(described_class).to receive(:update).with('--display', 'testcmd').and_return(my_fixture_read('display', 'testcmd')) described_class.all end @@ -34,9 +34,9 @@ def my_fixture_read(type, path) subject { described_class.all } before do - described_class.stubs(:list_alternatives).returns my_fixture_alternatives - described_class.stubs(:update).with('--display', 'sample').returns my_fixture_read('display', 'sample') - described_class.stubs(:update).with('--display', 'testcmd').returns my_fixture_read('display', 'testcmd') + allow(described_class).to receive(:list_alternatives).and_return(my_fixture_alternatives) + allow(described_class).to receive(:update).with('--display', 'sample').and_return(my_fixture_read('display', 'sample')) + allow(described_class).to receive(:update).with('--display', 'testcmd').and_return(my_fixture_read('display', 'testcmd')) end it { is_expected.to be_a Hash } @@ -47,8 +47,9 @@ def my_fixture_read(type, path) describe '.instances' do it 'delegates to .all' do - described_class.expects(:all).returns(stub_selections) - described_class.expects(:new).twice.returns(stub) + stub_instance = instance_double(described_class) + expect(described_class).to receive(:all).and_return(stub_selections) + expect(described_class).to receive(:new).twice.and_return(stub_instance) described_class.instances end end @@ -59,11 +60,11 @@ def my_fixture_read(type, path) let(:resource) { Puppet::Type.type(:alternatives).new(name: 'sample') } before do - Puppet::Type.type(:alternatives).stubs(:defaultprovider).returns described_class - described_class.stubs(:update).with('--display', 'sample').returns my_fixture_read('display', 'sample') - described_class.stubs(:update).with('--display', 'testcmd').returns my_fixture_read('display', 'testcmd') + allow(Puppet::Type.type(:alternatives)).to receive(:defaultprovider).and_return(described_class) + allow(described_class).to receive(:update).with('--display', 'sample').and_return(my_fixture_read('display', 'sample')) + allow(described_class).to receive(:update).with('--display', 'testcmd').and_return(my_fixture_read('display', 'testcmd')) resource.provider = subject - described_class.stubs(:all).returns(stub_selections) + allow(described_class).to receive(:all).and_return(stub_selections) end it '#path retrieves the path from class.all' do @@ -71,18 +72,18 @@ def my_fixture_read(type, path) end it '#path= updates the path with alternatives --set' do - subject.expects(:update).with('--set', 'sample', '/opt/sample1') + expect(subject).to receive(:update).with('--set', 'sample', '/opt/sample1') subject.path = '/opt/sample1' end it '#mode=(:auto) calls alternatives --auto' do - subject.expects(:update).with('--auto', 'sample') + expect(subject).to receive(:update).with('--auto', 'sample') subject.mode = :auto end it '#mode=(:manual) calls alternatives --set with current value' do - subject.expects(:path).returns('/opt/sample2') - subject.expects(:update).with('--set', 'sample', '/opt/sample2') + expect(subject).to receive(:path).and_return('/opt/sample2') + expect(subject).to receive(:update).with('--set', 'sample', '/opt/sample2') subject.mode = :manual end end diff --git a/spec/unit/provider/alternatives/dpkg_spec.rb b/spec/unit/provider/alternatives/dpkg_spec.rb index 78877bb..ba4cac5 100644 --- a/spec/unit/provider/alternatives/dpkg_spec.rb +++ b/spec/unit/provider/alternatives/dpkg_spec.rb @@ -20,7 +20,7 @@ def my_fixture_read(path) describe '.all' do it 'calls update-alternatives --get-selections' do - described_class.expects(:update).with('--get-selections').returns my_fixture_read('get-selections') + expect(described_class).to receive(:update).with('--get-selections').and_return(my_fixture_read('get-selections')) described_class.all end @@ -28,7 +28,7 @@ def my_fixture_read(path) subject { described_class.all } before do - described_class.stubs(:update).with('--get-selections').returns my_fixture_read('get-selections') + allow(described_class).to receive(:update).with('--get-selections').and_return(my_fixture_read('get-selections')) end it { is_expected.to be_a Hash } @@ -39,8 +39,9 @@ def my_fixture_read(path) describe '.instances' do it 'delegates to .all' do - described_class.expects(:all).returns(stub_selections) - described_class.expects(:new).twice.returns(stub) + stub_instance = instance_double(described_class) + expect(described_class).to receive(:all).and_return(stub_selections) + expect(described_class).to receive(:new).twice.and_return(stub_instance) described_class.instances end end @@ -51,9 +52,9 @@ def my_fixture_read(path) let(:resource) { Puppet::Type.type(:alternatives).new(name: 'editor') } before do - Puppet::Type.type(:alternatives).stubs(:defaultprovider).returns described_class + allow(Puppet::Type.type(:alternatives)).to receive(:defaultprovider).and_return(described_class) resource.provider = subject - described_class.stubs(:all).returns(stub_selections) + allow(described_class).to receive(:all).and_return(stub_selections) end it '#path retrieves the path from class.all' do @@ -61,18 +62,18 @@ def my_fixture_read(path) end it '#path= updates the path with update-alternatives --set' do - subject.expects(:update).with('--set', 'editor', '/bin/nano') + expect(subject).to receive(:update).with('--set', 'editor', '/bin/nano') subject.path = '/bin/nano' end it '#mode=(:auto) calls update-alternatives --auto' do - subject.expects(:update).with('--auto', 'editor') + expect(subject).to receive(:update).with('--auto', 'editor') subject.mode = :auto end it '#mode=(:manual) calls update-alternatives --set with current value' do - subject.expects(:path).returns('/usr/bin/vim.tiny') - subject.expects(:update).with('--set', 'editor', '/usr/bin/vim.tiny') + expect(subject).to receive(:path).and_return('/usr/bin/vim.tiny') + expect(subject).to receive(:update).with('--set', 'editor', '/usr/bin/vim.tiny') subject.mode = :manual end end diff --git a/spec/unit/type/alternatives_spec.rb b/spec/unit/type/alternatives_spec.rb index 2fe23d3..7de55e2 100644 --- a/spec/unit/type/alternatives_spec.rb +++ b/spec/unit/type/alternatives_spec.rb @@ -6,7 +6,7 @@ describe 'property `path`' do context 'on Debian systems' do before do - Facter.stubs(:value).with('os.family').returns('Debian') + allow(Facter).to receive(:value).with('os.family').and_return('Debian') end it 'passes validation with an absolute path' do @@ -20,7 +20,7 @@ context 'on RedHat systems' do before do - Facter.stubs(:value).with('os.family').returns('RedHat') + allow(Facter).to receive(:value).with('os.family').and_return('RedHat') end it 'passes validation with an absolute path' do