2014-12-31 15:59:32 -05:00
|
|
|
require 'spec_helper'
|
2011-05-13 19:37:24 -04:00
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
RSpec.describe 'AwesomePrint::ActiveSupport', skip: ->{ !ExtVerifier.has_rails? }.call do
|
2014-12-31 15:59:32 -05:00
|
|
|
before do
|
|
|
|
@ap = AwesomePrint::Inspector.new
|
|
|
|
end
|
2011-05-13 19:37:24 -04:00
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
it 'should format ActiveSupport::TimeWithZone as regular Time' do
|
2014-12-31 15:59:32 -05:00
|
|
|
Time.zone = 'Eastern Time (US & Canada)'
|
|
|
|
time = Time.utc(2007, 2, 10, 20, 30, 45).in_time_zone
|
|
|
|
expect(@ap.send(:awesome, time)).to eq("\e[0;32mSat, 10 Feb 2007 15:30:45 EST -05:00\e[0m")
|
|
|
|
end
|
2011-12-05 16:56:46 -05:00
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
it 'should format HashWithIndifferentAccess as regular Hash' do
|
|
|
|
hash = HashWithIndifferentAccess.new({ :hello => 'world' })
|
2014-12-31 15:59:32 -05:00
|
|
|
expect(@ap.send(:awesome, hash)).to eq("{\n \"hello\"\e[0;37m => \e[0m\e[0;33m\"world\"\e[0m\n}")
|
2011-05-13 19:37:24 -04:00
|
|
|
end
|
|
|
|
|
2014-12-31 15:59:32 -05:00
|
|
|
# ActiveSupport sticks in instance variables to the date object. Make sure
|
|
|
|
# we ignore that and format Date instance as regular date.
|
2016-11-08 00:07:03 -05:00
|
|
|
it 'should formate Date object as date' do
|
2014-12-31 15:59:32 -05:00
|
|
|
date = Date.new(2003, 5, 26)
|
2016-11-08 00:07:03 -05:00
|
|
|
expect(date.ai(:plain => true)).to eq('Mon, 26 May 2003')
|
2014-12-31 15:59:32 -05:00
|
|
|
expect(date.ai).to eq("\e[0;32mMon, 26 May 2003\e[0m")
|
|
|
|
end
|
2011-05-13 19:37:24 -04:00
|
|
|
end
|