Skip to content

Commit 2035db2

Browse files
committed
Update build fixture tests
1 parent 78e2112 commit 2035db2

3 files changed

Lines changed: 109 additions & 42 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"url": "https://api.github.com/repos/github/developer.github.com/pages/builds/5472601",
3+
"status": "errored",
4+
"error": {
5+
"message": "Some message"
6+
},
7+
"pusher": {
8+
"login": "octocat",
9+
"id": 1,
10+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
11+
"gravatar_id": "",
12+
"url": "https://api.github.com/users/octocat",
13+
"html_url": "https://github.com/octocat",
14+
"followers_url": "https://api.github.com/users/octocat/followers",
15+
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
16+
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
17+
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
18+
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
19+
"organizations_url": "https://api.github.com/users/octocat/orgs",
20+
"repos_url": "https://api.github.com/users/octocat/repos",
21+
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
22+
"received_events_url": "https://api.github.com/users/octocat/received_events",
23+
"type": "User",
24+
"site_admin": false
25+
},
26+
"commit": "fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210",
27+
"duration": 2104,
28+
"created_at": "2014-02-10T19:00:49Z",
29+
"updated_at": "2014-02-10T19:00:51Z"
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"url": "https://api.github.com/repos/github/developer.github.com/pages/builds/5472601",
3+
"status": "built",
4+
"error": {
5+
"message": null
6+
},
7+
"pusher": {
8+
"login": "octocat",
9+
"id": 1,
10+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
11+
"gravatar_id": "",
12+
"url": "https://api.github.com/users/octocat",
13+
"html_url": "https://github.com/octocat",
14+
"followers_url": "https://api.github.com/users/octocat/followers",
15+
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
16+
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
17+
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
18+
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
19+
"organizations_url": "https://api.github.com/users/octocat/orgs",
20+
"repos_url": "https://api.github.com/users/octocat/repos",
21+
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
22+
"received_events_url": "https://api.github.com/users/octocat/received_events",
23+
"type": "User",
24+
"site_admin": false
25+
},
26+
"commit": "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
27+
"duration": 2104,
28+
"created_at": "2014-02-10T19:00:49Z",
29+
"updated_at": "2014-02-10T19:00:51Z"
30+
}

spec/github_pages_health_check/repository_spec.rb

Lines changed: 49 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -50,58 +50,65 @@
5050
end
5151
end
5252

53-
%w(error success).each do |type|
54-
context "a build that was a(n) #{type}" do
55-
let(:access_token) { "1234" }
56-
let(:fixture) { File.read(fixture_path("build_#{type}.json")) }
57-
let(:url) { "https://api.github.com/repos/#{repo}/pages/builds/latest" }
58-
59-
before do
60-
stub_request(:get, url)
61-
.to_return(:status => 200,
62-
:body => fixture,
63-
:headers => { "Content-Type" => "application/json" })
64-
end
65-
66-
if type == "error"
67-
it "fails the check" do
68-
build_error = GitHubPages::HealthCheck::Errors::BuildError
69-
expect { subject.check! }.to raise_error(build_error)
53+
builds = {
54+
"error" => %w[build_error.json build_error_long_oid.json],
55+
"success" => %w[build_success.json build_success_long_oid.json],
56+
}
57+
58+
builds.each do |type, fixtures|
59+
fixtures.each do |fixture_name|
60+
context "a build that was a(n) #{type} using #{fixture_name}" do
61+
let(:access_token) { "1234" }
62+
let(:fixture) { File.read(fixture_path(fixture_name)) }
63+
let(:expected_commit) { JSON.parse(fixture).fetch("commit") }
64+
let(:url) { "https://api.github.com/repos/#{repo}/pages/builds/latest" }
65+
66+
before do
67+
stub_request(:get, url)
68+
.to_return(:status => 200,
69+
:body => fixture,
70+
:headers => { "Content-Type" => "application/json" })
7071
end
7172

72-
it "returns the build error" do
73-
expect(subject.build_error).to eql("Some message")
73+
if type == "error"
74+
it "fails the check" do
75+
build_error = GitHubPages::HealthCheck::Errors::BuildError
76+
expect { subject.check! }.to raise_error(build_error)
77+
end
78+
79+
it "returns the build error" do
80+
expect(subject.build_error).to eql("Some message")
81+
end
82+
83+
it "knows the site wasn't built" do
84+
expect(subject.built?).to be_falsy
85+
end
86+
else
87+
it "passes the check" do
88+
expect(subject.check!).to be_truthy
89+
end
90+
91+
it "returns no build error" do
92+
expect(subject.build_error).to be_nil
93+
end
94+
95+
it "knows the site was built" do
96+
expect(subject.built?).to be_truthy
97+
end
7498
end
7599

76-
it "knows the site wasn't built" do
77-
expect(subject.built?).to be_falsy
78-
end
79-
else
80-
it "passes the check" do
81-
expect(subject.check!).to be_truthy
100+
it "returns the commit OID" do
101+
expect(subject.last_build["commit"]).to eql(expected_commit)
82102
end
83103

84-
it "returns no build error" do
85-
expect(subject.build_error).to be_nil
104+
it "knows the build duration" do
105+
expect(subject.build_duration).to eql(2104)
86106
end
87107

88-
it "knows the site was built" do
89-
expect(subject.built?).to be_truthy
108+
it "knows when it was last built" do
109+
expect(subject.last_built.to_s).to match(/2014-02-10/)
90110
end
91111
end
92-
93-
it "returns the build info" do
94-
expected = "351391cdcb88ffae71ec3028c91f375a8036a26b"
95-
expect(subject.last_build["commit"]).to eql(expected)
96-
end
97-
98-
it "knows the build duration" do
99-
expect(subject.build_duration).to eql(2104)
100-
end
101-
102-
it "knows when it was last built" do
103-
expect(subject.last_built.to_s).to match(/2014-02-10/)
104-
end
105112
end
106113
end
107114

0 commit comments

Comments
 (0)