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
Limit spec dsl defined classes to own test methods #865
base: master
Are you sure you want to change the base?
Conversation
|
||
def self.methods_matching re | ||
public_instance_methods(false).grep(re).map(&:to_s) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't really make sense here, does it? Maybe I'm confused.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The class created by Class.new
will inherit from Minitest:Spec or some other subclass (Minitest::Spec#spec_type). Class.new
allows you to run code or create methods for that dynamic subclass which will be defined with the call to describe.
I had initially approached it by changing the method in Runnable, though that would cause issues with inheritance (since we wouldn't want to upset the current expected behavior of a test class inheriting from another running the tests of the inherited class). Thus, we'd need only the classes defined by describe
to have this behavior, which is why we'd need this here.
Why not in Spec?
… On Mar 23, 2021, at 12:13, Andrew McKinnie ***@***.***> wrote:
@amckinnie commented on this pull request.
In lib/minitest/spec.rb:
> @@ -266,6 +266,10 @@ def create name, desc # :nodoc:
@desc = desc
nuke_test_methods!
+
+ def self.methods_matching re
+ public_instance_methods(false).grep(re).map(&:to_s)
+ end
The class created by Class.new will inherit from Minitest:Spec or some other subclass (Minitest::Spec#spec_type). Class.new allows you to run code or create methods for that dynamic subclass which will be defined with the call to describe.
I had initially approached it by changing the method in Runnable, though that would cause issues with inheritance (since we wouldn't want to upset the current expected behavior of a test class inheriting from another running the tests of the inherited class). Thus, we'd need only the classes defined by describe to have this behavior, which is why we'd need this here.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
We could, though with the inheritance issue still applies.
This would currently run everything from ATest in BTest. Would we no longer want to do that? |
Issue:
Currently, minitest spec styles deals with tests being included from preceding or ancestor classes within the DSL with the method
Minitest::Spec::DSL#nuke_test_methods!
. This will wipe out existing test methods that have been defined at the time of class initialization (Minitest::Spec::DSL#create
). However, when tests are defined after a block is declared, they are still included when the instance methods for the class are pulled (since they're pulled with all the ancestor instance methods.In this example:
test_name
will be run twice, once as part of classMyTest
and once as part of classMyTest::foo
. This will occur for each describe block (or alias), so if there are multiple describe blocks in a test file, it will run for each of them.Proposed Solution:
For classes defined by the spec DSL, limit test methods pulled to that of the class itself.