inspec/test/unit/resources/parse_config_test.rb
Raphael Geissert 4872ddb780 Accept arrays in parse_config's method_missing
A single-element array allows Rspec's its behaviour to be worked around
and allow options containing dots to be tested using its.

This is already implemented by resources such as `json` and those based
on it (e.g. xml).

Related to issue #875.

Signed-off-by: Raphael Geissert <atomo64@gmail.com>
2020-12-08 10:40:51 +01:00

36 lines
1.3 KiB
Ruby

require "helper"
require "inspec/resource"
require "inspec/resources/parse_config"
describe "Inspec::Resources::ParseConfig" do
it "verify parse_config resource" do
options = {
assignment_regex: /^\s*([^=]*?)\s*=\s*(.*?)\s*$/,
}
resource = MockLoader.new(:centos6).load_resource("parse_config", "kernel.domainname = example.com", options)
result = { "kernel.domainname" => "example.com" }
_(resource.params).must_equal result
_(resource.content).must_equal "kernel.domainname = example.com"
_(resource.send("kernel.domainname")).must_equal "example.com"
end
it "verify parse_config_file resource" do
options = {
assignment_regex: /^\s*([^=]*?)\s*=\s*(.*?)\s*$/,
}
resource = MockLoader.new(:centos6).load_resource("parse_config_file", "/etc/sysctl.conf", options)
result = { "kernel.domainname" => "example.com" }
_(resource.params).must_equal result
_(resource.send("kernel.domainname")).must_equal "example.com"
end
it "parse_config resource accepts arrays due to rspec's its behavior" do
options = {
assignment_regex: /^\s*([^=]*?)\s*=\s*(.*?)\s*$/,
}
params = [:[], "kernel.domainname"]
resource = MockLoader.new(:centos6).load_resource("parse_config", "kernel.domainname = example.com", options)
_(resource.send(*params)).must_equal "example.com"
end
end