-
Notifications
You must be signed in to change notification settings - Fork 158
Expand file tree
/
Copy pathintegration_spec.rb
More file actions
114 lines (103 loc) · 4.25 KB
/
integration_spec.rb
File metadata and controls
114 lines (103 loc) · 4.25 KB
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
require "spec_helper"
require "jekyll"
require "jekyll-github-metadata/ghp_metadata_generator"
RSpec.describe("integration into a jekyll site") do
SOURCE_DIR = Pathname.new(File.expand_path("../test-site", __FILE__))
DEST_DIR = Pathname.new(File.expand_path("../../tmp/test-site-build", __FILE__))
def dest_dir(*files)
DEST_DIR.join(*files)
end
class ApiStub
attr_reader :path, :file
attr_accessor :stub
def initialize(path, file)
@path = path
@file = file
end
end
API_STUBS = {
"/users/jekyll/repos?per_page=100" => "owner_repos",
"/repos/jekyll/github-metadata" => "repo",
"/orgs/jekyll" => "org",
"/orgs/jekyll/public_members?per_page=100" => "org_members",
"/repos/jekyll/github-metadata/pages" => "repo_pages",
"/repos/jekyll/github-metadata/releases?per_page=100" => "repo_releases",
"/repos/jekyll/github-metadata/contributors?per_page=100" => "repo_contributors",
"/repos/jekyll/jekyll.github.io" => "not_found",
"/repos/jekyll/jekyll.github.com" => "repo",
"/repos/jekyll/jekyll.github.com/pages" => "repo_pages",
"/repos/jekyll/jekyll.github.io/pages" => "repo_pages"
}.map { |path, file| ApiStub.new(path, file) }
before(:each) do
# Reset some stuffs
ENV['NO_NETRC'] = "true"
ENV['JEKYLL_GITHUB_TOKEN'] = "1234abc"
ENV['PAGES_REPO_NWO'] = "jekyll/github-metadata"
ENV['PAGES_ENV'] = "dotcom"
Jekyll::GitHubMetadata.reset!
# Stub Requests
API_STUBS.each { |stub| stub.stub = stub_api(stub.path, stub.file) }
# Run Jekyll
Jekyll.logger.log_level = :error
Jekyll::Commands::Build.process({
"source" => SOURCE_DIR.to_s,
"destination" => DEST_DIR.to_s,
"gems" => %w{jekyll-github-metadata}
})
end
subject { SafeYAML::load(dest_dir("rendered.txt").read) }
{
"environment" => "dotcom",
"hostname" => "github.com",
"pages_env" => "dotcom",
"pages_hostname" => "github.io",
"help_url" => "https://help.github.com",
"api_url" => "https://api.github.com",
"versions" => proc {
begin
require 'github-pages'
GitHubPages.versions
rescue LoadError
{}
end
}.call,
"public_repositories" => Regexp.new('"id"=>17261694, "name"=>"atom-jekyll"'),
"organization_members" => Regexp.new('"login"=>"parkr", "id"=>237985'),
"build_revision" => /[a-f0-9]{40}/,
"project_title" => "github-metadata",
"project_tagline" => ":octocat: `site.github`",
"owner_name" => "jekyll",
"owner_url" => "https://github.com/jekyll",
"owner_gravatar_url" => "https://github.com/jekyll.png",
"repository_url" => "https://github.com/jekyll/github-metadata",
"repository_nwo" => "jekyll/github-metadata",
"repository_name" => "github-metadata",
"zip_url" => "https://github.com/jekyll/github-metadata/zipball/gh-pages",
"tar_url" => "https://github.com/jekyll/github-metadata/tarball/gh-pages",
"clone_url" => "https://github.com/jekyll/github-metadata.git",
"releases_url" => "https://github.com/jekyll/github-metadata/releases",
"issues_url" => "https://github.com/jekyll/github-metadata/issues",
"wiki_url" => nil, # disabled
"language" => "Ruby",
"is_user_page" => false,
"is_project_page" => true,
"show_downloads" => true,
"url" => "http://jekyll.github.io/github-metadata",
"contributors" => /"login"=>"parkr", "id"=>237985/,
"releases" => /"tag_name"=>"v1.1.0"/,
}.each do |key, value|
it "contains the correct #{key}" do
expect(subject).to have_key(key)
if value.is_a? Regexp
expect(subject[key].to_s).to match value
else
expect(subject[key]).to eql value
end
end
end
it "calls all the stubs" do
API_STUBS.each do |stub|
expect(stub.stub).to have_been_requested
end
end
end