Skip to content

Commit

Permalink
expand convert_to_bool helper
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Jul 17, 2024
1 parent 420399c commit 9f0f2f2
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/datadog/ci/utils/parsing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ module CI
module Utils
module Parsing
def self.convert_to_bool(value)
value.to_s.downcase == "true"
normalized_value = value.to_s.downcase
normalized_value == "true" || normalized_value == "1"
end
end
end
Expand Down
75 changes: 75 additions & 0 deletions spec/datadog/ci/utils/parsing_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# frozen_string_literal: true

require_relative "../../../../lib/datadog/ci/utils/parsing"

RSpec.describe Datadog::CI::Utils::Parsing do
describe ".convert_to_bool" do
subject(:convert_to_bool) { described_class.convert_to_bool(value) }

context "when the value is a boolean" do
context "and the value is true" do
let(:value) { true }

it { is_expected.to be true }
end

context "and the value is false" do
let(:value) { false }

it { is_expected.to be false }
end
end

context "when the value is a string" do
context "and the value is 'true'" do
let(:value) { "true" }

it { is_expected.to be true }
end

context "and the value is 'false'" do
let(:value) { "false" }

it { is_expected.to be false }
end

context "and the value is '1'" do
let(:value) { "1" }

it { is_expected.to be true }
end

context "and the value is '0'" do
let(:value) { "0" }

it { is_expected.to be false }
end

context "and the value is 'TRUE'" do
let(:value) { "TRUE" }

it { is_expected.to be true }
end

context "and the value is 'FALSE'" do
let(:value) { "FALSE" }

it { is_expected.to be false }
end
end

context "when the value is an integer" do
context "and the value is 1" do
let(:value) { 1 }

it { is_expected.to be true }
end

context "and the value is 0" do
let(:value) { 0 }

it { is_expected.to be false }
end
end
end
end

0 comments on commit 9f0f2f2

Please sign in to comment.