Tuesday, March 31, 2015

Run multiple instances of RSpec on same machine

Sime times you are stuck with realy badly written Rails project (or other application which comunicates with Database) which entire test suite takes ages to run. You want to run all the tests but you while they running you want to continue your TDD work.
If you run RSpec multiple times (multiple instances at a same time) you may break one of test suits because you will write data to same database both RSpec instances are comunicating with.
One way to handle this is if you run rspecs on different databases
# config/database.yml
default: &default
  adapter: mysql2
  encoding: utf8
  reconnect: false
  pool: 5
  username: root
  password: my_development_password
  socket: /var/run/mysqld/mysqld.sock

development:
  <<: *default
  database: myapp_development

test:
  <<: *default
  database: myapp_test<%= ENV['TEST_ENV_NUMBER'] %>
 RAILS_ENV=test TEST_ENV_NUMBER=2 rake db:create
 RAILS_ENV=test TEST_ENV_NUMBER=2 rake db:migrate

 TEST_ENV_NUMBER=2 rspec spec/
 If you are looking for solution how to run same test suite on multiple databases check https://github.com/grosser/parallel_tests

https://github.com/equivalent/scrapbook2/blob/master/archive/mini-blogs/2015-03-30-run-multiple-times-rspec-on-same-machine.md

Override Rails default rake task


desc "this will be now a default task"
task info: :environment do
    puts 'Run rake test to test'
end

task(:default).clear.enhance(['info'])
source

Tuesday, March 3, 2015

Carrierwave uploader not triggering proces in RSpec

processing is turn off for sake of test speed
# spec/my_test.spec
before do
  DocumentUploader.enable_processing = true
end
It's probably because you have something like
# config/initializers/carrierwave.rb
if Rails.env.test?
  CarrierWave.configure do |config|
    config.storage = :file
    config.enable_processing = false
  end
else
  CarrierWave.configure do |config|
    config.storage = :fog
  end
end
I recommend to keep the enable_processing = false and just overide it when needed