Skip to content

Commit

Permalink
Fix an error for Minitst/AssertOperator and Minitest/RefuteOperator
Browse files Browse the repository at this point in the history
This PR fixes the following error for `Minitst/AssertOperator` and `Minitest/RefuteOperator`
when running with Ruby 2.7:

```console
$ ruby -v
ruby 2.7.8p225 (2023-03-30 revision 1f4d455848) [x86_64-darwin19]

$ bundle exec rake

Finished in 2.522134s, 15.0666 runs/s, 18.6350 assertions/s.

  1) Error: RefuteOperatorTest#test_registers_offense_when_using_refute_with_operator_method_and_message:
FrozenError: can't modify frozen String: "expected, :<, actual"
    /Users/koic/src/github.com/rubocop/rubocop-minitest/lib/rubocop/cop/minitest/refute_operator.rb:46:
    in `build_new_arguments'
    /Users/koic/src/github.com/rubocop/rubocop-minitest/lib/rubocop/cop/minitest/refute_operator.rb:30:
    in `on_send'
```

And it introduces CI for the oldest RuboCop version still supported,
implementing a workflow for regression testing that is similar to the one found a
rubocop/rubocop-rails@c9acb7a.
  • Loading branch information
koic committed Nov 23, 2023
1 parent 0b26645 commit 7c9e66e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: CI

on:
push:
branches:
- master
pull_request:
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
oldest_supported_rubocop:
runs-on: ubuntu-latest
name: The oldest supported RuboCop version
steps:
- uses: actions/checkout@v4
- name: Use the oldest supported RuboCop
run: |
sed -e "/gem 'rubocop', github: 'rubocop\/rubocop'/d" \
-e "/gem 'rubocop-performance',/d" -i Gemfile
cat << EOF > Gemfile.local
gem 'rubocop', '1.39.0' # Specify the oldest supported RuboCop version
EOF
- name: set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7
bundler-cache: true
- name: test
run: bundle exec rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* [#275](https://github.com/rubocop/rubocop-minitest/issues/275): Make `Minitest/AssertMatch` aware of `assert_operator`
when running with Ruby 2.7. ([@koic][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/minitest/assert_operator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def on_send(node)

def build_new_arguments(node)
lhs, op, rhs = *node.first_argument
new_arguments = "#{lhs.source}, :#{op}, #{rhs.source}"
new_arguments = +"#{lhs.source}, :#{op}, #{rhs.source}"

if node.arguments.count == 2
new_arguments << ", #{node.last_argument.source}"
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/minitest/refute_operator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def on_send(node)

def build_new_arguments(node)
lhs, op, rhs = *node.first_argument
new_arguments = "#{lhs.source}, :#{op}, #{rhs.source}"
new_arguments = +"#{lhs.source}, :#{op}, #{rhs.source}"

if node.arguments.count == 2
new_arguments << ", #{node.last_argument.source}"
Expand Down

0 comments on commit 7c9e66e

Please sign in to comment.