File: configuration_spec.rb

package info (click to toggle)
ruby-html-proofer 5.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 22,524 kB
  • sloc: ruby: 4,389; sh: 8; makefile: 4; javascript: 1; php: 1
file content (72 lines) | stat: -rw-r--r-- 2,163 bytes parent folder | download
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