Permalink
Browse files

Simplified a few tests and added tests for has_many associationsy

  • Loading branch information...
1 parent 80a4382 commit caf2698ddef19b198a2f6c48a6360e3341ce9027 @lawrencepit lawrencepit committed Jun 17, 2008
Showing with 31 additions and 53 deletions.
  1. +9 −17 spec/model_stubbing_spec.rb
  2. +11 −18 spec/model_stubbing_test.rb
  3. +11 −18 spec/model_stubbing_test_spec.rb
@@ -2,31 +2,19 @@
module ModelStubbing
describe "Sample Stub Usage" do
+ define_models
- define_models do
- time 2007, 6, 1
-
- model User do
- stub :name => 'fred', :admin => false
- stub :admin, :admin => true
- end
-
- model Post do
- stub :title => 'first', :user => all_stubs(:admin_model_stubbing_user), :published_at => current_time + 5.days
- end
- end
-
it "retrieves stubs" do
- model_stubbing_users(:default).name.should == 'fred'
+ model_stubbing_users(:default).name.should == 'bob'
model_stubbing_users(:default).admin.should == false
- model_stubbing_users(:admin).name.should == 'fred'
+ model_stubbing_users(:admin).name.should == 'bob'
model_stubbing_users(:admin).admin.should == true
end
it "retrieves new records based on stubs" do
record = new_model_stubbing_user(:default)
- record.name.should == 'fred'
+ record.name.should == 'bob'
record.admin.should == false
end
@@ -48,10 +36,14 @@ module ModelStubbing
custom.id.should == model_stubbing_users(:default, :admin => true).id
end
- it "associates stubs" do
+ it "associates belongs_to stubs" do
model_stubbing_posts(:default).user.should == model_stubbing_users(:admin)
end
+ it "associates has_many stubs" do
+ model_stubbing_posts(:nice_one).tags.should == [model_stubbing_tags(:foo), model_stubbing_tags(:bar)]
+ end
+
it "stubs current time" do
current_time.should == Time.utc(2007, 6, 1)
model_stubbing_posts(:default).published_at.should == Time.utc(2007, 6, 6)
@@ -4,31 +4,20 @@
module ModelStubbing
class SampleTest < Test::Unit::TestCase
- define_models do
- time 2007, 6, 1
-
- model User do
- stub :name => 'fred', :admin => false
- stub :admin, :admin => true
- end
-
- model Post do
- stub :title => 'first', :user => all_stubs(:admin_model_stubbing_user), :published_at => current_time + 5.days
- end
- end
+ define_models
def test_should_retrieve_stubs
- assert_equal 'fred', model_stubbing_users(:default).name
- assert_equal false, model_stubbing_users(:default).admin
+ assert_equal 'bob', model_stubbing_users(:default).name
+ assert_equal false, model_stubbing_users(:default).admin
- assert_equal 'fred', model_stubbing_users(:admin).name
+ assert_equal 'bob', model_stubbing_users(:admin).name
assert model_stubbing_users(:admin).admin
end
def test_should_retrieve_new_records_based_on_stubs
record = new_model_stubbing_user(:default)
- assert_equal 'fred', record.name
- assert_equal false, record.admin
+ assert_equal 'bob', record.name
+ assert_equal false, record.admin
end
def test_should_retrieve_instantiated_stubs
@@ -47,10 +36,14 @@ def test_should_generate_custom_stubs
assert_equal custom.id, model_stubbing_users(:default, :admin => true).id
end
- def test_should_associate_stubs
+ def test_should_associate_belongs_to_stubs
assert_equal model_stubbing_users(:admin), model_stubbing_posts(:default).user
end
+ def test_should_associate_has_many_stubs
+ assert_equal model_stubbing_posts(:nice_one).tags, [model_stubbing_tags(:foo), model_stubbing_tags(:bar)]
+ end
+
def test_should_stub_current_time
assert_equal Time.utc(2007, 6, 1), current_time
assert_equal Time.utc(2007, 6, 6), model_stubbing_posts(:default).published_at
@@ -4,31 +4,20 @@
module ModelStubbing
describe "Sample" do
- define_models do
- time 2007, 6, 1
-
- model User do
- stub :name => 'fred', :admin => false
- stub :admin, :admin => true
- end
-
- model Post do
- stub :title => 'first', :user => all_stubs(:admin_model_stubbing_user), :published_at => current_time + 5.days
- end
- end
+ define_models
def test_should_retrieve_stubs
- assert_equal 'fred', model_stubbing_users(:default).name
- assert_equal false, model_stubbing_users(:default).admin
+ assert_equal 'bob', model_stubbing_users(:default).name
+ assert_equal false, model_stubbing_users(:default).admin
- assert_equal 'fred', model_stubbing_users(:admin).name
+ assert_equal 'bob', model_stubbing_users(:admin).name
assert model_stubbing_users(:admin).admin
end
def test_should_retrieve_new_records_based_on_stubs
record = new_model_stubbing_user(:default)
- assert_equal 'fred', record.name
- assert_equal false, record.admin
+ assert_equal 'bob', record.name
+ assert_equal false, record.admin
end
def test_should_retrieve_instantiated_stubs
@@ -47,10 +36,14 @@ def test_should_generate_custom_stubs
assert_equal custom.id, model_stubbing_users(:default, :admin => true).id
end
- def test_should_associate_stubs
+ def test_should_associate_belongs_to_stubs
assert_equal model_stubbing_users(:admin), model_stubbing_posts(:default).user
end
+ def test_should_associate_has_many_stubs
+ assert_equal model_stubbing_posts(:nice_one).tags, [model_stubbing_tags(:foo), model_stubbing_tags(:bar)]
+ end
+
def test_should_stub_current_time
assert_equal Time.utc(2007, 6, 1), current_time
assert_equal Time.utc(2007, 6, 6), model_stubbing_posts(:default).published_at

0 comments on commit caf2698

Please sign in to comment.