Skip to content

Instantly share code, notes, and snippets.

@dchelimsky
Created January 10, 2011 18:24
Show Gist options
  • Save dchelimsky/773190 to your computer and use it in GitHub Desktop.
Save dchelimsky/773190 to your computer and use it in GitHub Desktop.
# if you're converting a stock rails test/unit suite to rspec-2, this little business can help
module TestToSpec
def self.included(includer)
includer.class_eval do
def test(*args, &block)
example(*args, &block)
end
end
end
end
RSpec.configure {|c| c.include TestToSpec}
# with that ^^ in place, the steps to convert are:
#
# 1. move test/functionals/things_controller_test.rb to spec/controllers/things_controller_spec.rb
# 2. require 'spec_helper' instead of 'test_helper'
# 3. change `class ThingsControllerTest < Test::Unit::TestCase` to `describe ThingsController do`
#
# Assuming you are using the `test "test name" do` format in your t/u suite, the above helper will convert
# test methods to RSpec examples. All of the test/unit assertions and rails assertions will continue to work,
# so standard tests should just work at this point.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment