|
50 | 50 | end |
51 | 51 | end |
52 | 52 |
|
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" }) |
70 | 71 | end |
71 | 72 |
|
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 |
74 | 98 | end |
75 | 99 |
|
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) |
82 | 102 | end |
83 | 103 |
|
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) |
86 | 106 | end |
87 | 107 |
|
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/) |
90 | 110 | end |
91 | 111 | 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 |
105 | 112 | end |
106 | 113 | end |
107 | 114 |
|
|
0 commit comments