-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revamped Yast::RSpec:SCR including tests
- Loading branch information
Showing
5 changed files
with
172 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
#!/usr/bin/env rspec | ||
|
||
require_relative "test_helper" | ||
|
||
require "yast/rspec" | ||
|
||
describe Yast::RSpec::SCR do | ||
let(:chroot) { File.join(File.dirname(__FILE__), "chroot") } | ||
|
||
class DummyError < Exception; end | ||
|
||
def root_content | ||
Yast::SCR.Read(path(".target.dir"), "/") | ||
end | ||
|
||
describe "#path" do | ||
it "returns the expected Yast::Path object" do | ||
expect(path(".target.dir")).to eq(Yast::Path.new(".target.dir")) | ||
end | ||
end | ||
|
||
describe "#change_scr_root" do | ||
describe "file check" do | ||
it "raises an exception if the directory does not exist" do | ||
expect { change_scr_root("not/found/file") }. | ||
to raise_exception(RuntimeError, /not a valid directory/) | ||
end | ||
|
||
it "raises an exception if called on a regular file" do | ||
expect { change_scr_root(File.join(chroot, "just_a_file")) }. | ||
to raise_exception(RuntimeError, /not a valid directory/) | ||
end | ||
end | ||
|
||
describe "block syntax" do | ||
it "changes the root path inside the block" do | ||
expect(root_content).not_to eq(["just_a_file"]) | ||
change_scr_root(chroot) do | ||
expect(root_content).to eq(["just_a_file"]) | ||
end | ||
end | ||
|
||
it "restores the original path after running the block" do | ||
change_scr_root(chroot) do | ||
# Do something in the chroot | ||
end | ||
expect(root_content).not_to eq(["just_a_file"]) | ||
end | ||
|
||
it "restores the original path after a exception" do | ||
begin | ||
change_scr_root(chroot) do | ||
raise DummyError | ||
end | ||
rescue DummyError | ||
# Just catch the exception | ||
end | ||
expect(root_content).not_to eq(["just_a_file"]) | ||
end | ||
|
||
it "raises an exception for nested calls" do | ||
change_scr_root(chroot) do | ||
expect { change_scr_root(chroot) }. | ||
to raise_exception(RuntimeError, /reset_scr_root was expected/) | ||
end | ||
expect(root_content).not_to eq(["just_a_file"]) | ||
end | ||
end | ||
|
||
describe "non-block syntax" do | ||
after do | ||
reset_scr_root | ||
end | ||
|
||
it "changes the root path" do | ||
expect(root_content).not_to eq(["just_a_file"]) | ||
change_scr_root(chroot) | ||
expect(root_content).to eq(["just_a_file"]) | ||
end | ||
|
||
it "raises an exception for consecutive calls" do | ||
change_scr_root(chroot) | ||
expect { change_scr_root(chroot) }. | ||
to raise_exception(RuntimeError, /reset_scr_root was expected/) | ||
end | ||
end | ||
end | ||
|
||
describe "#reset_scr_root" do | ||
it "restores the original path" do | ||
change_scr_root(chroot) | ||
reset_scr_root | ||
expect(root_content).not_to eq(["just_a_file"]) | ||
end | ||
|
||
it "raises an exception if #change_scr_root was not called before" do | ||
expect { reset_scr_root }. | ||
to raise_exception(RuntimeError, /Unable to find a chrooted SCR/) | ||
end | ||
|
||
it "raises an exception if default SCR was modified" do | ||
original_handle = Yast::WFM.SCRGetDefault | ||
change_scr_root(chroot) | ||
|
||
# Manually close the chroot | ||
Yast::WFM.SCRClose(Yast::WFM.SCRGetDefault) | ||
Yast::WFM.SCRSetDefault(original_handle) | ||
|
||
expect { reset_scr_root }. | ||
to raise_exception(RuntimeError, /not the current default/) | ||
end | ||
end | ||
end |