Created
May 15, 2019 11:24
-
-
Save tatsuosakurai/455be42a32acd2bce30dbc82604ffbfd to your computer and use it in GitHub Desktop.
ruby( ActiveSupportあり )で、誕生日の前後一週間かどうかを判定するメソッドを実装してください〜
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
# 準備 | |
# `gem i activesupport` | |
# `gem i rspec` | |
# 実行 | |
# `rspec birthday_around_a_week_challenge.rb` | |
# 実装 | |
require 'active_support' | |
require 'active_support/core_ext' | |
# require 'byebug' | |
class BirthDay | |
def self.around_a_week?(birthday) | |
# TODO: 実装! | |
end | |
end | |
# spec_helper | |
require 'rspec' | |
require 'active_support/testing/time_helpers' | |
RSpec.configure do |config| | |
config.include ActiveSupport::Testing::TimeHelpers | |
end | |
# spec | |
RSpec.describe BirthDay do | |
describe 'around_a_week?' do | |
subject(:around_a_week?) { travel_to(today.to_time) { BirthDay.around_a_week?(birthday) } } | |
context '年をまたがない場合' do | |
let!(:birthday){ '1985-05-26 0:00'.to_time } | |
context '7日前' do | |
let!(:today) { '2019-5-19 00:00' } | |
it { expect(around_a_week?).to eq true } | |
end | |
context '8日前' do | |
let!(:today) { '2019-5-18 23:59' } | |
it { expect(around_a_week?).to eq false } | |
end | |
context '7日後' do | |
let!(:today) { '2019-6-2 23:59' } | |
it { expect(around_a_week?).to eq true } | |
end | |
context '8日後' do | |
let!(:today) { '2019-6-3 00:00' } | |
it { expect(around_a_week?).to eq false } | |
end | |
end | |
context '年をまたぐ場合' do | |
context '年末の場合' do | |
let(:birthday){ '1985-12-27 0:00'.to_time } | |
context '7日前' do | |
let!(:today) { '2019-12-20 00:00' } | |
it { expect(around_a_week?).to eq true } | |
end | |
context '8日前' do | |
let!(:today) { '2019-12-19 23:59' } | |
it { expect(around_a_week?).to eq false } | |
end | |
context '7日後' do | |
let!(:today) { '2020-1-3 23:59' } | |
it { expect(around_a_week?).to eq true } | |
end | |
context '8日後' do | |
let!(:today) { '2020-1-4 00:00' } | |
it { expect(around_a_week?).to eq false } | |
end | |
end | |
context '年始の場合' do | |
let(:birthday){ '1985-01-03 0:00'.to_time } | |
context '7日前' do | |
let!(:today) { '2019-12-27 00:00' } | |
it { expect(around_a_week?).to eq true } | |
end | |
context '8日前' do | |
let!(:today) { '2019-12-26 23:59' } | |
it { expect(around_a_week?).to eq false } | |
end | |
context '7日後' do | |
let!(:today) { '2020-1-10 23:59' } | |
it { expect(around_a_week?).to eq true } | |
end | |
context '8日後' do | |
let!(:today) { '2020-1-11 00:00' } | |
it { expect(around_a_week?).to eq false } | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment