Skip to content

Instantly share code, notes, and snippets.

@hopsoft
Created February 24, 2012 04:08
Show Gist options
  • Save hopsoft/1897425 to your computer and use it in GitHub Desktop.
Save hopsoft/1897425 to your computer and use it in GitHub Desktop.
Minitest with Ruby 1.9 & Rails 3.1 that actually works
# No need to add any new gem dependencies for this to work.
# test/minitest_helper.rb
ENV["RAILS_ENV"] = "test"
require "minitest/autorun"
require File.expand_path("../../config/environment", __FILE__)
require "active_support/testing/setup_and_teardown"
require "active_record/fixtures"
module Hopsoft
module Spec
def self.included(mod)
mod.class_eval do
include ::ActiveSupport::Testing::SetupAndTeardown
include ::ActiveRecord::TestFixtures
alias :method_name :__name__ if defined? :__name__
self.fixture_path = File.join(Rails.root, 'test', 'fixtures')
end
end
# Add methods to be used by all specs here...
end
end
MiniTest::Spec.send(:include, Hopsoft::Spec)
# test/fixtures/users.yml
one:
name: one
email: [email protected]
encrypted_password: password
# test/unit/user.rb
require 'minitest_helper'
class UserTest < MiniTest::Spec
fixtures :users
describe User do
it "should pass" do
u = users(:one)
u.must_be_instance_of User
u.name.must_equal "one"
u.email.must_equal "[email protected]"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment