Module: Dataset
- Defined in:
- lib/dataset.rb,
lib/dataset/base.rb,
lib/dataset/load.rb,
lib/dataset/session.rb,
lib/dataset/version.rb,
lib/dataset/resolver.rb,
lib/dataset/collection.rb,
lib/dataset/record/meta.rb,
lib/dataset/record/model.rb,
lib/dataset/database/base.rb,
lib/dataset/database/mysql.rb,
lib/dataset/record/fixture.rb,
lib/dataset/session_binding.rb,
lib/dataset/database/sqlite3.rb,
lib/dataset/extensions/rspec.rb,
lib/dataset/instance_methods.rb,
lib/dataset/record/heirarchy.rb,
lib/dataset/database/postgresql.rb,
lib/dataset/extensions/cucumber.rb,
lib/dataset/extensions/test_unit.rb
Overview
Quick Start
Write a test. If you want some data in your database, create a dataset. Start simple.
describe States do
dataset do
[%w(Colorado CO), %w(North\ Carolina NC), %w(South\ Carolina SC)].each do |name,abbrev|
create_record :state, abbrev.downcase, :name => name, :abbrev => abbrev
end
end
it 'should have an abbreviated name'
states(:nc).abbrev.should be('NC')
end
it 'should have a name'
states(:nc).name.should be('North Carolin')
end
end
Notice that you won’t be using find_id or find_model in your tests. You use methods like states and state_id, as in the example above.
When you find that you’re seeing patterns in the data you are creating, pull it into a class.
spec/datasets/states.rb
class StatesDataset < Dataset::Base
def load
# create useful data
end
end
spec/models/state.rb
describe State do
dataset :states
end
Installation
Dataset is installed into your testing environment by requiring the library, then including it into the class that will be the context of your test methods.
require 'dataset'
class Test::Unit::TestCase
include Dataset
datasets_directory "#{RAILS_ROOT}/test/datasets"
end
Note that should you desire your Dataset::Base subclasses be auto-discovered, you can set the datasets_directory.
Defined Under Namespace
Modules: ContextClassMethods, Database, Extensions, InstanceMethods, ModelFinders, Record, RecordMethods, VERSION Classes: Base, Block, Collection, DatasetNotFound, DirectoryResolver, Load, RecordNotFound, Reload, Resolver, Session, SessionBinding, TestSuite
Class Method Summary collapse
-
.included(test_context) ⇒ Object
:nodoc:.
Class Method Details
.included(test_context) ⇒ Object
:nodoc:
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/dataset.rb', line 75 def self.included(test_context) # :nodoc: if test_context.name =~ /World\Z/ require 'dataset/extensions/cucumber' elsif test_context.name =~ /TestCase\Z/ require 'dataset/extensions/test_unit' elsif test_context.name =~ /ExampleGroup\Z/ require 'dataset/extensions/rspec' else raise "I don't understand your test framework" end test_context.extend ContextClassMethods end |