Permalink
Browse files

Moved unit specifications into spec/unit

* spec/unit/* specs should specify the behaviour of the associated
  code with no external dependencies.
* Updated autotest rules to match file layout change
* Updated require paths within the unit specs
  • Loading branch information...
1 parent 19d6c98 commit 81d2787c0e427c0e805d15be69190c80a8c21b2d Dan Kubb committed Apr 10, 2008
Showing with 304 additions and 294 deletions.
  1. +19 −15 .autotest
  2. +0 −1 spec/integration/type_spec.rb
  3. +1 −1 spec/spec.opts
  4. +2 −0 spec/spec_helper.rb
  5. +10 −10 spec/{ → unit}/adapters/abstract_adapter_spec.rb
  6. +0 −1 spec/{ → unit/adapters}/adapter_shared_spec.rb
  7. +39 −39 spec/{ → unit}/adapters/data_objects_adapter_spec.rb
  8. +6 −6 spec/{ → unit}/associations/many_to_many_spec.rb
  9. +1 −1 spec/{ → unit}/associations/many_to_one_spec.rb
  10. +3 −3 spec/{ → unit}/associations/one_to_many_spec.rb
  11. +3 −2 spec/{ → unit}/associations/one_to_one_spec.rb
  12. +20 −20 spec/{ → unit}/associations/relationship_spec.rb
  13. +23 −24 spec/{ → unit}/cli_spec.rb
  14. +9 −9 spec/{ → unit}/dependency_spec.rb
  15. +40 −37 spec/{ → unit}/hook_spec.rb
  16. +38 −39 spec/{ → unit}/identity_map_spec.rb
  17. +4 −4 spec/{ → unit}/loaded_set_spec.rb
  18. +2 −2 spec/{ → unit}/naming_conventions_spec.rb
  19. +1 −1 spec/{ → unit}/property_set_spec.rb
  20. +3 −3 spec/{ → unit}/property_spec.rb
  21. +1 −1 spec/{ → unit}/query_spec.rb
  22. +8 −8 spec/{ → unit}/repository_spec.rb
  23. +3 −3 spec/{ → unit}/resource_spec.rb
  24. +1 −1 spec/{ → unit}/scope_spec.rb
  25. +38 −36 spec/{ → unit}/support/aliasinghash_spec.rb
  26. +1 −1 spec/{ → unit}/support/blank_spec.rb
  27. +1 −1 spec/{ → unit/support}/inflection_spec.rb
  28. +4 −4 spec/{ → unit}/support/object_spec.rb
  29. +2 −2 spec/{ → unit}/support/string_spec.rb
  30. +6 −6 spec/{ → unit}/support/struct_spec.rb
  31. +15 −13 spec/{ → unit}/type_spec.rb
View
@@ -1,22 +1,26 @@
Autotest.add_hook :initialize do |at|
- ignore = %w{.git burn www log plugins script tasks bin CHANGELOG FAQ MIT-LICENSE PERFORMANCE QUICKLINKS README}
+ ignore = %w[ .git burn www log plugins script tasks bin CHANGELOG FAQ MIT-LICENSE PERFORMANCE QUICKLINKS README ]
+
unless ENV['AUTOTEST'] == 'integration'
ignore << 'spec/integration'
end
-
- ignore.each do |exception|
+
+ ignore.each do |exception|
at.add_exception(exception)
end
-
+
at.clear_mappings
- at.add_mapping(%r%^spec/.*\.rb$%) { |filename, _|
- filename
- }
- at.add_mapping(%r%^lib/data_mapper/(.*)\.rb$%) { |_, m|
- ["spec/#{m[1]}_spec.rb"]
- }
- at.add_mapping(%r%^spec/spec_helper.rb$%) {
- at.files_matching %r%^spec/.*_spec\.rb$%
- }
-
-end
+
+ at.add_mapping(%r{^spec/.+_spec\.rb$}) do |filename,_|
+ filename
+ end
+
+ at.add_mapping(%r{^lib/data_mapper/(.+)\.rb$}) do |_,match|
+ [ "spec/unit/#{match[1]}_spec.rb" ] +
+ at.files_matching(%r{^spec/integration/.+_spec\.rb$})
+ end
+
+ at.add_mapping(%r{^spec/spec_helper\.rb$}) do
+ at.files_matching(%r{^spec/.+_spec\.rb$})
+ end
+end
@@ -49,7 +49,6 @@ class Coconut
coconut = TypeTests::Coconut.new(:faked => 'bob', :document => @document, :stuff => @stuff)
coconut.faked.should == 'bob'
coconut.document.should be_a_kind_of(Array)
- p coconut.stuff
coconut.stuff.should be_a_kind_of(Hash)
end
View
@@ -1 +1 @@
---require spec/spec_helper
+
View
@@ -10,6 +10,8 @@
require __DIR__.parent + 'environment'
require __DIR__ + 'mock_adapter'
+ROOT_DIR = __DIR__.parent
+
class Article
include DataMapper::Resource
@@ -1,40 +1,40 @@
require 'pathname'
-require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
+require Pathname(__FILE__).dirname.expand_path.parent.parent + 'spec_helper'
-require __DIR__.parent.parent + 'lib/data_mapper/adapters/abstract_adapter'
-require __DIR__.parent + 'adapter_shared_spec'
+require ROOT_DIR + 'lib/data_mapper/adapters/abstract_adapter'
+require __DIR__ + 'adapter_shared_spec'
describe DataMapper::Adapters::AbstractAdapter do
before do
@adapter = DataMapper::Adapters::AbstractAdapter.new(:default, 'mock_uri_string')
end
it_should_behave_like 'a DataMapper Adapter'
-
+
it "should raise NotImplementedError when #create is called" do
lambda { @adapter.create(:repository, :instance) }.should raise_error(NotImplementedError)
end
-
+
it "should raise NotImplementedError when #read is called" do
lambda { @adapter.read(:repository, :resource, [:key]) }.should raise_error(NotImplementedError)
end
-
+
it "should raise NotImplementedError when #update is called" do
lambda { @adapter.update(:repository, :instance) }.should raise_error(NotImplementedError)
end
-
+
it "should raise NotImplementedError when #delete is called" do
lambda { @adapter.delete(:repository, :instance) }.should raise_error(NotImplementedError)
end
-
+
it "should raise NotImplementedError when #read_one is called" do
lambda { @adapter.read_one(:repository, :query) }.should raise_error(NotImplementedError)
end
-
+
it "should raise NotImplementedError when #read_set is called" do
lambda { @adapter.read_set(:repository, :query) }.should raise_error(NotImplementedError)
end
-
+
it "should raise NotImplementedError when #delete_set is called" do
lambda { @adapter.delete_set(:repository, :query) }.should raise_error(NotImplementedError)
end
@@ -1,9 +1,9 @@
require 'pathname'
-require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
+require Pathname(__FILE__).dirname.expand_path.parent.parent + 'spec_helper'
-require __DIR__.parent.parent + 'lib/data_mapper'
-require __DIR__.parent.parent + 'lib/data_mapper/adapters/data_objects_adapter'
-require __DIR__.parent + 'adapter_shared_spec'
+require ROOT_DIR + 'lib/data_mapper'
+require ROOT_DIR + 'lib/data_mapper/adapters/data_objects_adapter'
+require __DIR__ + 'adapter_shared_spec'
describe DataMapper::Adapters::DataObjectsAdapter do
before do
@@ -18,7 +18,7 @@
@mock_db = mock('DB Connection', :create_command => @mock_command, :close => true)
@adapter.stub!(:create_connection).and_return(@mock_db)
- end
+ end
it 'should #create_command from the sql passed' do
@mock_db.should_receive(:create_command).with('SQL STRING').and_return(@mock_command)
@@ -54,7 +54,7 @@
describe '#query' do
before do
- @mock_reader = mock('Reader', :fields => ['id', 'UserName', 'AGE'],
+ @mock_reader = mock('Reader', :fields => ['id', 'UserName', 'AGE'],
:values => [1, 'rando', 27],
:close => true)
@mock_command = mock('Command', :execute_reader => @mock_reader)
@@ -63,7 +63,7 @@
#make the while loop run exactly once
@mock_reader.stub!(:next!).and_return(true, nil)
@adapter.stub!(:create_connection).and_return(@mock_db)
- end
+ end
it 'should #create_command from the sql passed' do
@mock_db.should_receive(:create_command).with('SQL STRING').and_return(@mock_command)
@@ -140,15 +140,15 @@
describe DataMapper::Adapters::DataObjectsAdapter::SQL, "creating, reading, updating, deleting statements" do
before do
@adapter = DataMapper::Adapters::DataObjectsAdapter.new(:default, URI.parse('mock://localhost'))
-
+
class Cheese
include DataMapper::Resource
property :id, Fixnum, :serial => true
property :name, String
property :color, String
property :notes, String, :lazy => true
end
-
+
class LittleBox
include DataMapper::Resource
property :street, String, :key => true
@@ -157,14 +157,14 @@ class LittleBox
property :notes, String, :lazy => true
end
end
-
+
describe "#create_statement" do
- it 'should generate a SQL statement for all fields' do
+ it 'should generate a SQL statement for all fields' do
@adapter.create_statement(Cheese, Cheese.properties(@adapter.name).slice(:name, :color)).should == <<-EOS.compress_lines
INSERT INTO "cheeses" ("name", "color") VALUES (?, ?)
EOS
end
-
+
it "should generate a SQL statement for only dirty fields" do
@adapter.create_statement(Cheese, Cheese.properties(@adapter.name).slice(:name)).should == <<-EOS.compress_lines
INSERT INTO "cheeses" ("name") VALUES (?)
@@ -175,39 +175,39 @@ class LittleBox
EOS
end
end
-
+
describe "#create_statement_with_returning" do
-
- it 'should generate a SQL statement for all fields' do
+
+ it 'should generate a SQL statement for all fields' do
@adapter.create_statement_with_returning(Cheese, Cheese.properties(@adapter.name).slice(:name, :color)).should == <<-EOS.compress_lines
INSERT INTO "cheeses" ("name", "color") VALUES (?, ?) RETURNING "id"
EOS
end
-
- it "should generate a SQL statement for only dirty fields" do
+
+ it "should generate a SQL statement for only dirty fields" do
@adapter.create_statement_with_returning(Cheese, Cheese.properties(@adapter.name).slice(:name)).should == <<-EOS.compress_lines
INSERT INTO "cheeses" ("name") VALUES (?) RETURNING "id"
EOS
-
+
@adapter.create_statement_with_returning(Cheese, Cheese.properties(@adapter.name).slice(:color)).should == <<-EOS.compress_lines
INSERT INTO "cheeses" ("color") VALUES (?) RETURNING "id"
EOS
end
end
-
+
describe "#update_statement" do
-
- it 'should generate a SQL statement for all fields' do
+
+ it 'should generate a SQL statement for all fields' do
@adapter.update_statement(Cheese, Cheese.properties(@adapter.name).slice(:name, :color)).should == <<-EOS.compress_lines
UPDATE "cheeses" SET
"name" = ?,
"color" = ?
WHERE "id" = ?
EOS
end
-
- it "should generate a SQL statement for only dirty fields" do
+
+ it "should generate a SQL statement for only dirty fields" do
@adapter.update_statement(Cheese, Cheese.properties(@adapter.name).slice(:name)).should == <<-EOS.compress_lines
UPDATE "cheeses" SET "name" = ? WHERE "id" = ?
EOS
@@ -216,43 +216,43 @@ class LittleBox
UPDATE "cheeses" SET "color" = ? WHERE "id" = ?
EOS
end
-
+
it "should generate a SQL statement that includes a Composite Key" do
@adapter.update_statement(LittleBox, LittleBox.properties(@adapter.name).slice(:hillside)).should == <<-EOS.compress_lines
UPDATE "little_boxes" SET "hillside" = ? WHERE "street" = ? AND "color" = ?
EOS
-
+
@adapter.update_statement(LittleBox, LittleBox.properties(@adapter.name).slice(:color, :hillside)).should == <<-EOS.compress_lines
UPDATE "little_boxes" SET "color" = ?, "hillside" = ? WHERE "street" = ? AND "color" = ?
EOS
end
end
-
+
describe "#delete_statement" do
-
- it 'should generate a SQL statement for a serial Key' do
+
+ it 'should generate a SQL statement for a serial Key' do
@adapter.delete_statement(Cheese).should == <<-EOS.compress_lines
DELETE FROM "cheeses" WHERE "id" = ?
EOS
end
-
+
it "should generate a SQL statement for a Composite Key" do
@adapter.delete_statement(LittleBox).should == <<-EOS.compress_lines
DELETE FROM "little_boxes" WHERE "street" = ? AND "color" = ?
EOS
end
-
+
end
-
+
describe "#read_statement (without lazy attributes)" do
- it 'should generate a SQL statement for a serial Key' do
+ it 'should generate a SQL statement for a serial Key' do
@adapter.read_statement(Cheese, [1]).should == <<-EOS.compress_lines
SELECT "id", "name", "color" FROM "cheeses" WHERE "id" = ?
EOS
end
-
- it "should generate a SQL statement that includes a Composite Key" do
+
+ it "should generate a SQL statement that includes a Composite Key" do
@adapter.read_statement(LittleBox, ['Shady Drive', 'Blue']).should == <<-EOS.compress_lines
SELECT "street", "color", "hillside" FROM "little_boxes" WHERE "street" = ? AND "color" = ?
EOS
@@ -261,7 +261,7 @@ class LittleBox
end
describe '#uri options' do
- it 'should transform a fully specified option hash into a URI' do
+ it 'should transform a fully specified option hash into a URI' do
options = {
:adapter => 'mysql',
:host => 'davidleal.com',
@@ -271,18 +271,18 @@ class LittleBox
:database => 'you_can_call_me_al',
:socket => 'nosock'
}
-
+
adapter = DataMapper::Adapters::DataObjectsAdapter.allocate
- adapter.uri(options).should ==
+ adapter.uri(options).should ==
URI.parse("mysql://me:mypass@davidleal.com:5000/you_can_call_me_al?socket=nosock")
end
-
+
it 'should transform a minimal options hash into a URI' do
options = {
:adapter => 'mysql',
:database => 'you_can_call_me_al'
}
-
+
adapter = DataMapper::Adapters::DataObjectsAdapter.allocate
adapter.uri(options).should == URI.parse("mysql:///you_can_call_me_al")
end
@@ -1,29 +1,29 @@
require 'pathname'
-require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
+require Pathname(__FILE__).dirname.expand_path.parent.parent + 'spec_helper'
describe "DataMapper::Associations::ManyToMany" do
before do
@adapter = DataMapper::Repository.adapters[:relationship_spec] || DataMapper.setup(:relationship_spec, 'mock://localhost')
end
-
+
it "should allow a declaration" do
-
+
lambda do
class Supplier
many_to_many :manufacturers
end
end.should_not raise_error
end
-
+
describe DataMapper::Associations::ManyToMany::Instance do
before do
@this = mock("this")
@that = mock("that")
@relationship = mock("relationship")
@association = DataMapper::Associations::ManyToMany::Instance.new(@relationship, @that, nil)
end
-
+
end
-
+
end
@@ -1,5 +1,5 @@
require 'pathname'
-require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
+require Pathname(__FILE__).dirname.expand_path.parent.parent + 'spec_helper'
describe "DataMapper::Associations::ManyToOne" do
@@ -1,5 +1,5 @@
require 'pathname'
-require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
+require Pathname(__FILE__).dirname.expand_path.parent.parent + 'spec_helper'
describe "DataMapper::Associations::OneToMany" do
@@ -8,12 +8,12 @@
end
it "should allow a declaration" do
-
+
lambda do
class Manufacturer
one_to_many :vehicles
end
end.should_not raise_error
end
-
+
end
Oops, something went wrong.

0 comments on commit 81d2787

Please sign in to comment.