forked from rodjek/puppet-lint
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix
Ensure check methods can't modify tokens array
The functionality originally released in rodjek#296 was probably broken at the time, possibly made worse by later rubocop 'fixes' and also incompatible with ruby 3.4. We now look at the stack trace only from the `tokens` wrapper method in `checkplugin`. Fixes #225
- Loading branch information
1 parent
002f275
commit ff0337e
Showing
5 changed files
with
46 additions
and
28 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
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,36 @@ | ||
require 'spec_helper' | ||
|
||
class DummyCheckPlugin < PuppetLint::CheckPlugin | ||
def check | ||
# Since we're calling `tokens` from a `check` method, we should get our own Array object. | ||
# If we add an extra token to it, PuppetLint::Data.tokens should remain unchanged. | ||
tokens << :extra_token | ||
end | ||
|
||
def fix | ||
tokens << :fix_token | ||
end | ||
end | ||
|
||
describe PuppetLint::CheckPlugin do | ||
before(:each) do | ||
PuppetLint::Data.tokens = [:token1, :token2, :token3] | ||
end | ||
|
||
it 'returns a duplicate of the token array when called from check' do | ||
plugin = DummyCheckPlugin.new | ||
|
||
plugin.check | ||
|
||
# Verify that the global token array remains unchanged. | ||
expect(PuppetLint::Data.tokens).to eq([:token1, :token2, :token3]) | ||
end | ||
|
||
it 'other methods can modify the tokens array' do | ||
plugin = DummyCheckPlugin.new | ||
|
||
plugin.fix | ||
|
||
expect(PuppetLint::Data.tokens).to eq([:token1, :token2, :token3, :fix_token]) | ||
end | ||
end |