Single spec running twice

45 views
Skip to first unread message

Andrew Coulton

unread,
Aug 19, 2013, 4:43:07 PM8/19/13
to phpsp...@googlegroups.com
I'm using PHPSpec for the first time, and it's generally making sense and working well for me.

However I'm currently having a very strange issue - my project so far has a single Spec file, but it's running twice within a single PHPSpec run. For example, as you can see at https://travis-ci.org/ingenerator/be_entity it runs the Ingenerator\BeEntity\Factory\Example spec and then runs it again, finally reporting that 2 specs have passed.

I'm sure I must be doing something stupid, but I can't work out what...

Any tips?

Thanks,

Andrew


Silviu Constantin Voicu

unread,
Aug 21, 2013, 7:19:35 AM8/21/13
to phpsp...@googlegroups.com
well, there 2 specs
Ingenerator\BeEntity\Factory\Example
and
Ingenerator\BeEntity\FactoryManager

Andrew Coulton

unread,
Aug 22, 2013, 3:41:51 AM8/22/13
to phpsp...@googlegroups.com
Silviu,

Well, there are now - there weren't when I posted :) Sorry, I should have linked directly to the build where it was happening. 

I've since dug into it and found the problem. I had a class file (not containing a spec) in spec/Ingenerator/BeEntity/Factory/Example.php alongside the spec file in spec/Ingenerator/BeEntity/Factory/ExampleSpec.php. When PHPSpec loads the list of specs it starts by listing all the files in the spec path and stripping the "Spec.php" from the end to get the potential spec class names, and then if it finds a class with that name exists it adds it to the list of specs to run.

Because of my extra file PHPSpec was adding the spec\Ingenerator\BeEntity\Factory\Example class to the run list twice. I moved the class file so that it's name no longer matched a real class and that solved the problem.

It's a slightly unusual class/file structure because this package includes an abstract class which consuming applications are expected to extend for their specific use cases. The Example class that I'm specifying is just a demonstrator and a harness for specifying the behaviour of the base class - so I wanted to keep it with the spec files rather than in the package source.


Cheers for taking a look,

Andrew
Reply all
Reply to author
Forward
0 new messages