Skip to content

Instantly share code, notes, and snippets.

@jimytc
Created June 6, 2020 02:36
Show Gist options
  • Save jimytc/034440dfb3098e3edef0912bf9820954 to your computer and use it in GitHub Desktop.
Save jimytc/034440dfb3098e3edef0912bf9820954 to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
source 'https://rubygems.org'
gem 'activesupport'
gem 'minitest'
gem 'minitest-reporters', '>= 0.5.0'
gem 'rr'
gem 'rubocop'
# frozen_string_literal: true
class Holiday
def sayHello
if christmas?(Date.today)
"Merry X'mas"
else
"Today is not X'mas"
end
end
private
def christmas?(date)
date.day == 25 && date.month == 12
end
end
# frozen_string_literal: true
require 'minitest/autorun'
require 'date'
require_relative 'holiday'
class HolidayTest < Minitest::Test
def test_has_class_and_method
assert Holiday.new.sayHello
end
def test_is_christmas
Date.stub(Date.today, Date.new(2020, 12, 25)) do
assert_equal "Merry X'mas", Holiday.new.sayHello
end
end
def test_is_not_christmas
Date.stub(Date.today, Date.new(2020, 3, 3)) do
assert_equal "Today is not X'mas", Holiday.new.sayHello
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment