Rspec running very, very slowly on Ruby on Rails - ruby-on-rails

I am running Ruby on Rails 5.1.4 and am trying to upgrade to Ruby 2.5.1 from Ruby 2.4.4. When I run Rspec, it is running incredibly slowly. I have used the method described here by myronmarston allows me to see what is happening.
The Rspec program appears to be progressing normally, just every step is taking a long time, for example it takes over half an hour to finish the rspec.configure block in spec_helper, minutes to execute a validate statement in a model. I have tried different tests and it is not any specific test code.
If I start up the rails server, the app appears to be working normally. The console appears to work normally as well, it is just rspec. I have tried spring stop and it makes no difference to outcome.
Any ideas on what is causing this?

Related

Profiling of Ruby Minitest tests

I have a lot of slow-running Minitest tests for Rails app (3-4 minutes on one test). I want to profile them to learn how to fix them.
I tried to use standard Ruby profiler and ruby-prof - neither worked. Standard Ruby profiler profiles... something, but it prints its results BEFORE running tests, and I get no information on them. Ruby-prof simply hangs my tests if I include RubyProf.start in the test.
The Internet is full of advices on profiling Rails apps. Hovever, I did not find any guide for profiling tests for Rails apps. Please, help me choose proper strategy for test profiling!
I was able to add the profile to my unit tests successfully by including require 'profile' at the top of my test file. It does hang at the beginning (maybe for 30 seconds) when it's setting up, but after the tests ran I got a detailed output on how much time was spent in different functions.
I ran the tests from the command line with ruby -rprofile -I"lib:test" <test filepath>.

possible to debug/pry from methadone's App class?

I started a blank project with methadone, an awesome framework for building command line apps. The only problem is that I am unable to debug from within the App class that's in bin/my_app
The App class is a file created when you run methadone. Here's how I'm trying to use pry
#!/usr/bin/env ruby
require 'optparse'
require 'methadone'
require 'my_app'
require 'pry'
class App
include Methadone::Main
include Methadone::CLILogging
main do
binding.pry # <= pry here
end
...
When I run rake features I can tell the running process is trying to do something with pry since it pauses for a few seconds. I get the following error and then rake/cucumber is aborted.
process still alive after 3 seconds (ChildProcess::TimeoutError)
I can use pry just fine from the cucumber steps, rspec, or any other place, just not from anywhere in this App class.
One very interesting thing is that if I run my command line app from the console it WILL stop where pry is. It just wont pop into pry when using cucumber.
How can I get the app to work with pry when I'm running rake features?
Update
Sorry, I should clarify that methadone comes with aruba. So my cucumber scenario would look like this
When I successfully run `my_app arg1`
However, it WILL go into debug/pry if I run it with
bundle exec bin/my_app
Use pry-remote to connect to a pry session in the Aruba-managed subprocess.
(Disclosure: I paired with #Dty to come to this solution)
Aruba runs the app in a totally separate process, so I would guess what's happening is that when aruba runs your app, pry starts up at a prompt and waits for input. Since it doesn't get any, aruba times out after three seconds (the default it will wait for an app to complete). This is why you see the "process still alive" issue.
I'm not 100% sure how you could get the standard input of your shell that's running rake features to connect to your app's standard input so you could issue pry commands, but I don't think aruba was designed to allow this.
You have a couple of options:
Tag your scenario with #announce, and use When I run interactively... followed by several When I type - these commands should go to the interactive pry console that's waiting. Kind of kludgy, but it might work
Execute a unit test of your App class. You'll need to replace the call to go! with something like go! if $0 == __FILE__ so that you can require your executable in a test and manipulate App directly.
I have not tried either of these, but the second option feels a bit better and could also be improved with support from the library, if you can figure out a good way to do this.

Loading ruby takes ages

I'm frequently starting up rails console or rails server or using other command line ruby apps. The bootstrap takes several seconds, which becomes tedious after a while.
Is there any way I can either run a compiled version, or keep it loaded using something like spork, so running 'heroku logs' runs instantly, rather than taking 10 seconds to start up?
Run a compiled version of what?
Rails server and rails console take long time to load because they have to load up Ruby on Rails plus whatever your environment requires. If you want to keep instances running then just open up a terminal window, load your console and server, and never close them.
Have you thought of trying vagrant? it will keep your instance running to you want them to stop.

Speeding up rails tests during development by keeping Rails in memory?

When running rspec tests on my rails app using "rake" or "rake spec", it takes a long time to initialize Rails and start running tests.
Is there a way to keep Rails loaded in memory and run tests against it? I'm hoping there's something similar to using "grails interactive" like this How to speed up grails test execution but for Rails.
It's almost what Spork is all about.
See the most awesome railscast "How I test" http://railscasts.com/episodes/275-how-i-test
This uses guard to run a relevant test every time you save a file so you know almost instantly if the code you have written has caused a pass or a fail. Also if you are running on linux then you can use the libnotify and libnotify-rails gems which pop up a window for you (totally unobtrusively) indicating a pass or failure so you don't have to keep checking the console.
There is a Railscast called Spork that specifically discusses this problem at http://railscasts.com/episodes/285-spork and offers an excellent solution with a detailed walkthrough.

Ruby on Rails Autotest No Longer Catching Errors

I am going through Hartl's rails tutorial and the autotest is no longer running newly written tests. I write a new test and it will not be reflected in autotest. Autotest still runs and remains green with a set number of examples. Existing tests will fail if I change things but new test are not recognized. Any ideas? Thanks.
Caught it. I had an errant end keyword.

Resources