Created
July 18, 2013 17:55
-
-
Save lcowell/6031444 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'rspec' | |
require 'date' | |
require 'time' | |
module MyHelper | |
extend self | |
def convert_to_datetime(input) | |
if input.is_a?(String) | |
DateTime.parse(input) | |
else | |
input | |
end | |
end | |
end | |
describe MyHelper do | |
describe 'convert_to_datetime functionality' do | |
let(:input) { '2012-03-04' } | |
let(:date_version) { DateTime.parse(input) } | |
it 'should successfully convert a well formatted date string' do | |
output = MyHelper.convert_to_datetime input | |
output.should be_an_instance_of(DateTime) | |
output.should == date_version | |
end | |
it 'should return the original date if a DateTime object was passed in' do | |
output = MyHelper.convert_to_datetime date_version | |
output.should be_an_instance_of(DateTime) | |
output.should == date_version | |
end | |
end | |
end | |
# > rspec -v | |
#2.14.2 | |
# | |
#> rspec delete_spec.rb | |
#.. | |
# | |
#Finished in 0.00097 seconds | |
#2 examples, 0 failures |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment