# rubocop:disable Metrics/BlockLength require 'human_duration' RSpec.describe HumanDuration do it 'has a version number' do expect(HumanDuration::VERSION).not_to be nil end context 'Class Accessor Method' do context 'Using default compact mode' do before(:each) do @hd = HumanDuration::Duration end it 'says "negative" for seconds < 0 (Negative value test)' do expect(@hd.human_duration(-1)).to eql('negative') end it 'says "now" for 0 seconds (Zero second test)' do expect(@hd.human_duration(0)).to eql('now') end it 'says "1 second" for 1 second (Singular test)' do expect(@hd.human_duration(1)).to eql('1 second') end it 'says "10 seconds" for 10 second (Plural test)' do expect(@hd.human_duration(10)).to eql('10 seconds') end it 'says "1 minute" for 60 seconds' do expect(@hd.human_duration(60)).to eql('1 minute') end it 'says "1 hour" for 3600 seconds' do expect(@hd.human_duration(360_0)).to eql('1 hour') end it 'says "1 year" for 31536000 seconds' do expect(@hd.human_duration(315_360_00)).to eql('1 year') end it 'says "1 year, 2 hours and 13 seconds" for 31543213 seconds' do expect(@hd.human_duration(315_432_13)).to eql('1 year, 2 hours and 13 seconds') end end context 'Using short mode' do before(:each) do @hd = HumanDuration::Duration @hd.display_type('short') end it 'says "negative" for seconds < 0 (Negative value test)' do expect(@hd.human_duration(-1)).to eql('negative') end it 'says "now" for 0 seconds (Zero second test)' do expect(@hd.human_duration(0)).to eql('now') end it 'says "1 s" for 1 second (Singular test)' do expect(@hd.human_duration(1)).to eql('1 s') end it 'says "10 s" for 10 second (Plural test)' do expect(@hd.human_duration(10)).to eql('10 s') end it 'says "1 m" for 60 seconds' do expect(@hd.human_duration(60)).to eql('1 m') end it 'says "1 h" for 3600 seconds' do expect(@hd.human_duration(360_0)).to eql('1 h') end it 'says "1 y" for 31536000 seconds' do expect(@hd.human_duration(315_360_00)).to eql('1 y') end it 'says "1 y, 2 h & 13 s" for 31543213 seconds' do expect(@hd.human_duration(315_432_13)).to eql('1 y, 2 h & 13 s') end end context 'Using full mode' do before(:each) do @hd = HumanDuration::Duration @hd.display_type('full') end it 'says "negative" for seconds < 0 (Negative value test)' do expect(@hd.human_duration(-1)).to eql('negative') end it 'says "now" for 0 seconds (Zero second test)' do expect(@hd.human_duration(0)).to eql('now') end it 'says "0 years, 0 days, 0 hours, 0 minutes and 1 second" for 1 second (Singular test)' do expect(@hd.human_duration(1)).to eql('0 years, 0 days, 0 hours, 0 minutes and 1 second') end it 'says "0 years, 0 days, 0 hours, 0 minutes and 10 seconds" for 10 second (Plural test)' do expect(@hd.human_duration(10)).to eql('0 years, 0 days, 0 hours, 0 minutes and 10 seconds') end it 'says "0 years, 0 days, 0 hours, 1 minute and 0 seconds" for 60 seconds' do expect(@hd.human_duration(60)).to eql('0 years, 0 days, 0 hours, 1 minute and 0 seconds') end it 'says "0 years, 0 days, 1 hour, 0 minutes and 0 seconds" for 3600 seconds' do expect(@hd.human_duration(360_0)).to eql('0 years, 0 days, 1 hour, 0 minutes and 0 seconds') end it 'says "1 year, 0 days, 0 hours, 0 minutes and 0 seconds" for 31536000 seconds' do expect(@hd.human_duration(315_360_00)).to eql('1 year, 0 days, 0 hours, 0 minutes and 0 seconds') end it 'says "1 year, 0 days, 2 hours, 0 minutes and 13 seconds" for 31543213 seconds' do expect(@hd.human_duration(315_432_13)).to eql('1 year, 0 days, 2 hours, 0 minutes and 13 seconds') end end end context 'String Accessor Method' do context 'Using default compact mode' do it 'says "negative" for seconds < 0 (Negative value test)' do expect(-1.human_duration).to eql('negative') end it 'says "now" for 0 seconds (Zero second test)' do expect(0.human_duration).to eql('now') end it 'says "1 second" for 1 second (Singular test)' do expect(1.human_duration).to eql('1 second') end it 'says "10 seconds" for 10 second (Plural test)' do expect(10.human_duration).to eql('10 seconds') end it 'says "1 minute" for 60 seconds' do expect(60.human_duration).to eql('1 minute') end it 'says "1 hour" for 3600 seconds' do expect(360_0.human_duration).to eql('1 hour') end it 'says "1 year" for 31536000 seconds' do expect(315_360_00.human_duration).to eql('1 year') end it 'says "1 year, 2 hours and 13 seconds" for 31543213 seconds' do expect(315_432_13.human_duration).to eql('1 year, 2 hours and 13 seconds') end end context 'Using short mode' do it 'says "negative" for seconds < 0 (Negative value test)' do expect(-1.human_duration('short')).to eql('negative') end it 'says "now" for 0 seconds (Zero second test)' do expect(0.human_duration('short')).to eql('now') end it 'says "1 s" for 1 second (Singular test)' do expect(1.human_duration('short')).to eql('1 s') end it 'says "10 s" for 10 second (Plural test)' do expect(10.human_duration('short')).to eql('10 s') end it 'says "1 m" for 60 seconds' do expect(60.human_duration('short')).to eql('1 m') end it 'says "1 h" for 3600 seconds' do expect(360_0.human_duration('short')).to eql('1 h') end it 'says "1 y" for 31536000 seconds' do expect(315_360_00.human_duration('short')).to eql('1 y') end it 'says "1 y, 2 h & 13 s" for 31543213 seconds' do expect(315_432_13.human_duration('short')).to eql('1 y, 2 h & 13 s') end end context 'Using full mode' do it 'says "negative" for seconds < 0 (Negative value test)' do expect(-1.human_duration('full')).to eql('negative') end it 'says "now" for 0 seconds (Zero second test)' do expect(0.human_duration('full')).to eql('now') end it 'says "0 years, 0 days, 0 hours, 0 minutes and 1 second" for 1 second (Singular test)' do expect(1.human_duration('full')).to eql('0 years, 0 days, 0 hours, 0 minutes and 1 second') end it 'says "0 years, 0 days, 0 hours, 0 minutes and 10 seconds" for 10 second (Plural test)' do expect(10.human_duration('full')).to eql('0 years, 0 days, 0 hours, 0 minutes and 10 seconds') end it 'says "0 years, 0 days, 0 hours, 1 minute and 0 seconds" for 60 seconds' do expect(60.human_duration('full')).to eql('0 years, 0 days, 0 hours, 1 minute and 0 seconds') end it 'says "0 years, 0 days, 1 hour, 0 minutes and 0 seconds" for 3600 seconds' do expect(360_0.human_duration('full')).to eql('0 years, 0 days, 1 hour, 0 minutes and 0 seconds') end it 'says "1 year, 0 days, 0 hours, 0 minutes and 0 seconds" for 31536000 seconds' do expect(315_360_00.human_duration('full')).to eql('1 year, 0 days, 0 hours, 0 minutes and 0 seconds') end it 'says "1 year, 0 days, 2 hours, 0 minutes and 13 seconds" for 31543213 seconds' do expect(315_432_13.human_duration('full')).to eql('1 year, 0 days, 2 hours, 0 minutes and 13 seconds') end end end context 'Test Error Handling' do it 'Test invalid display type raises an exception direct call' do expect { HumanDuration::Duration.display_type('invalid') }.to raise_error(ArgumentError, 'Invalid type - Valid options are:- compact, short and full') end it 'Test invalid display type raises an exception indirect call' do expect { 0.human_duration('invalid') }.to raise_error(ArgumentError, 'Invalid type - Valid options are:- compact, short and full') end end end # rubocop:enable Metrics/BlockLength