Skip to content

Commit

Permalink
whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
saturnflyer committed Feb 22, 2013
1 parent ae916af commit c522e95
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 94 deletions.
38 changes: 19 additions & 19 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 Down
16 changes: 8 additions & 8 deletions lib/dataset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,14 +82,14 @@ def self.extended(context_class) # :nodoc:
superclass_delegating_accessor :dataset_session
end
end

# 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 Dataset::Database::Base).
def set_dataset_resolver
Dataset::Resolver.default ||= Dataset::DirectoryResolver.new(RSpec.configuration.datasets_directory)
end

def add_dataset(*datasets, &block) # :nodoc:
set_dataset_resolver
dataset_session = dataset_session_in_hierarchy
Expand All @@ -98,7 +98,7 @@ def add_dataset(*datasets, &block) # :nodoc:
define_method :doload, block
}) unless block.nil?
end

def dataset_session_in_hierarchy # :nodoc:
self.dataset_session ||= begin
database_spec = ActiveRecord::Base.configurations[Rails.env].with_indifferent_access
Expand Down
16 changes: 8 additions & 8 deletions lib/dataset/extensions/test_unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,40 @@ def initialize(suite, test_class)
@suite = suite
@test_class = test_class
end

def dataset_session
@test_class.dataset_session
end

def run(result, &progress_block)
if dataset_session
load = dataset_session.load_datasets_for(@test_class)
@suite.tests.each { |e| e.extend_from_dataset_load(load) }
end
@suite.run(result, &progress_block)
end

def method_missing(method_symbol, *args)
@suite.send(method_symbol, *args)
end
end

module Extensions # :nodoc:

module TestUnitTestCase # :nodoc:
def self.extended(test_case)
class << test_case
alias_method_chain :suite, :dataset
end
end

def suite_with_dataset
Dataset::TestSuite.new(suite_without_dataset, self)
end

def dataset(*datasets, &block)
add_dataset(*datasets, &block)

# Unfortunately, if we have rspec loaded, TestCase has it's suite method
# modified for the test/unit runners, but uses a different mechanism to
# collect tests if the rspec runners are used.
Expand Down
2 changes: 1 addition & 1 deletion lib/dataset/tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
task :load => :environment do
require 'dataset'
dataset_names = (ENV['DATASETS'] || 'default').split(',')

context = Class.new do
extend Dataset::ContextClassMethods
datasets_directory [
Expand Down
34 changes: 17 additions & 17 deletions spec/dataset/rspec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@ class Spec::Example::ExampleGroup
group = Class.new(Spec::Example::ExampleGroup)
group.should respond_to(:dataset)
end

it 'should load the dataset when the group is run' do
load_count = 0
dataset = Class.new(Dataset::Base) do
define_method(:load) do
load_count += 1
end
end

group = Class.new(Spec::Example::ExampleGroup) do
self.dataset(dataset)
it('one') {}
it('two') {}
end

group.run options
load_count.should be(1)
end

it 'should load datasets in nested groups' do
dataset_one = Class.new(Dataset::Base) do
define_method(:load) do
Expand All @@ -40,7 +40,7 @@ class Spec::Example::ExampleGroup
Place.create!
end
end

group = Class.new(Spec::Example::ExampleGroup) do
dataset(dataset_one)
it('one') {}
Expand All @@ -49,24 +49,24 @@ class Spec::Example::ExampleGroup
dataset(dataset_two)
it('two') {}
end

group.run options
Thing.count.should be(1)
Place.count.should be(0)

group_child.run options
Thing.count.should be(1)
Place.count.should be(1)
end

it 'should expose data reading methods from dataset binding to the test methods through the group instances' do
created_model = nil
dataset = Class.new(Dataset::Base) do
define_method(:load) do
created_model = create_model(Thing, :dataset_thing)
end
end

found_in_before_all, dataset_thing_in_example = nil
created_in_before_all, before_all_thing_in_example = nil
created_in_example = nil
Expand All @@ -82,22 +82,22 @@ class Spec::Example::ExampleGroup
created_in_example = create_model(Thing)
end
end

group.run options
group.should_not respond_to(:things)

dataset_thing_in_example.should_not be_nil
dataset_thing_in_example.should == created_model

found_in_before_all.should_not be_nil
found_in_before_all.should == created_model

created_in_before_all.should_not be_nil
before_all_thing_in_example.should == created_in_before_all

created_in_example.should_not be_nil
end

it 'should expose dataset helper methods to the test methods through the group instances' do
dataset_one = Class.new(Dataset::Base) do
helpers do
Expand All @@ -112,7 +112,7 @@ def helper_two; end
end
def load; end
end

group = Class.new(Spec::Example::ExampleGroup) do
self.dataset(dataset_two)
before(:all) do
Expand All @@ -124,7 +124,7 @@ def load; end
self.should respond_to(:helper_two)
end
end

group.run options
group.should_not respond_to(:helper_one)
group.should_not respond_to(:helper_two)
Expand Down
Loading

0 comments on commit c522e95

Please sign in to comment.