Permalink
Browse files

Updating tests to work with latest shoulda

  • Loading branch information...
mikel committed Dec 21, 2010
1 parent 47b3ebc commit ab050fdd1d499d6456e08d7490b7f5e4b5a8059e
Showing with 37 additions and 10 deletions.
  1. +28 −8 test/factory_data_test.rb
  2. +8 −2 test/preloader_test.rb
  3. +1 −0 test/test_helper.rb
View
@@ -7,50 +7,68 @@ def setup
context 'Calling FactoryData.preload(:users)' do
setup do
+ @user_count = User.count
FactoryData.preload(:users) do |data|
data.add(:thom) { User.create(:first_name => 'Thom', :last_name => 'York') }
end
end
- should_not_change 'User.count'
- should_change "FactoryData.methods.include?('users')", :from => false, :to => true
+ should "not change User.count" do
+ assert_equal(@user_count, User.count)
+ end
+
+ should "change FactoryData.methods.include?('users') to true" do
+ assert_equal(true, FactoryData.methods.include?('users'))
+ end
context 'when there was a previous user record in the database' do
setup { User.create(:first_name => 'Barack', :last_name => 'Obama') }
context 'and calling FactoryData.delete_preload_data!' do
setup { FactoryData.delete_preload_data! }
- should_change 'User.count', :to => 0
+
+ should "change User.count to 0" do
+ assert_equal(0, User.count)
+ end
end
end
context 'and later calling FactoryData.preload_data!' do
setup do
+ @user_count = User.count
@out, @err = OutputCapturer.capture do
FactoryData.preload_data!
end
end
- should_change 'User.count', :by => 1
+ should "change User.count by 1" do
+ assert_equal(@user_count + 1, User.count)
+ end
context 'and later re-defining the preloaders' do
setup do
+ @user_count = User.count
FactoryData.preload(:users) do |data|
data.add(:thom) { User.create(:first_name => 'Thom', :last_name => 'York') }
data.add(:john) { User.create(:first_name => 'John', :last_name => 'Doe') }
end
end
- should_change 'User.count', :by => -1
+ should "change User.count by - 1" do
+ assert_equal(@user_count - 1, User.count)
+ end
context 'and preloading the re-defined preloader' do
setup do
+ @user_count = User.count
@out, @err = OutputCapturer.capture do
FactoryData.preload_data!
end
end
- should_change 'User.count', :by => 2
+ should "create 2 users" do
+ assert_equal(@user_count + 2, User.count)
+ end
end
end
@@ -76,10 +94,12 @@ def setup
end
context 'and later calling FactoryData.reset_cache!' do
- setup { FactoryData.reset_cache! }
+ setup do
+ FactoryData.reset_cache!
+ end
should 'reload the record from the database the next time FactoryData.users(key) is called' do
- User.expects(:find).once.returns(@user)
+ User.expects(:find_by_id).once.returns(@user)
FactoryData.users(:thom)
end
end
View
@@ -20,12 +20,15 @@ def setup
context 'when preloaded' do
setup do
+ @user_count = User.count
@out, @err = OutputCapturer.capture do
@preloader.preload!
end
end
- should_change 'User.count', :by => 2
+ should 'change User.count by 2' do
+ assert_equal(@user_count + 2, User.count)
+ end
should 'return the preloaded data when #get_record is called' do
assert_equal 'York', @preloader.get_record(:thom).last_name
@@ -39,6 +42,7 @@ def setup
context 'when preloaded again' do
setup do
+ @user_count = User.count
@out, @err = OutputCapturer.capture do
@preloader.preload!
end
@@ -49,7 +53,9 @@ def setup
assert_equal '', @out
end
- should_not_change 'User.count'
+ should 'not change User.count' do
+ assert_equal(@user_count, User.count)
+ end
end
should 'issue a delete statement if #delete_table_data! is called' do
View
@@ -1,6 +1,7 @@
require 'rubygems'
require 'test/unit'
require 'shoulda'
+require 'sqlite3'
begin
require 'ruby-debug'

0 comments on commit ab050fd

Please sign in to comment.