-
Notifications
You must be signed in to change notification settings - Fork 20
/
check_box_test.rb
104 lines (88 loc) · 2.87 KB
/
check_box_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# Copyright (c) [2021] SUSE LLC
#
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of version 2 of the GNU General Public License as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, contact SUSE LLC.
#
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.
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
subject { described_class.new(question) }
let(:question) do
Y2Autoinstall::Ask::Question.new("Question 1").tap do |question|
question.type = "boolean"
end
end
include_examples "CWM::CheckBox"
include_examples "ask dialog widget"
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