# 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 method access' do context 'Using default compact mode' do before(:each) do @hd = HumanDuration.new end it 'says negative for seconds < 0 (Negative value test)' do expect(@hd.humanize(-1)).to eql('negative') end it 'says now for 0 seconds (Zero second test)' do expect(@hd.humanize(0)).to eql('now') end it 'says \'1 second\' for 1 second (Singular test)' do expect(@hd.humanize(1)).to eql('1 second') end it 'says \'10 seconds\' for 10 second (Plural test)' do expect(@hd.humanize(10)).to eql('10 seconds') end it 'says \'1 minute\' for 60 seconds' do expect(@hd.humanize(60)).to eql('1 minute') end it 'says \'1 hour\' for 3600 seconds' do expect(@hd.humanize(360_0)).to eql('1 hour') end it 'says \'1 year\' for 31536000 seconds' do expect(@hd.humanize(315_360_00)).to eql('1 year') end it 'says \'1 year, 2 hours and 13 seconds\' for 31543213 seconds' do expect(@hd.humanize(315_432_13)).to eql('1 year, 2 hours and 13 seconds') end end context 'Using short mode' do before(:each) do @hd = HumanDuration.new('type' => 'short') end it 'says negative for seconds < 0 (Negative value test)' do expect(@hd.humanize(-1)).to eql('negative') end it 'says now for 0 seconds (Zero second test)' do expect(@hd.humanize(0)).to eql('now') end it 'says \'1 s\' for 1 second (Singular test)' do expect(@hd.humanize(1)).to eql('1 s') end it 'says \'10 s\' for 10 second (Plural test)' do expect(@hd.humanize(10)).to eql('10 s') end it 'says \'1 m\' for 60 seconds' do expect(@hd.humanize(60)).to eql('1 m') end it 'says \'1 h\' for 3600 seconds' do expect(@hd.humanize(360_0)).to eql('1 h') end it 'says \'1 y\' for 31536000 seconds' do expect(@hd.humanize(315_360_00)).to eql('1 y') end it 'says \'1 y, 2 h & 13 s\' for 31543213 seconds' do expect(@hd.humanize(315_432_13)).to eql('1 y, 2 h & 13 s') end end context 'Using full mode' do before(:each) do @hd = HumanDuration.new('type' => 'full') end it 'says negative for seconds < 0 (Negative value test)' do expect(@hd.humanize(-1)).to eql('negative') end it 'says now for 0 seconds (Zero second test)' do expect(@hd.humanize(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.humanize(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.humanize(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.humanize(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.humanize(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.humanize(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.humanize(315_432_13)).to eql('1 year, 0 days, 2 hours, 0 minutes and 13 seconds') end end end context 'Static method access' do context 'Using default compact mode' do before(:each) do @hd = HumanDurationStatic end it 'says negative for seconds < 0 (Negative value test)' do expect(@hd.humanize(-1)).to eql('negative') end it 'says now for 0 seconds (Zero second test)' do expect(@hd.humanize(0)).to eql('now') end it 'says \'1 second\' for 1 second (Singular test)' do expect(@hd.humanize(1)).to eql('1 second') end it 'says \'10 seconds\' for 10 second (Plural test)' do expect(@hd.humanize(10)).to eql('10 seconds') end it 'says \'1 minute\' for 60 seconds' do expect(@hd.humanize(60)).to eql('1 minute') end it 'says \'1 hour\' for 3600 seconds' do expect(@hd.humanize(360_0)).to eql('1 hour') end it 'says \'1 year\' for 31536000 seconds' do expect(@hd.humanize(315_360_00)).to eql('1 year') end it 'says \'1 year, 2 hours and 13 seconds\' for 31543213 seconds' do expect(@hd.humanize(315_432_13)).to eql('1 year, 2 hours and 13 seconds') end end context 'Using short mode' do before(:each) do @hd = HumanDurationStatic end it 'says negative for seconds < 0 (Negative value test)' do expect(@hd.humanize(-1, 'type' => 'short')).to eql('negative') end it 'says now for 0 seconds (Zero second test)' do expect(@hd.humanize(0, 'type' => 'short')).to eql('now') end it 'says \'1 s\' for 1 second (Singular test)' do expect(@hd.humanize(1, 'type' => 'short')).to eql('1 s') end it 'says \'10 s\' for 10 second (Plural test)' do expect(@hd.humanize(10, 'type' => 'short')).to eql('10 s') end it 'says \'1 m\' for 60 seconds' do expect(@hd.humanize(60, 'type' => 'short')).to eql('1 m') end it 'says \'1 h\' for 3600 seconds' do expect(@hd.humanize(360_0, 'type' => 'short')).to eql('1 h') end it 'says \'1 y\' for 31536000 seconds' do expect(@hd.humanize(315_360_00, 'type' => 'short')).to eql('1 y') end it 'says \'1 y, 2 h & 13 s\' for 31543213 seconds' do expect(@hd.humanize(315_432_13, 'type' => 'short')).to eql('1 y, 2 h & 13 s') end end context 'Using full mode' do before(:each) do @hd = HumanDurationStatic end it 'says negative for seconds < 0 (Negative value test)' do expect(@hd.humanize(-1, 'type' => 'full')).to eql('negative') end it 'says now for 0 seconds (Zero second test)' do expect(@hd.humanize(0, 'type' => '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(@hd.humanize(1, 'type' => '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(@hd.humanize(10, 'type' => '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(@hd.humanize(60, 'type' => '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(@hd.humanize(360_0, 'type' => '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(@hd.humanize(315_360_00, 'type' => '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(@hd.humanize(315_432_13, 'type' => 'full')).to eql('1 year, 0 days, 2 hours, 0 minutes and 13 seconds') end end end context 'Direct method access' do context 'Using default compact mode' do it 'says negative for seconds < 0 (Negative value test)' do expect(humanize(-1)).to eql('negative') end it 'says now for 0 seconds (Zero second test)' do expect(humanize(0)).to eql('now') end it 'says \'1 second\' for 1 second (Singular test)' do expect(humanize(1)).to eql('1 second') end it 'says \'10 seconds\' for 10 second (Plural test)' do expect(humanize(10)).to eql('10 seconds') end it 'says \'1 minute\' for 60 seconds' do expect(humanize(60)).to eql('1 minute') end it 'says \'1 hour\' for 3600 seconds' do expect(humanize(360_0)).to eql('1 hour') end it 'says \'1 year\' for 31536000 seconds' do expect(humanize(315_360_00)).to eql('1 year') end it 'says \'1 year, 2 hours and 13 seconds\' for 31543213 seconds' do expect(humanize(315_432_13)).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(humanize(-1, 'type' => 'short')).to eql('negative') end it 'says now for 0 seconds (Zero second test)' do expect(humanize(0, 'type' => 'short')).to eql('now') end it 'says \'1 s\' for 1 second (Singular test)' do expect(humanize(1, 'type' => 'short')).to eql('1 s') end it 'says \'10 s\' for 10 second (Plural test)' do expect(humanize(10, 'type' => 'short')).to eql('10 s') end it 'says \'1 m\' for 60 seconds' do expect(humanize(60, 'type' => 'short')).to eql('1 m') end it 'says \'1 h\' for 3600 seconds' do expect(humanize(360_0, 'type' => 'short')).to eql('1 h') end it 'says \'1 y\' for 31536000 seconds' do expect(humanize(315_360_00, 'type' => 'short')).to eql('1 y') end it 'says \'1 y, 2 h & 13 s\' for 31543213 seconds' do expect(humanize(315_432_13, 'type' => '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(humanize(-1, 'type' => 'full')).to eql('negative') end it 'says now for 0 seconds (Zero second test)' do expect(humanize(0, 'type' => '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(humanize(1, 'type' => '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(humanize(10, 'type' => '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(humanize(60, 'type' => '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(humanize(360_0, 'type' => '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(humanize(315_360_00, 'type' => '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(humanize(315_432_13, 'type' => 'full')).to eql('1 year, 0 days, 2 hours, 0 minutes and 13 seconds') end end end end # rubocop:enable Metrics/BlockLength