Skip to content

Commit

Permalink
Merge pull request #283 from bastelfreak/rubocop2
Browse files Browse the repository at this point in the history
RuboCop: Fix RSpec/DescribedClass
  • Loading branch information
bastelfreak authored May 17, 2024
2 parents c0279e4 + 87768e0 commit 8d315d2
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 61 deletions.
14 changes: 0 additions & 14 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,6 @@ RSpec/ContextWording:
- 'spec/unit/module_sync/git_service/gitlab_spec.rb'
- 'spec/unit/module_sync_spec.rb'

# Offense count: 17
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: SkipBlocks, EnforcedStyle, OnlyStaticConstants.
# SupportedStyles: described_class, explicit
RSpec/DescribedClass:
Exclude:
- 'spec/unit/module_sync/git_service/factory_spec.rb'
- 'spec/unit/module_sync/git_service/github_spec.rb'
- 'spec/unit/module_sync/git_service/gitlab_spec.rb'
- 'spec/unit/module_sync/git_service_spec.rb'
- 'spec/unit/module_sync/settings_spec.rb'
- 'spec/unit/module_sync/source_code_spec.rb'
- 'spec/unit/module_sync_spec.rb'

# Offense count: 11
# Configuration parameters: CountAsOne.
RSpec/ExampleLength:
Expand Down
6 changes: 2 additions & 4 deletions spec/unit/module_sync/git_service/factory_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@
context 'when instantiate a GitHub service without credentials' do
it 'raises an error' do
expect do
ModuleSync::GitService::Factory.instantiate(type: :github, endpoint: nil,
token: nil)
described_class.instantiate(type: :github, endpoint: nil, token: nil)
end.to raise_error(ModuleSync::GitService::MissingCredentialsError)
end
end

context 'when instantiate a GitLab service without credentials' do
it 'raises an error' do
expect do
ModuleSync::GitService::Factory.instantiate(type: :gitlab, endpoint: nil,
token: nil)
described_class.instantiate(type: :gitlab, endpoint: nil, token: nil)
end.to raise_error(ModuleSync::GitService::MissingCredentialsError)
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/module_sync/git_service/github_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
before do
@client = double
allow(Octokit::Client).to receive(:new).and_return(@client)
@it = ModuleSync::GitService::GitHub.new('test', 'https://api.github.com')
@it = described_class.new('test', 'https://api.github.com')
end

let(:args) do
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/module_sync/git_service/gitlab_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
before do
@client = double
allow(Gitlab::Client).to receive(:new).and_return(@client)
@it = ModuleSync::GitService::GitLab.new('test', 'https://gitlab.com/api/v4')
@it = described_class.new('test', 'https://gitlab.com/api/v4')
end

let(:args) do
Expand Down
72 changes: 36 additions & 36 deletions spec/unit/module_sync/git_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
end

it 'build git service arguments from configuration entry' do
expect(ModuleSync::GitService.configuration_for(sourcecode: sourcecode)).to eq({
type: :gitlab,
endpoint: 'https://vcs.example.com/api/v4',
token: 'secret',
})
expect(described_class.configuration_for(sourcecode: sourcecode)).to eq({
type: :gitlab,
endpoint: 'https://vcs.example.com/api/v4',
token: 'secret',
})
end
end

Expand All @@ -55,11 +55,11 @@
.with('GITLAB_TOKEN')
.and_return('secret')

expect(ModuleSync::GitService.configuration_for(sourcecode: sourcecode)).to eq({
type: :gitlab,
endpoint: 'https://vcs.example.com/api/v4',
token: 'secret',
})
expect(described_class.configuration_for(sourcecode: sourcecode)).to eq({
type: :gitlab,
endpoint: 'https://vcs.example.com/api/v4',
token: 'secret',
})
end
end

Expand All @@ -69,21 +69,21 @@
.with('GITLAB_TOKEN')
.and_return('secret')

expect(ModuleSync::GitService.configuration_for(sourcecode: sourcecode)).to eq({
type: :gitlab,
endpoint: 'https://git.example.com/api/v4',
token: 'secret',
})
expect(described_class.configuration_for(sourcecode: sourcecode)).to eq({
type: :gitlab,
endpoint: 'https://git.example.com/api/v4',
token: 'secret',
})
end
end

context 'without any environment variable sets' do
it 'returns a nil token' do
expect(ModuleSync::GitService.configuration_for(sourcecode: sourcecode)).to eq({
type: :gitlab,
endpoint: 'https://git.example.com/api/v4',
token: nil,
})
expect(described_class.configuration_for(sourcecode: sourcecode)).to eq({
type: :gitlab,
endpoint: 'https://git.example.com/api/v4',
token: nil,
})
end
end
end
Expand All @@ -102,21 +102,21 @@
.with('GITLAB_TOKEN')
.and_return('secret')

expect(ModuleSync::GitService.configuration_for(sourcecode: sourcecode)).to eq({
type: :gitlab,
endpoint: 'https://gitlab.example.com/api/v4',
token: 'secret',
})
expect(described_class.configuration_for(sourcecode: sourcecode)).to eq({
type: :gitlab,
endpoint: 'https://gitlab.example.com/api/v4',
token: 'secret',
})
end
end

context 'without a GITLAB_TOKEN environment variable sets' do
it 'returns a nil token' do
expect(ModuleSync::GitService.configuration_for(sourcecode: sourcecode)).to eq({
type: :gitlab,
endpoint: 'https://gitlab.example.com/api/v4',
token: nil,
})
expect(described_class.configuration_for(sourcecode: sourcecode)).to eq({
type: :gitlab,
endpoint: 'https://gitlab.example.com/api/v4',
token: nil,
})
end
end
end
Expand All @@ -134,11 +134,11 @@
.with('GITHUB_TOKEN')
.and_return('secret')

expect(ModuleSync::GitService.configuration_for(sourcecode: sourcecode)).to eq({
type: :github,
endpoint: 'https://vcs.example.com',
token: 'secret',
})
expect(described_class.configuration_for(sourcecode: sourcecode)).to eq({
type: :github,
endpoint: 'https://vcs.example.com',
token: 'secret',
})
end
end

Expand All @@ -152,7 +152,7 @@
.with('GITLAB_TOKEN')
.and_return('secret')

expect { ModuleSync::GitService.configuration_for(sourcecode: sourcecode) }
expect { described_class.configuration_for(sourcecode: sourcecode) }
.to raise_error ModuleSync::Error
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/module_sync/settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe ModuleSync::Settings do
subject do
ModuleSync::Settings.new(
described_class.new(
{},
{},
{},
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/module_sync/source_code_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe ModuleSync::SourceCode do
subject do
ModuleSync::SourceCode.new('namespace/name', nil)
described_class.new('namespace/name', nil)
end

before do
Expand Down
6 changes: 3 additions & 3 deletions spec/unit/module_sync_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
describe ModuleSync do
context '::update' do
it 'loads the managed modules from the specified :managed_modules_conf' do
allow(ModuleSync).to receive(:find_template_files).and_return([])
allow(described_class).to receive(:find_template_files).and_return([])
allow(ModuleSync::Util).to receive(:parse_config).with('./config_defaults.yml').and_return({})
expect(ModuleSync).to receive(:managed_modules).with(no_args).and_return([])
expect(described_class).to receive(:managed_modules).with(no_args).and_return([])

options = { managed_modules_conf: 'test_file.yml' }
ModuleSync.update(options)
described_class.update(options)
end
end
end

0 comments on commit 8d315d2

Please sign in to comment.