File: configuration_spec.rb

package info (click to toggle)
ruby-json-spec 1.1.5-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 312 kB
  • sloc: ruby: 1,059; makefile: 2
file content (62 lines) | stat: -rw-r--r-- 1,632 bytes parent folder | download | duplicates (3)
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
require "spec_helper"

describe JsonSpec::Configuration do
  it "excludes id and timestamps by default" do
    JsonSpec.excluded_keys.should eq ["id", "created_at", "updated_at"]
  end

  it "excludes custom keys" do
    JsonSpec.exclude_keys("token")
    JsonSpec.excluded_keys.should eq ["token"]
  end

  it "excludes custom keys via setter" do
    JsonSpec.excluded_keys = ["token"]
    JsonSpec.excluded_keys.should eq ["token"]
  end

  it "excludes custom keys via block" do
    JsonSpec.configure { |c| c.exclude_keys("token") }
    JsonSpec.excluded_keys.should eq ["token"]
  end

  it "excludes custom keys via block setter" do
    JsonSpec.configure { |c| c.excluded_keys = ["token"] }
    JsonSpec.excluded_keys.should eq ["token"]
  end

  it "excludes custom keys via instance-evaluated block" do
    JsonSpec.configure{ exclude_keys("token") }
    JsonSpec.excluded_keys.should eq ["token"]
  end

  it "ensures its excluded keys are strings" do
    JsonSpec.exclude_keys(:token)
    JsonSpec.excluded_keys.should eq ["token"]
  end

  it "ensures its excluded keys are unique" do
    JsonSpec.exclude_keys("token", :token)
    JsonSpec.excluded_keys.should eq ["token"]
  end

  it "resets its excluded keys" do
    original = JsonSpec.excluded_keys

    JsonSpec.exclude_keys("token")
    JsonSpec.excluded_keys.should_not eq original

    JsonSpec.reset
    JsonSpec.excluded_keys.should eq original
  end

  it "resets its directory" do
    JsonSpec.directory.should be_nil

    JsonSpec.directory = "/"
    JsonSpec.directory.should_not be_nil

    JsonSpec.reset
    JsonSpec.directory.should be_nil
  end
end