Skip to content

Commit

Permalink
Suppress method redefinition warnings
Browse files Browse the repository at this point in the history
- When running with `$VERBOSE` set to `true`, rspectre generates a very large # of warnings.
  • Loading branch information
dgollahon committed May 13, 2023
1 parent cc174a0 commit 66c4a17
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
2 changes: 2 additions & 0 deletions lib/rspectre/linter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def self.record(node)
def self.prepend_behavior(scope, method_name)
original_method = scope.instance_method(method_name)

# Removing the method first prevents method redefined warnings when $VERBOSE is true
scope.remove_method(method_name)
scope.__send__(:define_method, method_name) do |*args, **kwargs, &block|
yield

Expand Down
2 changes: 2 additions & 0 deletions spec/shared/highlighted_offenses.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ def expected_offenses(source, spec_file)

expect(offense.description).to eql(description)
end

expect(stderr.empty?).to be(true), 'There was unexpected output to STDERR!'
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/shared/rspectre_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def run_rspectre(source)

output =
Dir.chdir(File.dirname(spec_file.path)) do
Open3.capture3("#{rspectre_path} --rspec #{spec_file.path}")
Open3.capture3("RUBYOPT='--verbose' #{rspectre_path} --rspec #{spec_file.path}")
end

yield([output, spec_file])
Expand Down
4 changes: 2 additions & 2 deletions spec/unused_let_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
let(:unused_binary) { "\\xff".b }
^^^^^^^^^^^^^^^^^^^ UnusedLet: Unused `let` definition.
let(:unused_compound) { 1 + 1; 'noop' }
let(:unused_compound) { foo; 'noop' }
^^^^^^^^^^^^^^^^^^^^^ UnusedLet: Unused `let` definition.
let(
Expand All @@ -26,7 +26,7 @@
let(:unused_multiline_compound) do
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UnusedLet: Unused `let` definition.
'doop'
foo
'noop'
end
Expand Down

0 comments on commit 66c4a17

Please sign in to comment.