Skip to content

RuboCop::Cop::Airbnb::ModuleMethodInWrongFile returns incorrect error message when defining a method inside singleton class #190

Open
@RenzoMinelli

Description

@RenzoMinelli

When developing PR #189, tests were changed to use new rspec-rubocop syntax which also checks that the message generated is correct. After doing this, the spec that checks that an error is returned when using "<<" static methods and a non-matching name failed with an incorrect message:

Method baz should be defined in foo/foo.rb

When the expected message was:

Method baz should be defined in foo.rb

After digging a little about it to understand what was happening, we realized that this incorrect message is also present on master – but there are no assertions respecting the offense's text, thus the test succeeds.
The issue seems to be caused by the method normalize_module_name(node.parent_module_name) (on module_method_in_wrong_file.rb#L88) which returns Foo::Foo instead of just Foo.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions