-
-
Notifications
You must be signed in to change notification settings - Fork 159
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
base: main
Are you sure you want to change the base?
Commits on Jan 16, 2020
-
Configuration menu - View commit details
-
Copy full SHA for d538675 - Browse repository at this point
Copy the full SHA d538675View commit details -
Configuration menu - View commit details
-
Copy full SHA for 356d967 - Browse repository at this point
Copy the full SHA 356d967View commit details -
configure check only if treatment isn't default
This allows us to call stub_method_unnecessarily in the default case without a treatment
Configuration menu - View commit details
-
Copy full SHA for 2b58fe2 - Browse repository at this point
Copy the full SHA 2b58fe2View commit details -
Configuration menu - View commit details
-
Copy full SHA for 7737927 - Browse repository at this point
Copy the full SHA 7737927View commit details -
Configuration menu - View commit details
-
Copy full SHA for 68d6abb - Browse repository at this point
Copy the full SHA 68d6abbView commit details -
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.
Configuration menu - View commit details
-
Copy full SHA for 964262c - Browse repository at this point
Copy the full SHA 964262cView commit details -
extract stub_method_on_nil & violation_message
... following the same structure and logic as in the case of stubbing_method_unnecessarily
Configuration menu - View commit details
-
Copy full SHA for d1665a3 - Browse repository at this point
Copy the full SHA d1665a3View commit details -
Configuration menu - View commit details
-
Copy full SHA for 3ec6ac9 - Browse repository at this point
Copy the full SHA 3ec6ac9View commit details -
Configuration menu - View commit details
-
Copy full SHA for 73f20ec - Browse repository at this point
Copy the full SHA 73f20ecView commit details -
Refactor:rename method_x->with_potential_violation
...to reduce diff between StubbingMethod{Unnecessarily,OnNil}Test to prep to extract common module
Configuration menu - View commit details
-
Copy full SHA for 8c40baf - Browse repository at this point
Copy the full SHA 8c40bafView commit details -
Refactor: extract block to potential_violation
...to furter reduce diff betwee StubbingMethod{Unnecessarily,OnNil}Test to prep to extract common module
Configuration menu - View commit details
-
Copy full SHA for 7c0c807 - Browse repository at this point
Copy the full SHA 7c0c807View commit details -
Refactor: extract block to configure_violation
...to furter reduce diff betwee StubbingMethod{Unnecessarily,OnNil}Test to prep to extract common module
Configuration menu - View commit details
-
Copy full SHA for 34f90ae - Browse repository at this point
Copy the full SHA 34f90aeView commit details -
Refactor: make test method name truthful
This seems to have been an artifact of copy-paste
Configuration menu - View commit details
-
Copy full SHA for c744731 - Browse repository at this point
Copy the full SHA c744731View commit details -
extract StubbingWithPotentialViolationSharedTests
... pulling up all the identical methods between Stubbing{MethodUnnecessarily,Nil}Test
Configuration menu - View commit details
-
Copy full SHA for be0831a - Browse repository at this point
Copy the full SHA be0831aView commit details -
Configuration menu - View commit details
-
Copy full SHA for d136000 - Browse repository at this point
Copy the full SHA d136000View commit details -
Configuration menu - View commit details
-
Copy full SHA for cfb2d60 - Browse repository at this point
Copy the full SHA cfb2d60View commit details -
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).
Configuration menu - View commit details
-
Copy full SHA for 9071d2a - Browse repository at this point
Copy the full SHA 9071d2aView commit details -
Configuration menu - View commit details
-
Copy full SHA for 88e50e4 - Browse repository at this point
Copy the full SHA 88e50e4View commit details -
use shared tests in StubbingNonExistentClassMethodTest
... just as in the case of StubbingNonExistentAnyInstanceMethodTest
Configuration menu - View commit details
-
Copy full SHA for 451ec0b - Browse repository at this point
Copy the full SHA 451ec0bView commit details -
use shared tests in StubbingNonExistentInstanceMethodTest
... just as in case of StubbingNonExistent{AnyInstance,Class}MethodTest
Configuration menu - View commit details
-
Copy full SHA for f16f1b3 - Browse repository at this point
Copy the full SHA f16f1b3View commit details -
use shared tests in StubbingOnNonMockObjectTest
... just as in all the StubbingNonExistent*MethodTest
Configuration menu - View commit details
-
Copy full SHA for ad2cd32 - Browse repository at this point
Copy the full SHA ad2cd32View commit details -
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
Configuration menu - View commit details
-
Copy full SHA for d67f0b5 - Browse repository at this point
Copy the full SHA d67f0b5View commit details -
Refactor: rename existing*method->existing_method
... to reduce diff between and prep to DRY up test_should_allow_stubbing_existing_*_any_instance_method
Configuration menu - View commit details
-
Copy full SHA for 420aec3 - Browse repository at this point
Copy the full SHA 420aec3View commit details -
set visibility programmatically than declaratively
... this will allow us to extract a parameterizable method to DRY up
Configuration menu - View commit details
-
Copy full SHA for e53c6a8 - Browse repository at this point
Copy the full SHA e53c6a8View commit details -
put mocha configure and run_as_test together
... to prep for extracting both into a single method
Configuration menu - View commit details
-
Copy full SHA for 8f403ec - Browse repository at this point
Copy the full SHA 8f403ecView commit details -
Configuration menu - View commit details
-
Copy full SHA for 23f11a5 - Browse repository at this point
Copy the full SHA 23f11a5View commit details -
Configuration menu - View commit details
-
Copy full SHA for 9f6164e - Browse repository at this point
Copy the full SHA 9f6164eView commit details -
Configuration menu - View commit details
-
Copy full SHA for 307aa5a - Browse repository at this point
Copy the full SHA 307aa5aView commit details -
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.
Configuration menu - View commit details
-
Copy full SHA for bbcdb07 - Browse repository at this point
Copy the full SHA bbcdb07View commit details -
Refactor:extract stubbee_with_method to lower diff
... between test_should_allow_stubbing_existing_*_any_instance_{,super}class_method
Configuration menu - View commit details
-
Copy full SHA for 6f95b2f - Browse repository at this point
Copy the full SHA 6f95b2fView commit details -
Configuration menu - View commit details
-
Copy full SHA for e56097a - Browse repository at this point
Copy the full SHA e56097aView commit details -
Configuration menu - View commit details
-
Copy full SHA for 6f9b6e7 - Browse repository at this point
Copy the full SHA 6f9b6e7View commit details -
define method programmatically than declaratively
... to allow class or superclass to be the method owner
Configuration menu - View commit details
-
Copy full SHA for c58b383 - Browse repository at this point
Copy the full SHA c58b383View commit details -
Refactor: push stubbee creation down a method
into assert_allows_stubbing_existing_any_instance_method
Configuration menu - View commit details
-
Copy full SHA for 0aef1b8 - Browse repository at this point
Copy the full SHA 0aef1b8View commit details -
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
Configuration menu - View commit details
-
Copy full SHA for be34bf6 - Browse repository at this point
Copy the full SHA be34bf6View commit details -
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
Configuration menu - View commit details
-
Copy full SHA for 55cc6b9 - Browse repository at this point
Copy the full SHA 55cc6b9View commit details -
Configuration menu - View commit details
-
Copy full SHA for 478733c - Browse repository at this point
Copy the full SHA 478733cView commit details -
Configuration menu - View commit details
-
Copy full SHA for 702992f - Browse repository at this point
Copy the full SHA 702992fView commit details -
use existing method shared tests for class methods
... by specifying custom method_owner and stub_owner
Configuration menu - View commit details
-
Copy full SHA for 84f2a61 - Browse repository at this point
Copy the full SHA 84f2a61View commit details -
instance method tests use ExistingMethodSharedTest
... by specifying custom method_owner and stub_owner
Configuration menu - View commit details
-
Copy full SHA for bac7571 - Browse repository at this point
Copy the full SHA bac7571View commit details -
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
Configuration menu - View commit details
-
Copy full SHA for 1ae84b8 - Browse repository at this point
Copy the full SHA 1ae84b8View commit details -
Configuration menu - View commit details
-
Copy full SHA for 2df5eed - Browse repository at this point
Copy the full SHA 2df5eedView commit details -
Configuration menu - View commit details
-
Copy full SHA for dae2123 - Browse repository at this point
Copy the full SHA dae2123View commit details -
Configuration menu - View commit details
-
Copy full SHA for 79558ac - Browse repository at this point
Copy the full SHA 79558acView commit details -
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)
Configuration menu - View commit details
-
Copy full SHA for f9c1a65 - Browse repository at this point
Copy the full SHA f9c1a65View commit details -
reduce diff in tests for private and protected
by using the same method names, and setting visibility programmatically rather than declaratively
Configuration menu - View commit details
-
Copy full SHA for 03e25ed - Browse repository at this point
Copy the full SHA 03e25edView commit details -
Configuration menu - View commit details
-
Copy full SHA for 1965488 - Browse repository at this point
Copy the full SHA 1965488View commit details -
Refactor: extract {stub,method}_owner for override
... in StubbingNonPublic{Class,Instance}MethodTest
Configuration menu - View commit details
-
Copy full SHA for c3cb560 - Browse repository at this point
Copy the full SHA c3cb560View commit details -
extract StubbingNonPublicMethodSharedTests
for use in StubbingNonPublic{Class,Instance}MethodTest with overridable method_owner and stubbed_owner later
Configuration menu - View commit details
-
Copy full SHA for cf22b80 - Browse repository at this point
Copy the full SHA cf22b80View commit details -
use shared mod in StubbingNonPublicClassMethodTest
following the same structure as StubbingNonPublicAnyInstanceMethodTest - StubbingNonPublicClassMethodTest - StubbingPrivateClassMethodTest - StubbingProtectedClassMethodTest
Configuration menu - View commit details
-
Copy full SHA for 8f424f1 - Browse repository at this point
Copy the full SHA 8f424f1View commit details -
use shared mod in StubbingNonPublicInstanceMethodTest
following the same structure as StubbingNonPublic{AnyInstance,Class}MethodTest - StubbingNonPublicInstanceMethodTest - StubbingPrivateInstanceMethodTest - StubbingProtectedInstanceMethodTest
Configuration menu - View commit details
-
Copy full SHA for 39702b9 - Browse repository at this point
Copy the full SHA 39702b9View commit details -
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
Configuration menu - View commit details
-
Copy full SHA for 18356c2 - Browse repository at this point
Copy the full SHA 18356c2View commit details -
Refactor: minor rename and reorder for consistency
... and to make duplication more obvious
Configuration menu - View commit details
-
Copy full SHA for af2f216 - Browse repository at this point
Copy the full SHA af2f216View commit details -
Configuration menu - View commit details
-
Copy full SHA for 6d33106 - Browse repository at this point
Copy the full SHA 6d33106View commit details -
Configuration menu - View commit details
-
Copy full SHA for 6e28fd6 - Browse repository at this point
Copy the full SHA 6e28fd6View commit details -
Configuration menu - View commit details
-
Copy full SHA for fe601c2 - Browse repository at this point
Copy the full SHA fe601c2View commit details -
Configuration menu - View commit details
-
Copy full SHA for 04c4a5b - Browse repository at this point
Copy the full SHA 04c4a5bView commit details -
Configuration menu - View commit details
-
Copy full SHA for b557ff8 - Browse repository at this point
Copy the full SHA b557ff8View commit details -
Configuration menu - View commit details
-
Copy full SHA for 807758e - Browse repository at this point
Copy the full SHA 807758eView commit details -
Configuration menu - View commit details
-
Copy full SHA for 9d90336 - Browse repository at this point
Copy the full SHA 9d90336View commit details -
Configuration menu - View commit details
-
Copy full SHA for d2932ce - Browse repository at this point
Copy the full SHA d2932ceView commit details -
Configuration menu - View commit details
-
Copy full SHA for 8f6a9b4 - Browse repository at this point
Copy the full SHA 8f6a9b4View commit details
Commits on Jan 17, 2020
-
Configuration menu - View commit details
-
Copy full SHA for 7554c38 - Browse repository at this point
Copy the full SHA 7554c38View commit details