Open shah-smit opened 3 years ago
Mocking Time:
hello.rb
def print
time = Time.now
return time.strftime("%d%m%Y%H%M%S")
end
spec.rb
require 'minitest/autorun'
require 'minitest/mock'
it "should set the date to the current date" do
old_time = Time.new(2019,11,11, 23, 30, 0)
Time.stub(:now, old_time) do
string_formatted_time = print
string_formatted_time.must_equal "11112019233000"
end
end
https://dev.to/exampro/testunit-writing-test-code-in-ruby-part-1-of-3-44m2