Rspec Still Slow On Windows Even With Spork
Asked Answered
S

4

10

I have followed this tutorial on speeding up rspec with spork, and I am on a win7 x64 box with ruby 1.9.2 and rails 3.2.5. Everything is working, but test still execute slowly. Does spork simply not do much on windows because the OS doesn't support forking?

Is there anything else I can do to speed things up?

I also found this similar SO question, and watched the video by Corey Haines on fast testing. I enjoyed the video, but I can't help feeling that something is off when the state of our tools (slow tests due to rails startup time, in this case) dictates how we structure our code. If that slow startup time didn't exist, would there be any need for his methods? On the other hand, with tests taking 10-30 seconds to run, so many of the benefits of TDD are lost that I see his point of view as well.

In case it's relevant, here's the console output from spork as the rspec was executed a couple times:

    $ bundle exec spork
Using RSpec
  -- Starting to fill pool...
     Wait until at least one slave is provided before running tests...
  ** CTRL+BREAK to stop Spork and kill all ruby slave processes **
Spork is ready and listening on 8989!
  -- Rinda Ring Server listening for connections...

   -- build slave 1...
Preloading Rails environment
   -- build slave 2...
Preloading Rails environment
Loading Spork.prefork block...
Loading Spork.prefork block...
Running tests with args ["--color"]...
  --> DRb magazine_slave_service: 1 provided...
  --> DRb magazine_slave_service: 2 provided...
  <-- take tuple(2); slave.run...
   -- (2);run done
Done.

   -- build slave 2...
Preloading Rails environment
Loading Spork.prefork block...
Running tests with args ["--color"]...
  <-- take tuple(1); slave.run...
   -- (1);run done
Done.

   -- build slave 1...
Preloading Rails environment
Loading Spork.prefork block...
  --> DRb magazine_slave_service: 2 provided...
Synergist answered 19/6, 2012 at 9:42 Comment(18)
How many examples take 30 seconds to run? Spork won't help you to speedup your tests' time. It'll make them to run in a much shorter period.Trimaran
I was speaking generally. In my example there is just one test, which in itself executes in a fraction of a second, but takes 5-10 seconds to actually run, including rails load timeSynergist
Running spork on windows is useless, why are you doing it? There isn't anything that's going to help you, ruby on windows is slow and most of the tools out there are linux/mac only. If you decide to go on windows you just have to accept the fact that Ruby is pretty effed up in there.Levantine
How about to run you rspec w/o bundle? Just make sure you don't have few versions of RSpec. And I suppose you'd called spork --bootstrap as the first step.Trimaran
@MaurícioLinhares Nope, it isn't useless. It gives a significant boost. I checked!Trimaran
@jdoe: Yes I called --bootstrap. Running without bundle does seem to help quite a bit, thanks. However, is there a less verbose way to do it than my current way, which is "ruby C:\\RailsInstaller\\Ruby1.9.2\\lib\\ruby\\gems\\1.9.1\\gems\\rspec-core-2.9.0\\exe\\rspec" from the command line?Synergist
@Synergist Run gem in rspec-core -v 2.9.0 --no-ri --no-rdoc. It should reinstall your rspec-core with adding some files in Ruby's bin folder to be able to run your specs simply as: rspec.Trimaran
@Trimaran Playing with this some more.... So while bypassing bundle seems to add a little speed, I am still looking at around 4 seconds to run an essentially instant test.Synergist
@MaurícioLinhares The entire talk I linked used a mac to run all the examples, so while the problem is worse on windows it exists everywhereSynergist
Yes, it does, but since spork preloads the rails environment and forks to run your tests, it runs much faster on a OS that supports forking and this is what is hurting your tests.Levantine
@MaurícioLinhares Can you speak at all to my 2nd question, regarding the appropriateness of refactoring your code as Corey suggests, and thus letting your tools dictate your design? Do you find it hackish, or do you think it's fine?Synergist
@Synergist well, I'm a Java programmer turned Ruby programmer so I have a very distinct view of this. What people think is "hacks" is, in fact, how we have been doing stuff in the Java land for quite a while. Having an object that saves itself would be something out of this world in a well engineered java app, you would like to have persistence in a separate place, so you can test your models easily and without external dependencies. But then comes the other problem, over engineering, which we also had in java apps. So striking a balance is the key here.Levantine
So, if there's code out there that's making your TDD a pain, it usually means the code is wrong and you need to improve it. If you, for instance, don't use anything rails specific in your test, why require the rails env for it? It's complicated, but it's a world of trade-offs. We just have to make sure we are gravitating to a place that makes us productive. But please, don't use windows for Ruby development (you can also try JRuby) ;)Levantine
Windows isn't that bad except for the speed, which is really the only major stopper I see for RoR. I'm working on Linux now, and those selenium tests are so slow that I shudder to imagine how they would even run on Windows. But Windows is still good for learners, I did get through the tutorial on Windows once and that experience made setup on other environments to be much easier.Calhoun
that said, feel free to challenge #8907372Calhoun
When I started Rails, I tried on a Windows machine. It took 10 minutes for Rails to start. Also, many gems won't work on Windows. So I switched to Ubuntu. If you want to learn Rails, make the investment and install Ubuntu or get a Mac. Otherwise you are just wasting your time. FWIW, while working on a single test, I am running the test in 2.5 sec.Beaty
Have you considered offloading running the suite of tests to a CI server like Travis? You can just run your individual tests you are working on locally, push to CI and let it tell you if the rest of the tests work or not. When your application reaches the scale of having hundreds of tests, you'll have to do that anyway.Langille
And really, just running a virtual machine of Ubuntu will make your life much easier in a number of ways.Langille
A
1

The Code Shop is building an MRI Ruby optimized for Windows, you can find more about it on their Website or their Github Repo.

I also suggest you to watch this talk about developping rails apps on Windows

Aluino answered 21/12, 2012 at 8:27 Comment(0)
F
1

Try checking out http://railscasts.com/episodes/413-fast-tests. This shows a lot of different tools that can improve the speed of your test suite significantly!

Foundation answered 9/5, 2013 at 16:15 Comment(0)
H
0

Before, I was as patient as anybody else in running RSPEC tests using Windows! Doing rake(s) takes too much of my time and it wasn't really healthy anymore. Deliverables were some kind of delayed because the development in Windows was such a pain. And that's the truth. That's why I switched to Linux. But sometimes, there were still trouble(s) in using Linux (hassle installation of some stuffs and more). I just remained patient until I switched to MAC which is a lot better.

If you are really consistent in using Windows for ROR then running tests would be that slow if there are plenty of modules to test.

I'm kinda sure also that Selenium testing would be a disaster in Windows.

But, you may also try to add some other stuffs like using GUARD (for faster execution of test scripts) wherein you don't have to type rspec spec repeatedly.

See: https://github.com/guard/guard

For the spork, well I also encountered a bug about it (before)... wherein I'm testing some spec files using Linux and then it was so slow that I really hated using it.

And that's the reality.

Check out how I configured SPORK to work for rspec:

spec_helper.rb

See: https://github.com/xirukitepe/animelist/blob/master/spec/spec_helper.rb

Hyacinthia answered 27/12, 2012 at 9:55 Comment(0)
E
0

I would use a linux VM for this kind of thing...

The biggest increase in test speed I've managed to get with RSpec has been to ensure it never hits the database unless it absolutely has to.

Earwig answered 8/5, 2013 at 7:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.