How does rspec + rspec-rails launch the rails app for tests?

41 views
Skip to first unread message

Ming Er

unread,
Apr 2, 2014, 8:58:11 PM4/2/14
to rs...@googlegroups.com
I've been using RSpec (also Cucumber) without an understanding of the internals.  I decided to remedy that by diving into the github repos for rspec and rspec-rails.  One basic thing that I haven't been able to figure out in the code is when I run an rspec test, say "rspec spec/blah_spec.rb," how does the rails app get launched to be tested against?  TIA for any pointers.

Myron Marston

unread,
Apr 2, 2014, 11:07:49 PM4/2/14
to rs...@googlegroups.com
On Wednesday, April 2, 2014 5:58:11 PM UTC-7, Ming Er wrote:
I've been using RSpec (also Cucumber) without an understanding of the internals.  I decided to remedy that by diving into the github repos for rspec and rspec-rails.  One basic thing that I haven't been able to figure out in the code is when I run an rspec test, say "rspec spec/blah_spec.rb," how does the rails app get launched to be tested against?  TIA for any pointers.

In general, I would say that the rails app doesn't get launched to be tested against.  The various pieces (models, controllers, etc) can be used (somewhat) independently (using rails' test support in some places) without booting a rails server, and the tests for these various components run directly against them.

When running end-to-end integration/acceptance tests (depending on your nomenclature), you're usually using a tool such as rack-test to mimic an HTTP client or capybara to mimic user interactions in a web browser.  Rails is built on top of rack[1], which provides a simple means to make requests to the rails app w/o actually having to run it as an HTTP server.

Finally, if you do use capybara to do end-to-end tests involving the javascript layer as well, it actually boots the rails app [2] as an HTTP server in a separate thread using webrick (or a similar application server).

HTH,
Myron


 
Reply all
Reply to author
Forward
0 new messages