Permalink
Browse files

Making all tests pass

  • Loading branch information...
1 parent f4b134b commit 80a4382c2c303097c5838734a90df3f85dcf5880 @lawrencepit lawrencepit committed Jun 17, 2008
View
@@ -60,4 +60,5 @@ def self.guess_mock_framework!
end
end
-Test::Unit::TestCase.extend ModelStubbing
+Test::Unit::TestCase.extend ModelStubbing
+Spec::Example::ExampleGroup.extend ModelStubbing if defined? Spec::Example::ExampleGroup
@@ -68,7 +68,7 @@ def ==(defn)
def setup_on(base, options = {}, &block)
self.insert = false if options[:insert] == false
self.instance_eval(&block) if block
- if base.ancestors.include? Test::Unit::TestCase
+ if base.ancestors.any? { |a| a.to_s == "Test::Unit::TestCase" || a.to_s == "Spec::Example::ExampleGroup" }
unless base.ancestors.include?(ModelStubbing::Extension)
base.send :include, ModelStubbing::Extension
end
View
@@ -27,7 +27,7 @@ module ModelStubbing
end
it "keeps order of defined models" do
- @definition.ordered_models.should == [@definition.models[:model_stubbing_users], @definition.models[:model_stubbing_foo_bars], @definition.models[:model_stubbing_posts]]
+ @definition.ordered_models.should == [@definition.models[:model_stubbing_users], @definition.models[:model_stubbing_foo_bars], @definition.models[:model_stubbing_tags], @definition.models[:model_stubbing_posts]]
end
end
@@ -2,6 +2,7 @@
module ModelStubbing
describe "Sample Stub Usage" do
+
define_models do
time 2007, 6, 1
@@ -51,7 +52,7 @@ module ModelStubbing
model_stubbing_posts(:default).user.should == model_stubbing_users(:admin)
end
- it "stubbs current time" do
+ 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)
end
@@ -2,56 +2,58 @@
require 'test/unit'
require 'mocha'
-class SampleTest < Test::Unit::TestCase
- define_models do
- time 2007, 6, 1
-
- model User do
- stub :name => 'fred', :admin => false
- stub :admin, :admin => true
+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
- model Post do
- stub :title => 'first', :user => all_stubs(:admin_user), :published_at => current_time + 5.days
- end
- end
-
- def test_should_retrieve_stubs
- assert_equal 'fred', users(:default).name
- assert_equal false, users(:default).admin
+ def test_should_retrieve_stubs
+ assert_equal 'fred', model_stubbing_users(:default).name
+ assert_equal false, model_stubbing_users(:default).admin
- assert_equal 'fred', users(:admin).name
- assert users(:admin).admin
- end
+ assert_equal 'fred', model_stubbing_users(:admin).name
+ assert model_stubbing_users(:admin).admin
+ end
- def test_should_retrieve_new_records_based_on_stubs
- record = new_user(:default)
- assert_equal 'fred', record.name
- assert_equal false, record.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
+ end
- def test_should_retrieve_instantiated_stubs
- assert_equal users(:default).id, users(:default).id
- end
+ def test_should_retrieve_instantiated_stubs
+ assert_equal model_stubbing_users(:default).id, model_stubbing_users(:default).id
+ end
- def test_should_retrieve_instantiated_new_records_based_on_stubs
- record = new_user(:default)
- assert_nil record.id
- assert record.new_record?
- end
+ def test_should_retrieve_instantiated_new_records_based_on_stubs
+ record = new_model_stubbing_user(:default)
+ assert_nil record.id
+ assert record.new_record?
+ end
- def test_should_generate_custom_stubs
- custom = users(:default, :admin => true)
- assert_not_equal users(:default).id, custom.id
- assert_equal custom.id, users(:default, :admin => true).id
- end
+ def test_should_generate_custom_stubs
+ custom = model_stubbing_users(:default, :admin => true)
+ assert_not_equal model_stubbing_users(:default).id, custom.id
+ assert_equal custom.id, model_stubbing_users(:default, :admin => true).id
+ end
- def test_should_associate_stubs
- assert_equal users(:admin), posts(:default).user
- end
+ def test_should_associate_stubs
+ assert_equal model_stubbing_users(:admin), model_stubbing_posts(:default).user
+ end
- def test_should_stub_current_time
- assert_equal Time.utc(2007, 6, 1), current_time
- assert_equal Time.utc(2007, 6, 6), posts(:default).published_at
+ 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
+ end
end
-end
+end
@@ -2,56 +2,58 @@
require 'test/spec'
require 'mocha'
-describe "Sample" do
- define_models do
- time 2007, 6, 1
-
- model User do
- stub :name => 'fred', :admin => false
- stub :admin, :admin => true
+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
- model Post do
- stub :title => 'first', :user => all_stubs(:admin_model_stubbing_user), :published_at => current_time + 5.days
- end
- end
-
- def test_should_retrieve_stubs
- assert_equal 'fred', users(:default).name
- assert_equal false, users(:default).admin
+ def test_should_retrieve_stubs
+ assert_equal 'fred', model_stubbing_users(:default).name
+ assert_equal false, model_stubbing_users(:default).admin
- assert_equal 'fred', users(:admin).name
- assert users(:admin).admin
- end
+ assert_equal 'fred', model_stubbing_users(:admin).name
+ assert model_stubbing_users(:admin).admin
+ end
- def test_should_retrieve_new_records_based_on_stubs
- record = new_user(:default)
- assert_equal 'fred', record.name
- assert_equal false, record.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
+ end
- def test_should_retrieve_instantiated_stubs
- assert_equal users(:default).id, users(:default).id
- end
+ def test_should_retrieve_instantiated_stubs
+ assert_equal model_stubbing_users(:default).id, model_stubbing_users(:default).id
+ end
- def test_should_retrieve_instantiated_new_records_based_on_stubs
- record = new_user(:default)
- assert_nil record.id
- assert record.new_record?
- end
+ def test_should_retrieve_instantiated_new_records_based_on_stubs
+ record = new_model_stubbing_user(:default)
+ assert_nil record.id
+ assert record.new_record?
+ end
- def test_should_generate_custom_stubs
- custom = users(:default, :admin => true)
- assert_not_equal users(:default).id, custom.id
- assert_equal custom.id, users(:default, :admin => true).id
- end
+ def test_should_generate_custom_stubs
+ custom = model_stubbing_users(:default, :admin => true)
+ assert_not_equal model_stubbing_users(:default).id, custom.id
+ assert_equal custom.id, model_stubbing_users(:default, :admin => true).id
+ end
- def test_should_associate_stubs
- assert_equal users(:admin), posts(:default).user
- end
+ def test_should_associate_stubs
+ assert_equal model_stubbing_users(:admin), model_stubbing_posts(:default).user
+ end
- def test_should_stub_current_time
- assert_equal Time.utc(2007, 6, 1), current_time
- assert_equal Time.utc(2007, 6, 6), posts(:default).published_at
+ 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
+ end
end
end
View
@@ -2,6 +2,7 @@
module ModelStubbing
describe Stub do
+
before :all do
@definition = ModelStubbing.definitions[:default]
@users = @definition.models[:model_stubbing_users]

0 comments on commit 80a4382

Please sign in to comment.