rubocop / minitest-style-guide

Best practices for writing your tests
https://minitest.rubystyle.guide
70 stars 15 forks source link

[Fix #25] Add global expectations rule #28

Closed koic closed 4 years ago

koic commented 4 years ago

Fixes #25.

This PR adds global expectations rule.

It separates the problems solved by The Style Guide and RuboCop Minitest respectively.

The Minitest Style Guide

This will be already solved by https://github.com/rubocop-hq/rubocop-minitest/pull/63.

# bad
(1+1).must_equal 2

# good
_(1 + 1).must_equal 2
value(1 + 1).must_equal 2
expect(1 + 1).must_equal 2

RuboCop Minitest

This will be implemented as a different Minitest cop than https://github.com/rubocop-hq/rubocop-minitest/pull/63.

# default
_(1 + 1).must_equal 2      # good
value(1 + 1).must_equal 2  # bad
expect(1 + 1).must_equal 2 # bad

# optional (value)
_(1 + 1).must_equal 2      # bad
value(1 + 1).must_equal 2  # good
expect(1 + 1).must_equal 2 # bad

# optional (expect)
_(1 + 1).must_equal 2      # bad
value(1 + 1).must_equal 2  # bad
expect(1 + 1).must_equal 2 # good

This PR focuses on the issues that The Style Guide should solve.

bbatsov commented 4 years ago

Seems reasonable to me. I think that the old behaviour is also deprecated/scheduled for removal.

Might also be a good idea to link to some upstream docs in the guideline and to suggest in another rule what people should use by default expect/value/_. I'm not sure which is the most popular, but I'm sure consistency is important.

koic commented 4 years ago

Thank you for the review. I've updated this PR. In this PR, I'd like to add the rule to prevent deprecated methods, first.

bbatsov commented 4 years ago

Thanks!