Plugin details

An exceptional tool for creating test data sets using ActiveRecord.

Websitehttp://aiwilliams.github.com/dataset Repositorygit://github.com/karsthammer/dataset.git Author Adam Williams LicenseMIT

Documentation

Install the plugin:
ruby script/plugin install git://github.com/karsthammer/dataset.git

Dataset provides a simple API for creating and finding sets of data in your database. Check out Dataset::RecordMethods and Dataset::ModelFinders.

Dataset loads data intelligently if you use 'nested contexts' in your tests (RSpec, anything that uses Test::Unit::TestCase subclassing for creating nested contexts):

    describe Something do
      dataset :a              => Dataset :a is loaded (at the right time)
                              
      it 'should whatever'    
      end                     
                              
      describe More do        
        dataset :b            => Dataset :b is loaded. :a data is still there
                              
        it 'should'           
        end                   
      end                     
                              
      describe Another do     => Database is restored to :a, without re-running :a logic
        it 'should'
        end
      end
    end


The goal is to see a marked improvement in overall test run speed, basing this on the assumption that it is faster to have the OS copy a file or mySQL dump and load. Of course, we may find this to be a false assumption, but there were plenty of bugs in the former 'Scenarios' - addressing that afforded the opportunity to test the assumption.


Dataset does not prevent you from using other libraries like Machinist or factory_girl. If you were to used either of those, you could have a dataset like this:

    require 'faker'
    
    class OrganizationsDataset < Dataset::Base
      Sham.name  { Faker::Name.name }
      
      Organization.blueprint do
        name { Sham.name }
      end
      
      def load
        name_model Organization.make, :org_one
      end
    end


The benefit is that you can reuse interesting sets of data, without sacrificing the utility of those other libraries.

    describe Organization, 'stuff' do
      dataset :organizations
    end
    
    describe Organization, 'other stuff' do
      dataset :organizations
    end

Further Documentation

There is currently no advanced documentation for this plugin.

New documentation

Edit plugin | (0 older versions) | Last edited by: hardway, about 1 year ago