Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
class Note < ActiveRecord::Base
belongs_to :person
end

person_id = create_record Person, :myguy
create_record Note, :person => :myguy
Note.last.person_id == person_id
Expand Down Expand Up @@ -60,4 +60,4 @@

*1.0.0 [Scenarios Replacement] (December 15, 2008)

* Drop-in replacement for Scenarios plugin of old [aiwilliams]
* Drop-in replacement for Scenarios plugin of old [aiwilliams]
40 changes: 20 additions & 20 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -6,52 +6,52 @@ Dataset loads data intelligently if you use 'nested contexts' in your tests (RSp

describe Something do
dataset :a => Dataset :a is loaded (at the right time)
it 'should whatever'
end
describe More do

it 'should whatever'
end

describe More do
dataset :b => Dataset :b is loaded. :a data is still there
it 'should'
end
end

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


Get things installed, then read more in the Dataset documentation at http://aiwilliams.github.com/dataset

Expand Down Expand Up @@ -99,7 +99,7 @@ If you were a user of the Scenarios plugin, and want to do as little as possible
== Credits

Written by [Adam Williams](http://github.com/aiwilliams).

Contributors:

- [Saturn Flyer](http://www.saturnflyer.com) [github](http://github.com/saturnflyer)
Expand All @@ -108,4 +108,4 @@ Contributors:

---

Dataset is released under the MIT-License and is Copyright (c)2008 Adam Williams.
Dataset is released under the MIT-License and is Copyright (c)2008 Adam Williams.
4 changes: 2 additions & 2 deletions TODO
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
take any instance variables already in context and make them available to dataset blocks - this is for nested describes
I'm not sure about this one. It can be very frustrating to lose context of when the state of an iv is modified.

add ability to clear the database (some tests wanted to guarantee a clear db)
This is acheived with "dataset {}"

Expand All @@ -12,4 +12,4 @@ describe what happens when someone has a fixtures file - they get loaded after o
look into truncating database instead individual table deletes
allow configuration of dataset
* permatable / global scope
re-evaluation location of some tests that depend on TestCase in non-test/unit tests
re-evaluation location of some tests that depend on TestCase in non-test/unit tests
8 changes: 4 additions & 4 deletions dataset.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ Gem::Specification.new do |s|
s.add_runtime_dependency(%q<activesupport>, [">= 2.3.0"])
s.add_runtime_dependency(%q<activerecord>, [">= 2.3.0"])
else
s.add_dependency(%q<activesupport>, [">= 2.3.0"])
s.add_dependency(%q<activerecord>, [">= 2.3.0"])
s.add_dependency(%q<activesupport>, [">= 3.0.0"])
s.add_dependency(%q<activerecord>, [">= 3.0.0"])
end
else
s.add_dependency(%q<activesupport>, [">= 2.3.0"])
s.add_dependency(%q<activerecord>, [">= 2.3.0"])
s.add_dependency(%q<activesupport>, [">= 3.0.0"])
s.add_dependency(%q<activerecord>, [">= 3.0.0"])
end
end

30 changes: 15 additions & 15 deletions lib/dataset.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'activesupport'
require 'activerecord'
require 'active_support'
require 'active_record'

require 'dataset/version'
require 'dataset/instance_methods'
Expand All @@ -19,26 +19,26 @@
require 'dataset/record/model'

# == 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.
#
Expand Down Expand Up @@ -82,10 +82,10 @@ def self.included(test_context) # :nodoc:
else
raise "I don't understand your test framework"
end

test_context.extend ContextClassMethods
end

# Methods that are added to the class that Dataset is included in (the test
# context class).
#
Expand All @@ -96,10 +96,10 @@ def self.extended(context_class) # :nodoc:
superclass_delegating_accessor :dataset_session
end
end

mattr_accessor :datasets_database_dump_path
self.datasets_database_dump_path = File.expand_path(RAILS_ROOT + '/tmp/dataset') if defined?(RAILS_ROOT)
self.datasets_database_dump_path = File.expand_path(::Rails.root.to_s + '/tmp/dataset') if defined?(RAILS_ROOT)

# Replaces the default Dataset::Resolver with one that will look for
# dataset class definitions in the specified directory. Captures of the
# database will be stored in a subdirectory 'tmp' (see
Expand All @@ -108,15 +108,15 @@ def datasets_directory(path)
Dataset::Resolver.default = Dataset::DirectoryResolver.new(path)
Dataset::ContextClassMethods.datasets_database_dump_path = File.join(path, '/tmp/dataset')
end

def add_dataset(*datasets, &block) # :nodoc:
dataset_session = dataset_session_in_hierarchy
datasets.each { |dataset| dataset_session.add_dataset(self, dataset) }
dataset_session.add_dataset(self, Class.new(Dataset::Block) {
define_method :doload, block
}) unless block.nil?
end

def dataset_session_in_hierarchy # :nodoc:
self.dataset_session ||= begin
database_spec = ActiveRecord::Base.configurations['test'].with_indifferent_access
Expand All @@ -126,4 +126,4 @@ def dataset_session_in_hierarchy # :nodoc:
end
end
end
end
end
30 changes: 15 additions & 15 deletions lib/dataset/base.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Dataset

# The superclass of your Dataset classes.
#
# It is recommended that you create a dataset using the Dataset::Block
Expand All @@ -25,11 +25,11 @@ def helpers(&method_definitions)
end
@helper_methods.module_eval &method_definitions
end

def helper_methods # :nodoc:
@helper_methods
end

# Allows a subsclass to declare which datasets it uses.
#
# Dataset is designed to promote 'design by composition', rather than
Expand All @@ -54,16 +54,16 @@ def helper_methods # :nodoc:
# C uses B
# A uses C
# B, C, A is the load order
#
#
def uses(*datasets)
@used_datasets = datasets
end

def used_datasets # :nodoc:
@used_datasets
end
end

# Invoked once before a collection of tests is run. If you use a dataset
# in multiple test classes, it will be called once for each of them -
# remember that the database will be cleared at the beginning of running a
Expand All @@ -74,15 +74,15 @@ def used_datasets # :nodoc:
#
def load; end
end

# The easiest way to create some data before a suite of tests is run is by
# using a Dataset::Block. An example works wonders:
#
# class PeopleTest < Test::Unit::TestCase
# dataset do
# create_record :person, :billy, :name => 'Billy'
# end
#
#
# def test_name
# assert_equal 'Billy', people(:billy).name
# end
Expand All @@ -98,17 +98,17 @@ def load; end
#
# 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
Expand Down Expand Up @@ -136,7 +136,7 @@ def load; end
# id = create_record :person, :second_admin, :name => 'Admin Three'
# create_record :organization_administratorship, :organization_id => organization_id(:first_bank), :person_id => id
# end
#
#
# def test_admins
# assert organizations(:first_bank).admins.include?(people(:second_admin))
# end
Expand All @@ -147,11 +147,11 @@ def load; end
# When you need to go beyond the block, create a Dataset::Base subclass!
class Block < Base
include Dataset::InstanceMethods

def load # :nodoc:
dataset_session_binding.install_block_variables(self)
doload
dataset_session_binding.copy_block_variables(self)
end
end
end
end
6 changes: 3 additions & 3 deletions lib/dataset/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ class Collection < Array # :nodoc:
def initialize(parent)
concat parent
end

def <<(dataset)
super
uniq!
self
end

def subset?(other)
Set.new(self).subset?(Set.new(other))
end
end
end
end
4 changes: 1 addition & 3 deletions lib/dataset/extensions/rspec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module Dataset
module Extensions # :nodoc:

module RSpecExampleGroup # :nodoc:
def dataset(*datasets, &block)
add_dataset(*datasets, &block)
Expand All @@ -15,7 +14,6 @@ def dataset(*datasets, &block)
end
end
end

end
end
Spec::Example::ExampleGroup.extend Dataset::Extensions::RSpecExampleGroup
RSpec::Core::ExampleGroup.extend Dataset::Extensions::RSpecExampleGroup
Loading