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

Shared tests for potential violations (stubbing non-existent/public methods, etc.) #460

Open
wants to merge 63 commits into
base: main
Choose a base branch
from

Commits on Jan 16, 2020

  1. Configuration menu
    Copy the full SHA
    d538675 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    356d967 View commit details
    Browse the repository at this point in the history
  3. configure check only if treatment isn't default

    This allows us to call stub_method_unnecessarily in the default case without a
    treatment
    nitishr committed Jan 16, 2020
    Configuration menu
    Copy the full SHA
    2b58fe2 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    7737927 View commit details
    Browse the repository at this point in the history
  5. Refactor: inline temps

    nitishr committed Jan 16, 2020
    Configuration menu
    Copy the full SHA
    68d6abb View commit details
    Browse the repository at this point in the history
  6. define test class rather than body conditionally

    if RUBY_VERSION < '2.2.0', there's no point defining a test class that
    does just setup and teardown. Instead, let's not define the test class
    at all.
    nitishr committed Jan 16, 2020
    Configuration menu
    Copy the full SHA
    964262c View commit details
    Browse the repository at this point in the history
  7. extract stub_method_on_nil & violation_message

    ... following the same structure and logic as in the case of
    stubbing_method_unnecessarily
    nitishr committed Jan 16, 2020
    Configuration menu
    Copy the full SHA
    d1665a3 View commit details
    Browse the repository at this point in the history
  8. Refactor: inline temp

    nitishr committed Jan 16, 2020
    Configuration menu
    Copy the full SHA
    3ec6ac9 View commit details
    Browse the repository at this point in the history
  9. Configuration menu
    Copy the full SHA
    73f20ec View commit details
    Browse the repository at this point in the history
  10. Refactor:rename method_x->with_potential_violation

    ...to reduce diff between StubbingMethod{Unnecessarily,OnNil}Test to
    prep to extract common module
    nitishr committed Jan 16, 2020
    Configuration menu
    Copy the full SHA
    8c40baf View commit details
    Browse the repository at this point in the history
  11. Refactor: extract block to potential_violation

    ...to furter reduce diff betwee StubbingMethod{Unnecessarily,OnNil}Test
    to prep to extract common module
    nitishr committed Jan 16, 2020
    Configuration menu
    Copy the full SHA
    7c0c807 View commit details
    Browse the repository at this point in the history
  12. Refactor: extract block to configure_violation

    ...to furter reduce diff betwee StubbingMethod{Unnecessarily,OnNil}Test
    to prep to extract common module
    nitishr committed Jan 16, 2020
    Configuration menu
    Copy the full SHA
    34f90ae View commit details
    Browse the repository at this point in the history
  13. Refactor: make test method name truthful

    This seems to have been an artifact of copy-paste
    nitishr committed Jan 16, 2020
    Configuration menu
    Copy the full SHA
    c744731 View commit details
    Browse the repository at this point in the history
  14. extract StubbingWithPotentialViolationSharedTests

    ... pulling up all the identical methods between
    Stubbing{MethodUnnecessarily,Nil}Test
    nitishr committed Jan 16, 2020
    Configuration menu
    Copy the full SHA
    be0831a View commit details
    Browse the repository at this point in the history
  15. Configuration menu
    Copy the full SHA
    d136000 View commit details
    Browse the repository at this point in the history
  16. Configuration menu
    Copy the full SHA
    cfb2d60 View commit details
    Browse the repository at this point in the history
  17. use shared tests in StubbingNonExistentAnyInstanceMethodTest

    We can now start using the 'framework' we've extracted in the form of a
    shared test module customizable via configure_violation,
    potenial_violation and message_on_violation.
    StubbingNonExistentAnyInstanceMethodTest varies only in those 3 things.
    It checks the same things as in the shared module (viz. allow, warn,
    prevent and default).
    nitishr committed Jan 16, 2020
    Configuration menu
    Copy the full SHA
    9071d2a View commit details
    Browse the repository at this point in the history
  18. Configuration menu
    Copy the full SHA
    88e50e4 View commit details
    Browse the repository at this point in the history
  19. use shared tests in StubbingNonExistentClassMethodTest

    ... just as in the case of StubbingNonExistentAnyInstanceMethodTest
    nitishr committed Jan 16, 2020
    Configuration menu
    Copy the full SHA
    451ec0b View commit details
    Browse the repository at this point in the history
  20. use shared tests in StubbingNonExistentInstanceMethodTest

    ... just as in case of StubbingNonExistent{AnyInstance,Class}MethodTest
    nitishr committed Jan 16, 2020
    Configuration menu
    Copy the full SHA
    f16f1b3 View commit details
    Browse the repository at this point in the history
  21. use shared tests in StubbingOnNonMockObjectTest

    ... just as in all the StubbingNonExistent*MethodTest
    nitishr committed Jan 16, 2020
    Configuration menu
    Copy the full SHA
    ad2cd32 View commit details
    Browse the repository at this point in the history
  22. extract default to allow test to a module

    so we can include the module rather than a test calling the same
    assertion in multiple test classes
    nitishr committed Jan 16, 2020
    Configuration menu
    Copy the full SHA
    d67f0b5 View commit details
    Browse the repository at this point in the history
  23. Refactor: rename existing*method->existing_method

    ... to reduce diff between and prep to DRY up
    test_should_allow_stubbing_existing_*_any_instance_method
    nitishr committed Jan 16, 2020
    Configuration menu
    Copy the full SHA
    420aec3 View commit details
    Browse the repository at this point in the history
  24. set visibility programmatically than declaratively

    ... this will allow us to extract a parameterizable method to DRY up
    nitishr committed Jan 16, 2020
    Configuration menu
    Copy the full SHA
    e53c6a8 View commit details
    Browse the repository at this point in the history
  25. put mocha configure and run_as_test together

    ... to prep for extracting both into a single method
    nitishr committed Jan 16, 2020
    Configuration menu
    Copy the full SHA
    8f403ec View commit details
    Browse the repository at this point in the history
  26. Configuration menu
    Copy the full SHA
    23f11a5 View commit details
    Browse the repository at this point in the history
  27. Configuration menu
    Copy the full SHA
    9f6164e View commit details
    Browse the repository at this point in the history
  28. Refactor: inline temps

    nitishr committed Jan 16, 2020
    Configuration menu
    Copy the full SHA
    307aa5a View commit details
    Browse the repository at this point in the history
  29. separate tests for allow stubbing existing methods

    ... since those tests don't use the same fixture and 'framework' as the
    tests for checking stubbing non-existent methods, and the class and
    superclass tests follow the same structure, so separating them
    highlights the similarity and affords an opportunity for abstraction.
    nitishr committed Jan 16, 2020
    Configuration menu
    Copy the full SHA
    bbcdb07 View commit details
    Browse the repository at this point in the history
  30. Refactor:extract stubbee_with_method to lower diff

    ... between
    test_should_allow_stubbing_existing_*_any_instance_{,super}class_method
    nitishr committed Jan 16, 2020
    Configuration menu
    Copy the full SHA
    6f95b2f View commit details
    Browse the repository at this point in the history
  31. Configuration menu
    Copy the full SHA
    e56097a View commit details
    Browse the repository at this point in the history
  32. Configuration menu
    Copy the full SHA
    6f9b6e7 View commit details
    Browse the repository at this point in the history
  33. define method programmatically than declaratively

    ... to allow class or superclass to be the method owner
    nitishr committed Jan 16, 2020
    Configuration menu
    Copy the full SHA
    c58b383 View commit details
    Browse the repository at this point in the history
  34. Refactor: push stubbee creation down a method

    into assert_allows_stubbing_existing_any_instance_method
    nitishr committed Jan 16, 2020
    Configuration menu
    Copy the full SHA
    0aef1b8 View commit details
    Browse the repository at this point in the history
  35. allow test classes to specify method_owner,stubbee

    The earlier design had something like a double dispatch going on between
    the test classes and the shared module as follows:
    SharedModule#assert_allows_stubbing_existing_method ->
    TestClass#stubbee_with_method -> SharedModule#class_with_method. We now
    replace the ping-pong style with a unidirectional method call sequence:
    SharedModule#assert_allows_stubbing_existing_method ->
    TestClass#method_owner, TestClass#stubbee
    
    The new design also puts the names of the defined method and the stubbed
    method together in a single method body, so the correlation is more
    obvious and in a single location, rather than the earlier connascence of
    name between two methods
    nitishr committed Jan 16, 2020
    Configuration menu
    Copy the full SHA
    be34bf6 View commit details
    Browse the repository at this point in the history
  36. extract stub_owner to override for class methods

    We were using stubbee as the class whose methods would be stubbed, and
    then stubbing stubbee.any_instance. However, for class method tests, we
    would want an object (the class) that can be stubbed by calling .stubs
    on it directly. We call that object the stub_owner, which in case of
    AnyInstance tests will be stubbee.any_instance (or, after the rename
    here, stubbed_instance.any_instance
    nitishr committed Jan 16, 2020
    Configuration menu
    Copy the full SHA
    55cc6b9 View commit details
    Browse the repository at this point in the history
  37. Configuration menu
    Copy the full SHA
    478733c View commit details
    Browse the repository at this point in the history
  38. Configuration menu
    Copy the full SHA
    702992f View commit details
    Browse the repository at this point in the history
  39. use existing method shared tests for class methods

    ... by specifying custom method_owner and stub_owner
    nitishr committed Jan 16, 2020
    Configuration menu
    Copy the full SHA
    84f2a61 View commit details
    Browse the repository at this point in the history
  40. instance method tests use ExistingMethodSharedTest

    ... by specifying custom method_owner and stub_owner
    nitishr committed Jan 16, 2020
    Configuration menu
    Copy the full SHA
    bac7571 View commit details
    Browse the repository at this point in the history
  41. pull up test_should_allow_stubbing_method_responded_to

    from AllowStubbingNonExistent{AnyInstance,Class,Instance}{,Superclass}MethodTest
    after a rename to make it more generic. This also adds the respond_to? check to
    superclass tests. It wasn't clear why we should check for existing methods on a
    class and its superclass, but skip the superclass check for a method to which we
    the object responds
    nitishr committed Jan 16, 2020
    Configuration menu
    Copy the full SHA
    1ae84b8 View commit details
    Browse the repository at this point in the history
  42. Configuration menu
    Copy the full SHA
    2df5eed View commit details
    Browse the repository at this point in the history
  43. Configuration menu
    Copy the full SHA
    dae2123 View commit details
    Browse the repository at this point in the history
  44. Configuration menu
    Copy the full SHA
    79558ac View commit details
    Browse the repository at this point in the history
  45. use shared tests for non-public any_instance

    Just as in the case of stubbing non-existent method tests, we break the
    single StubbingNonPublicAnyInstanceMethodTest into:
    
    - StubbingNonPublicAnyInstanceMethodTest - with just
    test_should_allow_stubbing_public_any_instance_method
    - StubbingPrivateAnyInstanceMethodTest - checks that stubbing private
    methods is checked (allow/warn/prevent)
    - StubbingProtectedAnyInstanceMethodTest - checks that stubbing private
    methods is checked (allow/warn/prevent)
    nitishr committed Jan 16, 2020
    Configuration menu
    Copy the full SHA
    f9c1a65 View commit details
    Browse the repository at this point in the history
  46. reduce diff in tests for private and protected

    by using the same method names, and setting visibility programmatically
    rather than declaratively
    nitishr committed Jan 16, 2020
    Configuration menu
    Copy the full SHA
    03e25ed View commit details
    Browse the repository at this point in the history
  47. Configuration menu
    Copy the full SHA
    1965488 View commit details
    Browse the repository at this point in the history
  48. Refactor: extract {stub,method}_owner for override

    ... in StubbingNonPublic{Class,Instance}MethodTest
    nitishr committed Jan 16, 2020
    Configuration menu
    Copy the full SHA
    c3cb560 View commit details
    Browse the repository at this point in the history
  49. extract StubbingNonPublicMethodSharedTests

    for use in StubbingNonPublic{Class,Instance}MethodTest with overridable
    method_owner and stubbed_owner later
    nitishr committed Jan 16, 2020
    Configuration menu
    Copy the full SHA
    cf22b80 View commit details
    Browse the repository at this point in the history
  50. use shared mod in StubbingNonPublicClassMethodTest

    following the same structure as StubbingNonPublicAnyInstanceMethodTest
    - StubbingNonPublicClassMethodTest
    - StubbingPrivateClassMethodTest
    - StubbingProtectedClassMethodTest
    nitishr committed Jan 16, 2020
    Configuration menu
    Copy the full SHA
    8f424f1 View commit details
    Browse the repository at this point in the history
  51. use shared mod in StubbingNonPublicInstanceMethodTest

    following the same structure as
    StubbingNonPublic{AnyInstance,Class}MethodTest
    - StubbingNonPublicInstanceMethodTest
    - StubbingPrivateInstanceMethodTest
    - StubbingProtectedInstanceMethodTest
    nitishr committed Jan 16, 2020
    Configuration menu
    Copy the full SHA
    39702b9 View commit details
    Browse the repository at this point in the history
  52. extract test allow stubbing public method to mod

    and use it in StubbingNonPublic{AnyInstance,Class,Instance}MethodTest.
    This also adds the check for stubbing method that's responded to for
    AnyInstance since it's more consistent with the other two and it wasn't
    clear why the check didn't exist for AnyInstance while it did for Class
    and Instance methods
    nitishr committed Jan 16, 2020
    Configuration menu
    Copy the full SHA
    18356c2 View commit details
    Browse the repository at this point in the history
  53. Refactor: minor rename and reorder for consistency

    ... and to make duplication more obvious
    nitishr committed Jan 16, 2020
    Configuration menu
    Copy the full SHA
    af2f216 View commit details
    Browse the repository at this point in the history
  54. Configuration menu
    Copy the full SHA
    6d33106 View commit details
    Browse the repository at this point in the history
  55. Configuration menu
    Copy the full SHA
    6e28fd6 View commit details
    Browse the repository at this point in the history
  56. Configuration menu
    Copy the full SHA
    fe601c2 View commit details
    Browse the repository at this point in the history
  57. Configuration menu
    Copy the full SHA
    04c4a5b View commit details
    Browse the repository at this point in the history
  58. Configuration menu
    Copy the full SHA
    b557ff8 View commit details
    Browse the repository at this point in the history
  59. Configuration menu
    Copy the full SHA
    807758e View commit details
    Browse the repository at this point in the history
  60. Configuration menu
    Copy the full SHA
    9d90336 View commit details
    Browse the repository at this point in the history
  61. Configuration menu
    Copy the full SHA
    d2932ce View commit details
    Browse the repository at this point in the history
  62. Configuration menu
    Copy the full SHA
    8f6a9b4 View commit details
    Browse the repository at this point in the history

Commits on Jan 17, 2020

  1. Configuration menu
    Copy the full SHA
    7554c38 View commit details
    Browse the repository at this point in the history