简体   繁体   中英

CodeNarc - determine if a class is a Grails integration test

I'd like to write a custom CodeNarc rule that validates some aspects of Grails integration test classes. eg Spock integration tests should extend IntegrationSpec; not Specification.

But to do this, I need to filter on integration tests while visiting the classes in the rule, and I don't know how to do that.

One idea was to look at the source file path to see if it's in test/integration , but I don't know if it's possible to get the source path of a file.? Any other ideas?

You can definitely limit rule application based on path (as well as class name). Take a look at the configuring rules CodeNarc page.

In particular, you're probably looking for the applyToClassNames and doNotApplyToClassNames properties or the applyToFileNames and doNotApplyToFileNames properties, which should be available on any of the built-in Rules and any custom rules that extend the provided AbstractRule class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM