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

Add a cop to enforce aggregating examples #726

Closed
wants to merge 56 commits into from

Commits on Apr 24, 2019

  1. Add a cop to enforce aggregating examples

    The "one expectation per example" rule has been relaxed and allows for
    several expectations to be set in the same example.
    https://github.com/rubocop-hq/rspec-style-guide#expectations-per-example
    
    In cases the examples don't have any setup, metadata, or even a
    docstring, and may be aggregated into one thus saving on sometimes
    expensive context setup.
    
    The cop still does report the cases when the examples might be
    aggregated, but with some risk, e.g. when matchers with side effects are
    used. It makes sense to do so, since eventually those matchers might be
    fixed to leave the subject in its original state.
    
    Block expectation syntax is deliberately not supported due to:
     - `subject { -> { ... } }` syntax being hard to detect
     - aggregation should use composition with `.and`
     - aggregation of the `not_to` is barely possible when a matcher doesn't
     provide a negated variant
     - aggregation of block syntax with non-block syntax should be in a
     specific order
    
    Known caveats:
    The usages if `its` that are testing private methods/readers will result
    in spec failure. It's up to the user whether to replace with `__send__`,
    or test only public interface.
    
    Original idea and initial implementation:
    https://github.com/palkan/test-prof/blob/master/lib/test_prof/cops/rspec/aggregate_failures.rb
    pirj committed Apr 24, 2019
    Configuration menu
    Copy the full SHA
    916eb9b View commit details
    Browse the repository at this point in the history
  2. Clarify the purpose of the cop

    pirj committed Apr 24, 2019
    Configuration menu
    Copy the full SHA
    4ad3e68 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    4aa83a9 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    0adfd01 View commit details
    Browse the repository at this point in the history
  5. Use Language module

    pirj committed Apr 24, 2019
    Configuration menu
    Copy the full SHA
    e2a5b18 View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    a9b2983 View commit details
    Browse the repository at this point in the history
  7. Simplify heredoc detection

    pirj committed Apr 24, 2019
    Configuration menu
    Copy the full SHA
    5e3a001 View commit details
    Browse the repository at this point in the history
  8. Update manual

    pirj committed Apr 24, 2019
    Configuration menu
    Copy the full SHA
    b2c86c1 View commit details
    Browse the repository at this point in the history
  9. Fix docstring

    pirj committed Apr 24, 2019
    Configuration menu
    Copy the full SHA
    3a756e2 View commit details
    Browse the repository at this point in the history
  10. Configuration menu
    Copy the full SHA
    00f99ce View commit details
    Browse the repository at this point in the history
  11. Configuration menu
    Copy the full SHA
    e32b9a6 View commit details
    Browse the repository at this point in the history
  12. Configuration menu
    Copy the full SHA
    4dad154 View commit details
    Browse the repository at this point in the history
  13. Fix documentation issues

    pirj committed Apr 24, 2019
    Configuration menu
    Copy the full SHA
    dd47c96 View commit details
    Browse the repository at this point in the history
  14. fixup! Fix doc formatting

    pirj committed Apr 24, 2019
    Configuration menu
    Copy the full SHA
    9928939 View commit details
    Browse the repository at this point in the history
  15. Configuration menu
    Copy the full SHA
    b9de045 View commit details
    Browse the repository at this point in the history
  16. Configuration menu
    Copy the full SHA
    3d5f62a View commit details
    Browse the repository at this point in the history
  17. Configuration menu
    Copy the full SHA
    9655c29 View commit details
    Browse the repository at this point in the history
  18. Configuration menu
    Copy the full SHA
    b2d5e60 View commit details
    Browse the repository at this point in the history
  19. fixup! Fix typo

    pirj committed Apr 24, 2019
    Configuration menu
    Copy the full SHA
    ef3382a View commit details
    Browse the repository at this point in the history
  20. Apply suggestions from code review

    Improve wording, fix punctuation errors.
    
    Co-Authored-By: pirj <pirj@users.noreply.github.com>
    bquorning and pirj committed Apr 24, 2019
    Configuration menu
    Copy the full SHA
    0c04a79 View commit details
    Browse the repository at this point in the history
  21. Get rid of a shared example

    pirj committed Apr 24, 2019
    Configuration menu
    Copy the full SHA
    e394a6a View commit details
    Browse the repository at this point in the history
  22. Configuration menu
    Copy the full SHA
    a7510b9 View commit details
    Browse the repository at this point in the history
  23. Configuration menu
    Copy the full SHA
    46553f1 View commit details
    Browse the repository at this point in the history
  24. Configuration menu
    Copy the full SHA
    458fbf3 View commit details
    Browse the repository at this point in the history
  25. Configuration menu
    Copy the full SHA
    81c81c1 View commit details
    Browse the repository at this point in the history
  26. Configuration menu
    Copy the full SHA
    1e740ab View commit details
    Browse the repository at this point in the history
  27. Configuration menu
    Copy the full SHA
    318c77c View commit details
    Browse the repository at this point in the history
  28. Configuration menu
    Copy the full SHA
    8906bf3 View commit details
    Browse the repository at this point in the history
  29. Configuration menu
    Copy the full SHA
    2a93dfd View commit details
    Browse the repository at this point in the history
  30. Remove excessive test coverage

    pirj committed Apr 24, 2019
    Configuration menu
    Copy the full SHA
    4b0b0cc View commit details
    Browse the repository at this point in the history
  31. Configuration menu
    Copy the full SHA
    367c7a6 View commit details
    Browse the repository at this point in the history
  32. Configuration menu
    Copy the full SHA
    536fb90 View commit details
    Browse the repository at this point in the history
  33. Configuration menu
    Copy the full SHA
    5745c03 View commit details
    Browse the repository at this point in the history
  34. Remove excessive test coverage

    pirj committed Apr 24, 2019
    Configuration menu
    Copy the full SHA
    df23cf5 View commit details
    Browse the repository at this point in the history
  35. Configuration menu
    Copy the full SHA
    3522224 View commit details
    Browse the repository at this point in the history
  36. Configuration menu
    Copy the full SHA
    c38d4f6 View commit details
    Browse the repository at this point in the history
  37. Remove redundant docstring

    pirj committed Apr 24, 2019
    Configuration menu
    Copy the full SHA
    c0f67ec View commit details
    Browse the repository at this point in the history
  38. Extract its support to a module

    pirj committed Apr 24, 2019
    Configuration menu
    Copy the full SHA
    a1ebfad View commit details
    Browse the repository at this point in the history
  39. Configuration menu
    Copy the full SHA
    0263d7f View commit details
    Browse the repository at this point in the history
  40. Configuration menu
    Copy the full SHA
    3e0fbfc View commit details
    Browse the repository at this point in the history
  41. Configuration menu
    Copy the full SHA
    30e3463 View commit details
    Browse the repository at this point in the history
  42. Configuration menu
    Copy the full SHA
    b133213 View commit details
    Browse the repository at this point in the history
  43. Extract metadata and line ranges

    pirj committed Apr 24, 2019
    Configuration menu
    Copy the full SHA
    38b1e73 View commit details
    Browse the repository at this point in the history
  44. Simplify node pattern

    pirj committed Apr 24, 2019
    Configuration menu
    Copy the full SHA
    82df911 View commit details
    Browse the repository at this point in the history
  45. Detect side effect matcher with qualifiers

    Matchers with side effects with qualifiers were still aggregated, e.g.:
    
        is_expected.to allow_value('green').for(:color)
    pirj committed Apr 24, 2019
    Configuration menu
    Copy the full SHA
    9d613a7 View commit details
    Browse the repository at this point in the history
  46. Do not pretend to correct uncorrectable offenses

    Previously, auto-correct run pretended it corrected the offenses, even
    though they were not.
    pirj committed Apr 24, 2019
    Configuration menu
    Copy the full SHA
    aa2fd4a View commit details
    Browse the repository at this point in the history
  47. Configuration menu
    Copy the full SHA
    0237824 View commit details
    Browse the repository at this point in the history
  48. Fix spelling mistake

    pirj committed Apr 24, 2019
    Configuration menu
    Copy the full SHA
    d6c2c37 View commit details
    Browse the repository at this point in the history
  49. [DO NOT SQUASH] Add support for adding docs from modules

    Due to yard's override of docs when the docs are defined in several
    files for the same class ([see this
    issue](lsegal/yard#1173)), it's impossible to
    spread the docs to several files so that they are compiled into one
    document (e.g. a manual).
    
    Comparison using:
    
        RuboCop::Cop::Badge.for(code_object.to_s) == cop.badge
    
    makes it impossible to put the docs on the included module level without
    filtering out those modules for which a badge can't be inferred, because
    `RuboCop::Cop::Badge.for` raises an error.
    pirj committed Apr 24, 2019
    Configuration menu
    Copy the full SHA
    9e00508 View commit details
    Browse the repository at this point in the history
  50. Configuration menu
    Copy the full SHA
    f1c0a23 View commit details
    Browse the repository at this point in the history
  51. Configuration menu
    Copy the full SHA
    ad16b40 View commit details
    Browse the repository at this point in the history
  52. Configuration menu
    Copy the full SHA
    abe9f0e View commit details
    Browse the repository at this point in the history
  53. Configuration menu
    Copy the full SHA
    2bba4e4 View commit details
    Browse the repository at this point in the history
  54. Extract aggregation logic

    pirj committed Apr 24, 2019
    Configuration menu
    Copy the full SHA
    6c3afc1 View commit details
    Browse the repository at this point in the history
  55. Add code documentation

    pirj committed Apr 24, 2019
    Configuration menu
    Copy the full SHA
    a5542f5 View commit details
    Browse the repository at this point in the history
  56. Configuration menu
    Copy the full SHA
    bfbe3f2 View commit details
    Browse the repository at this point in the history