Skip to content
This repository has been archived by the owner on May 21, 2019. It is now read-only.

Commit

Permalink
Explained why we need to look at a class, and not an instance to dete…
Browse files Browse the repository at this point in the history
…ct scala step definitions.
  • Loading branch information
aslakhellesoy committed Sep 14, 2009
1 parent 7507ac5 commit 20321f0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,23 @@ class ScalaAnalyzer extends ClassAnalyzer {
def registerHooksAndStepDefinitionsFor(clazz: Class[_], classLanguage: ClassLanguage) {
if (classOf[ScalaDsl].isAssignableFrom(clazz)) {

/*
We get here before classes are registered in the objectFactory (PicoContainer/Spring).
Therefore, we can't ask the classLanguage for an instance of clazz yet.
(We'll get a NullPointerException from PicoFactory.getComponent())
Even if we changed ClassLanguage.load to objectFactory.addClass(clazz)
before invoking this method, we would run into problems if a class
with step definitions is abstract (they cannot be instantiated!)
Some people (using Java at least) actually define step definitions in
abstract classes. See Github ticket:
http://github.com/aslakhellesoy/cuke4duke/issues/closed#issue/15
Therefore - it should be possible to inspect step definitions of a class
*without* an instance - simply by looking at the clazz.
Is that possible?
*/
val scalaDsl = classLanguage.getTarget(clazz).asInstanceOf[ScalaDsl]

for (stepDefinition <- scalaDsl.stepDefinitions)
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<profile>
<id>examples</id>
<modules>
<!-- <module>examples/scala</module> -->
<module>examples/scala</module>
<module>examples/simple</module>
<module>examples/spring</module>
<module>examples/groovy</module>
Expand Down

0 comments on commit 20321f0

Please sign in to comment.