-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Tim Smith <tsmith@chef.io>
- Loading branch information
Showing
7 changed files
with
137 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
spec/rubocop/cop/chef/ruby/ruby_27_keyword_argument_warnings_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# frozen_string_literal: true | ||
# | ||
# Copyright:: Chef Software, Inc. | ||
# Author:: Tim Smith (<tsmith@chef.io>) | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
require "spec_helper" | ||
|
||
describe RuboCop::Cop::Chef::ChefRuby::Ruby27KeywordArgumentWarnings, :config do | ||
subject(:cop) { described_class.new(config) } | ||
|
||
it "registers an offense when passing a hash with brackets to shell_out" do | ||
expect_offense(<<~RUBY) | ||
shell_out('hostnamectl status', {returns: [0, 1]}) | ||
^^^^^^^^^^^^^^^^^ Pass options to shell_out helpers without the brackets to avoid Ruby 2.7 deprecation warnings. | ||
RUBY | ||
|
||
expect_correction(<<~RUBY) | ||
shell_out('hostnamectl status', returns: [0, 1]) | ||
RUBY | ||
end | ||
|
||
it "registers an offense when passing a hash with brackets to shell_out!" do | ||
expect_offense(<<~RUBY) | ||
shell_out!('hostnamectl status', {returns: [0, 1]}) | ||
^^^^^^^^^^^^^^^^^ Pass options to shell_out helpers without the brackets to avoid Ruby 2.7 deprecation warnings. | ||
RUBY | ||
|
||
expect_correction(<<~RUBY) | ||
shell_out!('hostnamectl status', returns: [0, 1]) | ||
RUBY | ||
end | ||
|
||
it "doesn't register an offense when properly passing options to the helpers" do | ||
expect_no_offenses("shell_out!('hostnamectl status', returns: [0, 1])") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
RSpec.shared_examples "autocorrect" do |original, corrected| | ||
it "autocorrects `#{original}` to `#{corrected}`" do | ||
autocorrected = autocorrect_source(original, "spec/foo_spec.rb") | ||
|
||
expect(autocorrected).to eql(corrected) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
require "rubocop" | ||
require "rubocop/rspec/support" | ||
|
||
module SpecHelper | ||
ROOT = Pathname.new(__dir__).parent.freeze | ||
end | ||
|
||
spec_helper_glob = File.expand_path("{support,shared}/*.rb", __dir__) | ||
Dir.glob(spec_helper_glob).map(&method(:require)) | ||
|
||
RSpec.configure do |config| | ||
# Basic configuration | ||
config.run_all_when_everything_filtered = true | ||
config.filter_run(:focus) | ||
config.order = :random | ||
|
||
config.include RuboCop::RSpec::ExpectOffense | ||
end | ||
|
||
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib")) | ||
$LOAD_PATH.unshift(File.dirname(__FILE__)) | ||
|
||
require "chefstyle" |