public
Fork of halorgium/mephisto
Description: A mirror of the mephisto code-base
Homepage: http://mephistoblog.com/
Clone URL: git://github.com/technoweenie/mephisto.git
Click here to lend your support to: mephisto and make a donation at www.pledgie.com !
update model_stubbing plugin

git-svn-id: http://svn.techno-weenie.net/projects/mephisto/trunk@3052 
567b1171-46fb-0310-a4c9-b4bef9110e78
technoweenie (author)
Fri Nov 23 18:43:37 -0800 2007
commit  81dd998b82020e38841198e896bb84b700033cd7
tree    99ea31c1fcd1b92094107b2366586429a952454d
parent  fa95f30d1e74cc5af558fe9767e6fe133730e343
...
65
66
67
68
69
70
 
71
72
73
74
...
65
66
67
 
 
 
68
69
70
71
72
0
@@ -65,9 +65,7 @@ a different approach. Oh, and apparently this is an implementation of the Objec
0
 TODO
0
 ====
0
 
0
-* Finish implementing test/unit support. Main issue is it doesn't
0
- insert the model stubs into the database since there's no equivalent
0
- to before(:all) in rspec
0
+* Support other mocking frameworks besides rspec and mocha?
0
 
0
 * Support Sequel, DataMapper, etc? I use AR, but I'm willing to abstract
0
   some of that out in case someone wants to support another ORM.
0
\ No newline at end of file
...
60
61
62
63
64
65
66
67
68
69
70
71
 
72
73
74
...
76
77
78
79
80
81
82
83
84
85
86
87
 
88
89
90
...
99
100
101
102
 
103
104
105
106
...
60
61
62
 
 
 
 
 
 
 
63
 
64
65
66
67
...
69
70
71
 
 
 
 
 
 
 
72
 
73
74
75
76
...
85
86
87
 
88
89
90
91
92
0
@@ -60,15 +60,8 @@ protected
0
   # Included into the current rspec example when #define_models is called.
0
   module RspecExtension
0
     def self.included(base)
0
- base.prepend_before :all do
0
- if self.class.definition.insert?
0
- ActiveRecord::Base.transaction do
0
- self.class.definition.models.values.each(&:insert)
0
- end
0
- end
0
- end
0
       base.prepend_before :each do
0
- ModelStubbing.stub_current_time_with(current_time) if current_time
0
+ setup_definition_for_test_run
0
       end
0
     end
0
   end
0
@@ -76,15 +69,8 @@ protected
0
   # Included into the current test/spec example when #define_models is called.
0
   module TestSpecExtension
0
     def self.included(base)
0
- base.before :all do
0
- if self.class.definition.insert?
0
- ActiveRecord::Base.transaction do
0
- self.class.definition.models.values.each(&:insert)
0
- end
0
- end
0
- end
0
       base.before :each do
0
- ModelStubbing.stub_current_time_with(current_time) if current_time
0
+ setup_definition_for_test_run
0
       end
0
     end
0
   end
0
@@ -99,7 +85,7 @@ protected
0
     end
0
     
0
     def setup_with_model_stubbing
0
- ModelStubbing.stub_current_time_with(current_time) if current_time
0
+ setup_definition_for_test_run
0
     end
0
   end
0
 end
0
\ No newline at end of file
...
78
79
80
 
 
 
 
 
 
 
 
 
 
81
82
 
83
84
85
...
78
79
80
81
82
83
84
85
86
87
88
89
90
91
 
92
93
94
95
0
@@ -78,8 +78,18 @@ module ModelStubbing
0
           def current_time
0
             self.class.definition.current_time
0
           end
0
+
0
+ def setup_definition_for_test_run
0
+ if !self.class.definition_inserted && self.class.definition.insert?
0
+ ActiveRecord::Base.transaction do
0
+ self.class.definition.models.values.each(&:insert)
0
+ end
0
+ self.class.definition_inserted = true
0
+ end
0
+ ModelStubbing.stub_current_time_with(current_time) if current_time
0
+ end
0
         end
0
- (class << klass ; self ; end).send :attr_accessor, :definition
0
+ (class << klass ; self ; end).send :attr_accessor, :definition, :definition_inserted
0
         klass.definition = self
0
       end
0
       klass.class_eval models.values.collect { |model| model.stub_method_definition }.join("\n")
...
1
2
3
4
 
 
 
 
 
 
 
 
 
 
 
5
...
1
2
 
3
4
5
6
7
8
9
10
11
12
13
14
15
0
@@ -1,3 +1,13 @@
0
 require 'model_stubbing'
0
 require 'spec' unless Object.const_defined?(:Spec)
0
-(Spec.const_defined?(:ExampleGroup) ? Spec::ExampleGroup : Spec::Example).extend ModelStubbing
0
\ No newline at end of file
0
+base_spec_class = \
0
+ if defined?(Test::Unit::TestCase::ExampleGroup)
0
+ Test::Unit::TestCase::ExampleGroup
0
+ elsif defined?(Spec::ExampleGroup)
0
+ Spec::ExampleGroup
0
+ elsif defined?(Spec::Example)
0
+ Spec::Example
0
+ else
0
+ raise "rspec doesn't seem to be loaded."
0
+ end
0
+base_spec_class.extend ModelStubbing
0
\ No newline at end of file

Comments

    No one has commented yet.