hanami-utils/spec/hanami/utils/blank_spec.rb

43 lines
1.5 KiB
Ruby
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

require 'hanami/utils/kernel'
require 'hanami/utils/string'
require 'hanami/utils/hash'
require 'hanami/utils/blank'
RSpec.describe Hanami::Utils::Blank do
describe '.blank?' do
[nil, false, '', ' ', " \n\t \r ", ' ', "\u00a0", [], {}, Set.new,
Hanami::Utils::Kernel.Boolean(0), Hanami::Utils::String.new(''),
Hanami::Utils::Hash.new({})].each do |v|
it 'returns true' do
expect(Hanami::Utils::Blank.blank?(v)).to eq(true)
end
end
[Object.new, true, 0, 1, 'a', :book, DateTime.now, Time.now, Date.new, [nil], { nil => 0 }, Set.new([1]),
Hanami::Utils::Kernel.Symbol(:hello), Hanami::Utils::String.new('foo'),
Hanami::Utils::Hash.new(foo: :bar)].each do |v|
it 'returns false' do
expect(Hanami::Utils::Blank.blank?(v)).to eq(false)
end
end
end
describe '.filled?' do
[nil, false, '', ' ', " \n\t \r ", ' ', "\u00a0", [], {}, Set.new,
Hanami::Utils::Kernel.Boolean(0), Hanami::Utils::String.new(''),
Hanami::Utils::Hash.new({})].each do |v|
it 'returns false' do
expect(Hanami::Utils::Blank.filled?(v)).to eq(false)
end
end
[Object.new, true, 0, 1, 'a', :book, DateTime.now, Time.now, Date.new, [nil], { nil => 0 }, Set.new([1]),
Hanami::Utils::Kernel.Symbol(:hello), Hanami::Utils::String.new('foo'),
Hanami::Utils::Hash.new(foo: :bar)].each do |v|
it 'returns true' do
expect(Hanami::Utils::Blank.filled?(v)).to eq(true)
end
end
end
end