I am trying to use Cucumber for a Rails project on Windows.
Unfortunately the time it takes to run a scenario is making BDD
impossible.
I understand this is largely due to the time taken by Rails to load up
under windows.
Does anyone have any ideas about how I can speed things up.
e.g Is it possible to call Cucumber inside a Rails console to avoid
the load up delay.
Cheers.
Windows is now supported by Spork! http://wiki.github.com/timcharper/spork/
Spork is a test server than can be invoked via DRb.
On POSIX systems Spork uses Kernel.fork.
On Windows forking is not an option so Spork creates a pool of preloaded processes which
avoids the huge Rails start up time.
At the moment it only works with win32/mingw Ruby because it depends on the win32-process gem.
A big thanks to the Spork Guys for doing such a great job and making cucumber BDD possible on Windows.
Please note that I have only tried Spork with
Windows XP
Rails 2.3.5
Ruby 1.9.1 from rubyinstaller.org
Have you tried running cucumber without db:test:prepare?
What about setting t.fork = true # set to false for performance increase
(both in /lib/tasks/cucumber.rake)
Is this just my machine, or is the console output of Spork running on Windows extremely slow?
Related
I'm using RVM to manage my environments for a few Rails projects. One of them is running Rails 3 on ruby 1.9.2, and one is running Rails 2.3 on ruby 1.8.7. The 1.8.7 environment is very slow to start any rails-based tasks (console, server, tests) - I mean 45s - 2 minutes depending on what's happening. The 1.9.2 environment is as snappy as can be.
I've tried playing with the patch level of the 1.8.7 environment, but that only helped a bit, and only for certain tasks (console and server). Tests still take forever to start, even when I'm running them individually with a ruby command.
Does anyone have an idea of what could be happening here?
Try to use spork gem which preload environment to your rails application. But it only depends on rspec tasks, I guess.
Another way: try to use ruby enterprise edition. http://www.rubyenterpriseedition.com/
I am working on moving our celerity based integration tests to capybara-webkit.
The documentation provided on git-hub (https://github.com/thoughtbot/capybara-webkit) for capybara-webkit was helpful but i am unable to run my tests, ending up with error for jruby:
NotImplementedError: fork is not available on this platform
org/jruby/RubyKernel.java:1792:in `fork'
Is there a way I can get capybara-webkit work with jruby?
You could try poltergeist which also provides a headless webkit driver for capybara, but does not rely on any native extensions. Instead, it uses PhantomJS to drive the tests. According to the README jruby is supported.
This is a bit of a long shot but have you tried gem 'spoon' in your Gemfile?
I have not been able to get capybara-webkit working with JRuby. I have had success using MRI for my development/TDD cycles and switching to JRuby (using RVM) to make sure everything still runs. When I run my JRuby features (cucumber), I just use selenium for testing javascript. I have a bit of setup code that looks similar to this in features/support/setup.rb:
Before do
if running_in_jruby
Capybara.javascript_driver = :selenium
else
Capybara.javascript_driver = :webkit
end
end
This is specific to cucumber of course, although you should be able to do something similar with rspec. I've found that MRI is quite a bit faster at running my tests due to the faster startup time vs. Java. I'll run my features/specs many times during the development of a feature, and then before I check in I'll switch to JRuby and run the tests just once.
We need to port a Rails application running on Linux to work on a client's Windows server. We've never done this and are unfamiliar with the Windows server environment. Our first decision is whether to try to port the app using JRuby or whether to just try to get the normal Ruby version working on a Windows server. Which course is more advisable?
Some gems we'll use that might be an issue (wildly guessing):
nokogiri
eventmachine
em-websocket
mysql or postgresql adapter
It depends.
If you use a lot of gems with natives extensions try before the native Ruby, but I would suggest a port to JRuby because it simplify a lot the deployment on Windows.
I personally use only JRuby on Windows with JBoss and Warbler or with the trinidad gem.
And, it sounds strange, but JRuby scales very well and it's faster than MRI with Java 7.
I have several JRuby on Rails apps that use MSSQL Server or Oracle and they are awesome in production with only a few optimisations (http://http.tv4.se/2011/01/20/optimzing-jruby-rails-3-0-performance)
From what I've heard, JRuby is supposed to be the best way to deploy Rails on Windows. But try to avoid this. Rails is happiest in a *nix environment, and anyway Windows is a terrible server OS.
If you can't get a *nix server, how about virtualizing?
I'm using RVM for managing environment, installed Ruby 1.9.2.p136 (i think its latest release.) and Rails 3, created gemsets and run bundler. everything working good so far
but;
Rails initalizes extremely slow when running commands, i.e. generate, destroy, rake etc.
Takes about 30-45 seconds to complete command. This will never happens if use Ruby Enterprise Edition or Ruby 1.8.7
Why this happens. Any thoughts?
Running on Ubuntu 10.10, RVM, Ruby 1.9.2, Rails 3
Thanks.
There is a thread about this on Rails-Core - http://groups.google.com/group/rubyonrails-core/browse_thread/thread/88519ef5a53088a1/c01ba447c6dc0de7?lnk=raot
To quote Yehuda Katz
"There are things that the C require code does in 1.9 that slow things down.
One such example is re-checking $LOAD_PATH to make sure it is all expanded
on every require. This is something that should be addressed by ruby-core.
I'll open a ticket on redmine if there isn't one already."
I am also experiencing this problem and a $LOAD_PATH issue seems like a potential cause. Lets hope it gets fixed soon.
Try to strace (on unix), dtruss (on mac) your command (might need to "sudo" though). It'll show you where the process is spending its time. Notice where it pauses. This is definitely not normal.
Having the same problems as this post, except I don't think the solution is the same unfortunately.
I'm getting this error message:
Rails requires RubyGems >= 0.9.4. Please install RubyGems
when I run a script/runner job in Cron, but it works perfectly fine when I run it in a terminal on the same server.
The rails server also runs fine. I only have trouble running script/runner's in cron. It seems to want to have a terminal attached...
Try which ruby and which gem from your cron job and also from the terminal. Are you accessing different binaries? You didn't mention which OS and which shell, but you may have a different $PATH when running headless.
The selected answer is completely correct, but something I'd suggest is to NOT use script/runner. The resources required to load the entire stack of your rails application is pretty intense for something to run regularly.
In my past experience, any cron jobs generally only have to deal with data (as opposed to say, generate static files, etc). In this case, you can very simply just load your models up, and since you've written your models the correct way (fat models), you can easily do your data processing with a few model methods.
Of course, all the above depends completely on your task, so take it with a grain of salt :)
I suppose this was a sort of answer to a problem that may not exist, and wasn't asked here, but just thought I'd throw my two cents in ;)
You wouldn't happen to be working on OSX? You should be installing a newer ruby rails and gems off macports instead. Google for the instructions...
As indicated by earlier posts, your Cron is using a different gem command source — also try which gem and gem -v. You may have a library set in your .bash_profile (or similar shell configuration or perhaps by other means, setting proper Ruby/Rails environment (i.e., Locomotive or other all-in-one environment).
To update your gem setup:
gem update --system
More information here - http://www.rubygems.org/read/book/1