4

Is there a way in which you can break specs up for a model into some sort of hierarchy? The specs for a couple of our models have gone over 5000 lines and this is reducing their maintainability.

I know that in an ideal world models would not be complex enough to require tests of this size, but these models effectively are Ruby implementations of pandas objects from Python scientific libraries (Series and DataFrame) so we are unfortunately bound by this.

I would like to be able to split the tests up by logical operations. Is this possible? I would ideally also like to run all the specs for a model with a single command.

Dave Schweisguth
  • 36,475
  • 10
  • 98
  • 121
Donovan Thomson
  • 2,375
  • 3
  • 17
  • 25
  • 2
    Have you looked at and using RSpec custom matchers and "behaves like" shared examples? They can significantly reduce line count in specs. – Neil Slater Jul 13 '15 at 09:46
  • I would also recommend to improve syntax as a starting point. – Andrey Deineko Jul 13 '15 at 09:47
  • 2
    I have ! They are already being implemented in the specs in question. Unfortunately the complex nature of the objects means that even using best Rspec practices the tests will still be 1000s of lines long – Donovan Thomson Jul 13 '15 at 09:49

1 Answers1

4

It is certainly possible. I've never had to arbitrarily break up a model spec, because I've always been able to break up the model and then test the pieces, but I've often had to break up acceptance specs, for example.

If your Series class had a bunch of methods about arithmetic, a bunch about baseball, a bunch about television and a bunch about wiring, you could break up the specs like so

spec/models/series/
  arithmetic_spec.rb
  baseball_spec.rb
  television_spec.rb
  wiring_spec.rb

and run them all at once with

rspec spec/models/series
Dave Schweisguth
  • 36,475
  • 10
  • 98
  • 121