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
|
# frozen_string_literal: true
require "spec_helper"
require "html-proofer"
describe "Configuration" do
let(:described_class) { HTMLProofer::Configuration }
it "Throws an error when the option name is not a string" do
expect do
described_class.new.parse_json_option(
123,
"",
)
end.to(raise_error(ArgumentError, "Must provide an option name in string format."))
end
it "Throws an error when the option name is empty" do
expect do
described_class.new.parse_json_option(
"",
"{}",
)
end.to(raise_error(ArgumentError, "Must provide an option name in string format."))
end
it "Throws an error when the option name is whitespace" do
expect do
described_class.new.parse_json_option(
" ",
"{}",
)
end.to(raise_error(ArgumentError, "Must provide an option name in string format."))
end
it "Throws an error when the json config is not a string" do
expect do
described_class.new.parse_json_option(
"testName",
123,
)
end.to(raise_error(ArgumentError, "Must provide a JSON configuration in string format."))
end
it "returns an empty options object when config is nil" do
result = described_class.new.parse_json_option("testName", nil)
expect(result).to(eq({}))
end
it "returns an empty options object when config is empty" do
result = described_class.new.parse_json_option("testName", "")
expect(result).to(eq({}))
end
it "returns an empty options object when config is whitespace" do
result = described_class.new.parse_json_option("testName", " ")
expect(result).to(eq({}))
end
it "Returns an object representing the json when valid json" do
result = described_class.new.parse_json_option(
"testName",
'{ "myValue": "hello world!", "numberValue": 123}',
)
expect(result[:myValue]).to(eq("hello world!"))
expect(result[:numberValue]).to(eq(123))
end
it "Throws an error when the json config is not valid json" do
expect { described_class.new.parse_json_option("testName", "abc") }.to(raise_error(ArgumentError))
end
end
|