shah-smit / observability-spring-demo

https://youtu.be/gJ9f32PyBnM
0 stars 0 forks source link

Resources: Unit testing in Ruby #8

Open shah-smit opened 3 years ago

shah-smit commented 3 years ago

https://dev.to/exampro/testunit-writing-test-code-in-ruby-part-1-of-3-44m2

shah-smit commented 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