Please read for an updated status on RailsCasts:
Learn more or hide this
yeah .the speed of test is very important for TDD.. personally i find Spork + sublime Text2 Rspec bundle is really helpful and significantly fast!
As of MiniTest 4.2.0 you can run tests in parallel with parallelize_me.
Oh man that's great. I feel the reason that ryan chose to focus on Rspec in this episode is that it is still widespread in most existing applications. And, the rails core team took minitest out of rails 4 for the time being.
I'm using minitest spec in my latest application, the tests are blazingly fast.
I was curious how this setup compares with using MiniTest or how much faster MiniTest and MiniTest Spec would be when using some of these gems and techniques.
Ryan, FactoryGirl.build implictly creates records in database when it has associations. Maybe it's better to use just Model.new for things like validations instead of build()?
That's absolutely the case. I believe Model.new is faster than 'build' method. There's an article about it: http://blog.12spokes.com/web-design-development/how-factorygirl-can-slow-down-your-test-suite-aka-factory-build-vs-blank-activerecord-objects/
You can use build_stubbed, that will build object with stubbed associations.
that's really good.
Would have liked to see this cast for Test::Unit too... ;-)
Only one problem with zeus and guard:
When we are using it, randomized with seed is always 0. Any solutions/suggestions? Is not a very big deal nonetheless.
Please open an issue on zeus on github
I've been dealing with this problem a lot lately while building a multi-tenancy app. Corey Haines' view on TDD is very interesting, and I encourage anyone interested to check out his brand new screencast episodes on Clean Coders.
If you have problems with url helpers while running zeus, I could be wrong but believe it's because of this here.
I applaud that effort to optimize time, but like spork, I've kicked zeus to the curb. They make the test environment just a little too dissimilar from the production and development environments. I wind up spending a lot of time tracking down bugs in my code... or my tests... only to learn it's neither; it's my testing environment flaking out. So how much time is it really saving? (BIG fan of guard, though.)
I have this test which is taking 5 seconds to run:
describe "GET /event/id" do
it "allows flagging an event", js: true do
create(:recording, event: user_event)
How would I speed up a test like that? -- I'm using poltergeist with phantomjs and all js: true tests are painfully slow :(
You can tag it as 'slow' and just run it on CI.
I suspect your test is so slow because of page.should_not have_content. Instead use page.should have_no_content
The first one will wait and see if the content appears. The second will test straight away that there is no content.
I had problems getting zeus and guard working nicely together until I found that I had to upgrade guard-rspec to 2.1.0 or greater
gem 'guard-rspec', "~> 2.1.0"
I've got everything working except parallel in guard. I have zeus running parallel and zeus working within guard, I've added the parallel: true to my guardfile.
Would this be an issue with guard, guard-rspec or parallel_tests? What versions of these gems should I be running?
Hope it helps ;)
Is anybody else receiving this error?
To replicate you clone the repo for the episode, go into the after folder and run
time bundle exec rake spec:models
I am using ruby 1.9.3-p385 and rbenv.
Episode translates single digit seconds into timecode with minutes
Failure/Error: build(:episode, seconds: 60*8+3).timecode.should eq('8:03')
uninitialized constant Episode::TimeDuration
# ./app/models/episode.rb:8:in `duration'
# ./app/models/episode.rb:5:in `timecode'
# ./spec/models/episode_spec.rb:19:in `block (2 levels) in <top (required)>'
I did a crude fix that seems to work. I basically just required the time_duration library from inside models/episode.rb.
class Episode < ActiveRecord::Base
Please correct me if this is the wrong approach :)
What a great episode! Thanks a lot for this, my test-suite is much faster now!
Wow my test suite went from 1min30sec to 58 sec just by using the GC trick! Thank you!
What about the sqlite :memory: database ? I have been using this since months for my tests, just to speed up the database transactions without having to change the specs. Not sure how big the gain is in the current rails but it was a big improvement once.
hi does anybody knows or can point me to some examples if using the above with mongodb?
This gem https://github.com/evrone/factory_girl-seeds helps to minimize total spec run time by preloading records for factory_girl and then use them in spec.
Why running tests with rspec is faster than with rake? What's rake doing unnecessarily?
It seems that one of the things rspec-rails does is to add 'test:prepare' as a dependency to the test task. Commented it in the activerecord databases.rake to check and it's accountable for 2 seconds here.
Still cannot figure out where the other 2 seconds goes.
This bug has been fixed in Rails 4.
First sign in through GitHub to post a comment.