diff --git a/spec/formats_spec.rb b/spec/formats_spec.rb index 2badbf8..e176ad6 100644 --- a/spec/formats_spec.rb +++ b/spec/formats_spec.rb @@ -48,11 +48,11 @@ describe ValidatesTimeliness::Formats do end describe "format proc generator" do - it "should generate proc which outputs date array" do + it "should generate proc which outputs date array with values in correct order" do generate_proc('yyyy-mm-dd').call('2000', '1', '2').should == [2000,1,2,0,0,0,0] end - it "should generate proc which outputs date array from format in non time array order" do + it "should generate proc which outputs date array from format with different order" do generate_proc('dd/mm/yyyy').call('2', '1', '2000').should == [2000,1,2,0,0,0,0] end diff --git a/spec/time_travel b/spec/time_travel deleted file mode 160000 index 7d4e697..0000000 --- a/spec/time_travel +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 7d4e697b1cee90bb1f34ac302881ce0641e654ec diff --git a/spec/time_travel/MIT-LICENSE b/spec/time_travel/MIT-LICENSE new file mode 100644 index 0000000..ac5cb2e --- /dev/null +++ b/spec/time_travel/MIT-LICENSE @@ -0,0 +1,20 @@ +Copyright (c) 2008 Peter Yandell + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/spec/time_travel/time_extensions.rb b/spec/time_travel/time_extensions.rb new file mode 100644 index 0000000..e3bdb4e --- /dev/null +++ b/spec/time_travel/time_extensions.rb @@ -0,0 +1,33 @@ +require 'time' + +module TimeTravel + module TimeExtensions + + def self.included(base) + base.extend(ClassMethods) + base.class_eval do + class << self + alias_method :immutable_now, :now + alias_method :now, :mutable_now + end + end + base.now = nil + end + + module ClassMethods + + @@now = nil + + def now=(time) + time = Time.parse(time) if time.instance_of?(String) + @@now = time + end + + def mutable_now #:nodoc: + @@now || immutable_now + end + + end + + end +end diff --git a/spec/time_travel/time_travel.rb b/spec/time_travel/time_travel.rb new file mode 100644 index 0000000..7d5d198 --- /dev/null +++ b/spec/time_travel/time_travel.rb @@ -0,0 +1,12 @@ +require 'time_travel/time_extensions' + +Time.send(:include, TimeTravel::TimeExtensions) + +def at_time(time) + Time.now = time + begin + yield + ensure + Time.now = nil + end +end