Skip to content
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 .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
---
inherit_from: .rubocop_todo.yml

# Managed by modulesync - DO NOT EDIT
# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/

Expand Down
25 changes: 25 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -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'
6 changes: 0 additions & 6 deletions .sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,3 @@
enabled_lint_checks:
- parameter_documentation
- parameter_types
Gemfile:
optional:
':test':
- gem: 'mocha'
spec/spec_helper.rb:
mock_with: ':mocha'
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

RSpec.configure do |c|
c.facterdb_string_keys = false
c.mock_with :mocha
end

add_mocked_facts!
Expand Down
33 changes: 17 additions & 16 deletions spec/unit/provider/alternatives/chkconfig_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ 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

describe 'returning data' do
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 }
Expand All @@ -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
Expand All @@ -59,30 +60,30 @@ 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
expect(subject.path).to eq('/opt/sample1')
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
Expand Down
21 changes: 11 additions & 10 deletions spec/unit/provider/alternatives/dpkg_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ 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

describe 'returning data' do
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 }
Expand All @@ -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
Expand All @@ -51,28 +52,28 @@ 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
expect(subject.path).to eq('/usr/bin/vim.tiny')
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
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/type/alternatives_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading