Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix warning about usage of TrueClass#=~ on Ruby 2.7 #375

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/hutch/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,12 @@ def self.is_bool(attr)
end

def self.to_bool(value)
!(value.nil? || value == '' || value =~ /^(false|f|no|n|0)$/i || value == false)
case value
when nil, false, '', /^(false|f|no|n|0)$/i
false
else
true
end
end

def self.is_num(attr)
Expand Down
48 changes: 43 additions & 5 deletions spec/hutch/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,52 @@
end

context 'boolean attributes' do
before { Hutch::Config.set(:autoload_rails, new_value) }
subject(:value) { Hutch::Config.user_config[:autoload_rails] }
context 'from non-empty string' do
before { Hutch::Config.set(:autoload_rails, new_value) }
subject(:value) { Hutch::Config.user_config[:autoload_rails] }

let(:new_value) { "t" }
let(:new_value) { "t" }


specify 'casts values to booleans' do
expect(value).to eq true
specify 'casts values to booleans' do
expect(value).to eq true
end
end

context 'from empty string' do
before { Hutch::Config.set(:autoload_rails, new_value) }
subject(:value) { Hutch::Config.user_config[:autoload_rails] }

let(:new_value) { "" }


specify 'casts values to booleans' do
expect(value).to eq false
end
end

context 'from boolean' do
before { Hutch::Config.set(:autoload_rails, new_value) }
subject(:value) { Hutch::Config.user_config[:autoload_rails] }

let(:new_value) { true }


specify 'casts values to booleans' do
expect(value).to eq true
end
end

context 'from nil' do
before { Hutch::Config.set(:autoload_rails, new_value) }
subject(:value) { Hutch::Config.user_config[:autoload_rails] }

let(:new_value) { nil }


specify 'casts values to booleans' do
expect(value).to eq false
end
end
end

Expand Down