-
-
Notifications
You must be signed in to change notification settings - Fork 9.9k
/
test_drop.rb
48 lines (39 loc) · 1.29 KB
/
test_drop.rb
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
# frozen_string_literal: true
require "helper"
class TestDrop < JekyllUnitTest
context "a document drop" do
setup do
@site = fixture_site({
"collections" => ["methods"],
})
@site.process
@document = @site.collections["methods"].docs.detect do |d|
d.relative_path == "_methods/configuration.md"
end
@drop = @document.to_liquid
end
should "reject 'nil' key" do
refute @drop.key?(nil)
end
should "raise KeyError if key is not found and no default provided" do
assert_raises KeyError do
@drop.fetch("not_existing_key")
end
end
should "fetch value without default" do
assert_equal "Jekyll.configuration", @drop.fetch("title")
end
should "fetch default if key is not found" do
assert_equal "default", @drop.fetch("not_existing_key", "default")
end
should "fetch default boolean value correctly" do
assert_equal false, @drop.fetch("bar", false)
end
should "fetch default value from block if key is not found" do
assert_equal "default bar", @drop.fetch("bar") { |el| "default #{el}" }
end
should "fetch default value from block first if both argument and block given" do
assert_equal "baz", @drop.fetch("bar", "default") { "baz" }
end
end
end