Skip to content

Commit

Permalink
Extend Ask::CheckBox unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed May 10, 2021
1 parent 939c603 commit 9740dbc
Showing 1 changed file with 67 additions and 1 deletion.
68 changes: 67 additions & 1 deletion test/lib/autoinstall/widgets/ask/check_box_test.rb
Expand Up @@ -20,6 +20,7 @@
require_relative "../../../../test_helper"
require "autoinstall/widgets/ask/check_box"
require "autoinstall/ask/question"
require "autoinstall/script"
require "cwm/rspec"

describe Y2Autoinstall::Widgets::Ask::CheckBox do
Expand All @@ -34,5 +35,70 @@
include_examples "CWM::CheckBox"
include_examples "ask dialog widget"

describe "#init"
describe "#init" do
before do
question.default = false
end

context "when the question has a value" do
before do
question.value = true
end

it "sets widget's value" do
expect(subject).to receive(:value=).with(true)
subject.init
end
end

context "when the question has not a value" do
context "and it has a default_value_script" do
let(:script) do
instance_double(
Y2Autoinstallation::AskDefaultValueScript,
create_script_file: nil, execute: result, stdout: stdout
)
end

let(:result) { true }
let(:stdout) { "true" }

before do
question.default_value_script = script
end

context "and the script returns 'true'" do
it "sets the value to true" do
expect(subject).to receive(:value=).with(true)
subject.init
end
end

context "and the script does not return 'true'" do
let(:stdout) { "no" }

it "sets the value to false" do
expect(subject).to receive(:value=).with(false)
subject.init
end
end

context "but the script fails" do
let(:result) { false }

it "uses the default value" do
expect(subject).to receive(:value=).with(question.default)
subject.init
end
end
end

context "and there is no default_value_script" do
it "uses the question default value as the widget's value" do
expect(subject).to receive(:value=).with(question.default)
subject.init
end
end
end
end
end

0 comments on commit 9740dbc

Please sign in to comment.