-
Notifications
You must be signed in to change notification settings - Fork 124
/
site_github_munger_spec.rb
155 lines (127 loc) · 4.49 KB
/
site_github_munger_spec.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
require "spec_helper"
require "jekyll"
require "jekyll-github-metadata/site_github_munger"
RSpec.describe(Jekyll::GitHubMetadata::SiteGitHubMunger) do
let(:source) { File.expand_path("test-site", __dir__) }
let(:dest) { File.expand_path("../tmp/test-site-build", __dir__) }
let(:github_namespace) { nil }
let(:user_config) { { "github" => github_namespace } }
let(:site) { Jekyll::Site.new(Jekyll::Configuration.from(user_config)) }
subject { described_class.new(site) }
let!(:stubs) { stub_all_api_requests }
context "generating" do
before(:each) do
ENV["JEKYLL_ENV"] = "production"
subject.munge!
end
context "with site.github as nil" do
it "replaces site.github with the drop" do
expect(site.config["github"]).to be_a(Liquid::Drop)
end
end
context "without site.github" do
let(:user_config) { {} }
it "replaces site.github with the drop" do
expect(site.config["github"]).to be_a(Liquid::Drop)
end
end
context "with site.github as a non-hash" do
let(:github_namespace) { "foo" }
it "doesn't munge" do
expect(site.config["github"]).to eql("foo")
end
end
context "with site.github as a hash" do
let(:github_namespace) { { "source" => { "branch" => "foo" } } }
it "lets user-specified values override the drop" do
expect(site.config["github"].invoke_drop("source")["branch"]).to eql("foo")
end
it "still sets other values" do
expect(site.config["github"].invoke_drop("source")["path"]).to eql("/")
end
end
context "with site.url set" do
let(:user_config) { { "url" => "http://example.com" } }
it "doesn't mangle site.url" do
expect(site.config["url"]).to eql("http://example.com")
end
end
context "with site.baseurl set" do
let(:user_config) { { "baseurl" => "/foo" } }
it "doesn't mangle site.url" do
expect(site.config["baseurl"]).to eql("/foo")
end
end
context "with site.baseurl set to ''" do
let(:user_config) { { "baseurl" => "" } }
it "doesn't mangle site.baseurl" do
expect(site.config["baseurl"]).to eql("")
end
end
context "with site.baseurl set to '/'" do
let(:user_config) { { "baseurl" => "/" } }
it "mangles site.url" do
expect(site.config["baseurl"]).to eql("/github-metadata")
end
end
context "without site.url set" do
it "sets site.url" do
expect(site.config["url"]).to eql("http://jekyll.github.io")
end
end
context "without site.baseurl set" do
it "sets site.baseurl" do
expect(site.config["baseurl"]).to eql("/github-metadata")
end
end
context "title and description" do
context "with title and description set" do
let(:user_config) do
{ "title" => "My title", "description" => "My description" }
end
it "respects the title and tagline" do
expect(site.config["title"]).to eql("My title")
expect(site.config["description"]).to eql("My description")
end
end
it "sets the title and description" do
expect(site.config["title"]).to eql("github-metadata")
expect(site.config["description"]).to eql(":octocat: `site.github`")
end
end
end
context "with a client with no credentials" do
before(:each) do
Jekyll::GitHubMetadata.client = Jekyll::GitHubMetadata::Client.new({ :access_token => "" })
end
it "does not fail upon call to #munge" do
expect(lambda do
subject.munge!
end).not_to raise_error
end
it "sets the site.github config" do
subject.munge!
expect(site.config["github"]).to be_instance_of(Jekyll::GitHubMetadata::MetadataDrop)
end
end
context "with a client with bad credentials" do
before(:each) do
Jekyll::GitHubMetadata.client = Jekyll::GitHubMetadata::Client.new({ :access_token => "1234abc" })
stub_request(:get, url("/repos/jekyll/github-metadata/pages"))
.with(:headers => request_headers.merge({
"Authorization" => "token 1234abc",
}))
.to_return(
:status => 401,
:headers => WebMockHelper::RESPONSE_HEADERS,
:body => webmock_data("bad_credentials")
)
end
it "fails loudly upon call to any drop method" do
subject.munge!
expect(lambda do
site.config["github"]["url"]
end).to raise_error(Jekyll::GitHubMetadata::Client::BadCredentialsError)
end
end
end