Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix specs for code transparently fixed with RuboCop 0.84 update #914

Merged
merged 4 commits into from May 24, 2020

Conversation

pirj
Copy link
Member

@pirj pirj commented May 21, 2020

It seems that RuboCop comes with certain fixes that improve how RuboCop RSpec itself works!


Before submitting the PR make sure the following are checked:

  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • [-] Updated documentation.
  • [-] Added an entry to the changelog if the new code introduces user-observable changes.
  • The build (bundle exec rake) passes (be sure to run this locally, since it may produce updated documentation that you will need to commit).

It seems that RuboCop comes with certain fixes that improve how RuboCop
RSpec works!
@pirj pirj self-assigned this May 21, 2020
expect_offense(<<-RUBY)
it do
foo = double
^^^^^^ Prefer using verifying doubles over normal doubles.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's quite strange how it worked like that, since IgnoreNameless: true by default.
Nice, it's fixed now.

This gives me an interesting thought, since on the one hand, it's a bug fix, and on the other, it's a change in behaviour. But we're unable to "protect" our users from that change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps cop_config was not merged with the default values?
Anyway, it's better to have the values explicitly set in specs and not rely on defaults

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly. Previously – before rubocop/rubocop#7970 – the default configuration was not present when testing. And it is now, so we can simplify a lot of our test.

I was too working on fixing our specs (and applied the exact same changes to spec/rubocop/cop/rspec/verified_doubles_spec.rb) and have taken the liberty of adding a few commits to your branch. I hope that is ok with you @pirj

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is such a wonderful idea. I recall it was discussed before, and so good it's now in place.

is ok with you

Of course, nice cleanup!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mention in the commit message of 4e7272b that the change in RuboCop actually introduces a “mystery guest”, which could be considered a code smell.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything works and looks nice. Do you have something else in mind tbd here, or is it good to merge?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we‘re good to merge.

@pirj pirj requested review from bquorning and Darhazer May 23, 2020 22:19
expect_offense(<<-RUBY)
it do
foo = double
^^^^^^ Prefer using verifying doubles over normal doubles.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps cop_config was not merged with the default values?
Anyway, it's better to have the values explicitly set in specs and not rely on defaults

After rubocop/rubocop#7970, all specs with
the `:config` metadata by default use the default configuration. So now,
there is often no reason to add a cop's default configuration in specs.
In rubocop/rubocop#7970 the shared context
`config` was updated to include the following:

    let(:cop) do
      cop_class.new(config, cop_options)
               .tap { |cop| cop.processed_source = processed_source }
    end

This is functionally equivalent to what we have all over our specs:

    subject(:cop) { described_class.new(config) }

The downside is that our specs become a less explicit. Actually they now
have a mystery guest, which may be considered a smell.
There is no longer by default a "when configuration is empty" situation
to test. We always have the default configuration when testing.

The existing tests ("should only fail" -> "onlies fail") did not add
much value.
@pirj pirj merged commit d87cbcc into master May 24, 2020
@pirj pirj deleted the fix-edge-rubocop-0.84-offences-2 branch May 24, 2020 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants