From 2a3488897217a29435fa4eed0f01707c30853595 Mon Sep 17 00:00:00 2001 From: rick Date: Fri, 23 Nov 2007 19:54:02 +0000 Subject: [PATCH] dup Definition#current_time git-svn-id: http://ar-code.svn.engineyard.com/plugins/model_stubbing@72 d98f8484-0aa7-43af-80ea-302c351499d6 --- lib/model_stubbing/definition.rb | 9 +++++---- spec/definition_spec.rb | 4 ++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/model_stubbing/definition.rb b/lib/model_stubbing/definition.rb index f96cf2f..fbf5184 100644 --- a/lib/model_stubbing/definition.rb +++ b/lib/model_stubbing/definition.rb @@ -3,9 +3,9 @@ module ModelStubbing # can set the current time for your tests. You typically create one per test case or # rspec example. class Definition - attr_reader :current_time - attr_reader :models - attr_reader :stubs + attr_accessor :current_time + attr_reader :models + attr_reader :stubs # Sets the time that Time.now is mocked to (in UTC) def time(*args) @@ -29,6 +29,7 @@ def initialize(&block) def dup copy = self.class.new + copy.current_time = @current_time models.each do |name, model| copy.models[name] = model.dup(copy) end @@ -40,7 +41,7 @@ def dup def ==(defn) (defn.object_id == object_id) || - (defn.is_a?(Definition))# && defn.models == @models && defn.stubs == @stubs) + (defn.is_a?(Definition) && defn.models == @models && defn.stubs == @stubs) end # Sets up the given class for this definition. Adds a few helper methods: diff --git a/spec/definition_spec.rb b/spec/definition_spec.rb index b1139f2..4ee9caa 100644 --- a/spec/definition_spec.rb +++ b/spec/definition_spec.rb @@ -60,6 +60,10 @@ @copy = @defn.dup end + it "dups @current_time" do + @defn.current_time.should == @copy.current_time + end + it "dups each model" do @defn.models.each do |name, model| duped_model = @copy.models[name]