Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is RSpec so slow under Rails?

Whenever I run rspec tests for my Rails application it takes forever and a day of overhead before it actually starts running tests. Why is rspec so slow? Is there a way to speed up Rails' initial load or single out the part of my Rails app I need (e.g. ActiveRecord stuff only) so it doesn't load absolutely everything to run a few tests?

like image 901
Adrian Dunston Avatar asked Sep 15 '08 20:09

Adrian Dunston


People also ask

Is RSpec TDD or BDD?

RSpec is a Behavior-Driven Development tool for Ruby programmers. BDD is an approach to software development that combines Test-Driven Development, Domain Driven Design and Acceptance Test-Driven Planning. RSpec helps you do the TDD part of that equation, focusing on the documentation and design aspects of TDD.

What is RSpec capybara?

Capybara is a web-based test automation software that simulates scenarios for user stories and automates web application testing for behavior-driven software development. It is written in the Ruby programming language.

Does RSpec clean database?

I use the database_cleaner gem to scrub my test database before each test runs, ensuring a clean slate and stable baseline every time. By default, RSpec will actually do this for you, running every test with a database transaction and then rolling back that transaction after it finishes.


1 Answers

I definitely suggest checking out spork.

http://spork.rubyforge.org/

The railstutorial specifically addresses this, and gives a workaround to get spork running nicely in rails 3.0 (as of this moment, spork is not rails 3 ready out of the box). Of course, if you're not on rails 3.0, then you should be good to go.

The part of the tutorial showing how to get spork running in rails 3.0

http://railstutorial.org/chapters/static-pages#sec:spork

Checking when spork is rails 3.0 ready

http://www.railsplugins.org/plugins/440-spork

like image 156
John Hinnegan Avatar answered Oct 08 '22 01:10

John Hinnegan