Archive for the 'testing' Category

22
May
12

making sure your integration tests view the actual data in the db


Monkeypatch ActiveRecord with this:


class ActiveRecord::Base
  mattr_accessor :shared_connection
  @@shared_connection = nil

  def self.connection
    @@shared_connection || retrieve_connection
  end
end

and your spec_helper with this:


RSpec.configure do |config|
  config.use_transactional_fixtures = false

  config.before :each do
    if Capybara.current_driver == :rack_test
      DatabaseCleaner.strategy = :transaction
    else
      DatabaseCleaner.strategy = :truncation
    end
    DatabaseCleaner.start
  end

  config.after do
    DatabaseCleaner.clean
  end
end

Full info available on Nicholas Rutherford’s blog. Thanks Nicholas!

08
Aug
11

test/unit run only specified test


class Whatever < Test::Unit::TestCase
  def test_case_1
    # code
  end

  def test_case_2
    # code
  end
end

By default, both testcases will be ran. If you want to run only a testcase, do like this:

ruby test.rb --name test_case_2

29
Nov
09

me & unit testing


Just started to learn about unit testing. Insanely useful!




Blog Stats

  • 216,750 hits