Skip to content

Commit

Permalink
switching the readme to markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-manges committed Oct 10, 2008
1 parent 7b9e463 commit ab31b71
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 67 deletions.
20 changes: 20 additions & 0 deletions LICENSE
@@ -0,0 +1,20 @@
Copyright (c) 2007-2008 Dan Manges

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
83 changes: 83 additions & 0 deletions README.markdown
@@ -0,0 +1,83 @@
UnitRecord
==========

Enables unit testing ActiveRecord classes without hitting the database.

Why?
----

Rationale: [http://www.dcmanges.com/blog/rails-unit-record-test-without-the-database](http://www.dcmanges.com/blog/rails-unit-record-test-without-the-database)

The biggest benefit to disconnecting unit tests from the database is having a faster test suite. Here is the benchmark from one of my current projects:

Finished in 19.302702 seconds.
4920 tests, 7878 assertions, 0 failures, 0 errors

4 seconds per 1,000 tests is a good guideline.

Installation
------------

gem install unit_record

Usage
-----

Restructuring the Rails Test Directory
--------------------------------------

The Rails test directory typically places testing for models under <tt>test/unit</tt> and tests for controllers under <tt>test/functional</tt>. However, we need to change the definition of unit and functional. Controllers can be unit tested (mocking out models and not rendering the view). Models can be functionally tested (hitting the database). Also, each type of test needs its own test\_helper. I recommend restructuring your test directory like this:

test
test_helper.rb
unit
unit_test_helper.rb
controllers
models
functional
functional_test_helper.rb
controllers
models

You should move existing functional tests into functional/controllers. You will also need to change the require line at the top of those tests to require the functional\_test\_helper.rb file instead of the test\_helper.rb file.

The <tt>functional_test_helper.rb</tt> file only needs to require <tt>test_helper.rb</tt>:

require File.dirname(__FILE__) + "/../test_helper"

For moving unit tests, you have a few options. I recommend moving them to unit/models and then disconnecting your unit tests from the database. Any tests that fail should then be modified to not hit the database or moved to functional/models.

Disconnecting
-------------

In the <tt>test/unit/unit\_test\_helper.rb</tt> file you created when restructuring your test directory, you should add these lines:

require File.dirname(__FILE__) + "/../test_helper"
require "unit_record"
ActiveRecord::Base.disconnect!

The <tt>disconnect!</tt> method will do everything necessary to run your unit tests without hitting the database.

Development
-----------

Active development occurs on the [GitHub](http://github.com/dan-manges/unit-record). Changes are pushed to the Rubyforge git repository.

Thanks
------
Thanks to Jay Fields for the [original implementation](http://blog.jayfields.com/2007/03/rails-activerecord-unit-testing-part-ii.html).

Maintainer
----------

[Dan Manges](http://www.dcmanges.com)

Contributors
------------

* David Lowenfels
* Rob Sanheim

License
-------
Released under the MIT license
67 changes: 0 additions & 67 deletions README.rdoc

This file was deleted.

7 changes: 7 additions & 0 deletions Rakefile
Expand Up @@ -72,6 +72,13 @@ namespace :gemspec do
end end
end end


task :readme do
require "rubygems"; gem "BlueCloth"; require "BlueCloth"; require 'tmpdir'
file = "#{Dir.tmpdir}/readme.html"
File.open(file, "w") { |f| f.write BlueCloth.new(File.read("README.markdown")).to_html }
sh "open #{file}"
end

RAILS_VERSIONS = %w[1.2.6 2.0.2 2.1.0 2.1.1] RAILS_VERSIONS = %w[1.2.6 2.0.2 2.1.0 2.1.1]


namespace :test do namespace :test do
Expand Down

0 comments on commit ab31b71

Please sign in to comment.