diff --git a/spec/fixtures/cassettes/github_lastrelease.yml b/spec/fixtures/cassettes/github_lastrelease.yml new file mode 100644 index 000000000..163e5bdea --- /dev/null +++ b/spec/fixtures/cassettes/github_lastrelease.yml @@ -0,0 +1,93 @@ +--- +http_interactions: +- request: + method: get + uri: https://api.github.com/repos/sgmap/tps/releases/latest + body: + encoding: US-ASCII + string: '' + headers: + Accept: + - "*/*" + Accept-Encoding: + - gzip, deflate + User-Agent: + - rest-client/2.0.0 (darwin15.6.0 x86_64) ruby/2.3.1p112 + response: + status: + code: 200 + message: OK + headers: + Server: + - GitHub.com + Date: + - Thu, 15 Dec 2016 15:48:21 GMT + Content-Type: + - application/json; charset=utf-8 + Transfer-Encoding: + - chunked + Status: + - 200 OK + X-Ratelimit-Limit: + - '60' + X-Ratelimit-Remaining: + - '46' + X-Ratelimit-Reset: + - '1481819650' + Cache-Control: + - public, max-age=60, s-maxage=60 + Vary: + - Accept + - Accept-Encoding + Etag: + - W/"104562bed37a43b27f0e4ba70c1d2cff" + Last-Modified: + - Thu, 17 Nov 2016 10:56:47 GMT + X-Github-Media-Type: + - github.v3 + Access-Control-Expose-Headers: + - ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, + X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval + Access-Control-Allow-Origin: + - "*" + Content-Security-Policy: + - default-src 'none' + Strict-Transport-Security: + - max-age=31536000; includeSubdomains; preload + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - deny + X-Xss-Protection: + - 1; mode=block + X-Served-By: + - 46808ddc41c302090177e58148908b23 + Content-Encoding: + - gzip + X-Github-Request-Id: + - B918B84A:73B5:C61DB9:5852BB44 + body: + encoding: ASCII-8BIT + string: !binary |- + H4sIAAAAAAAAA6VVy27bMBD8FUKXXBzTap4V0hZFeikQNIe0RdEHDFqiZQaU + yHJJt6mRf+nV3+Ef65BSnMTIA0ZPssTd4ezs7niRBaezIpt5b6ngXFg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: Thu, 15 Dec 2016 15:48:21 GMT +recorded_with: VCR 3.0.3 diff --git a/spec/lib/github/api_spec.rb b/spec/lib/github/api_spec.rb new file mode 100644 index 000000000..f605391cc --- /dev/null +++ b/spec/lib/github/api_spec.rb @@ -0,0 +1,26 @@ +require 'spec_helper' + +describe Github::API do + + describe '.base_uri' do + it { expect(described_class.base_uri).to eq 'https://api.github.com' } + end + + describe '.latest_release' do + subject { described_class.latest_release } + + context 'when github is up', vcr: {cassette_name: 'github_lastrelease'} do + it { expect(subject).to be_a RestClient::Response } + it { expect(subject.code).to eq 200 } + end + + context 'when github is down' do + + before do + allow_any_instance_of(RestClient::Resource).to receive(:get).and_raise(RestClient::Forbidden) + end + + it { is_expected.to be_nil } + end + end +end \ No newline at end of file diff --git a/spec/lib/github/releases_spec.rb b/spec/lib/github/releases_spec.rb new file mode 100644 index 000000000..41bcfc049 --- /dev/null +++ b/spec/lib/github/releases_spec.rb @@ -0,0 +1,23 @@ +require 'spec_helper' + +describe Github::Releases do + + describe '.latest' do + + subject { described_class.latest } + + context 'when github is up', vcr: {cassette_name: 'github_lastrelease'} do + it { expect(subject.url).to eq 'https://api.github.com/repos/sgmap/tps/releases/4685573' } + it { expect(subject.body).to match /.*[Nouveautés].*/ } + it { expect(subject.published_at).to match /[0-9][0-9][\/][0-9][0-9][\/][0-9][0-9][0-9][0-9]/ } + end + + context 'when github is down' do + before do + allow_any_instance_of(RestClient::Resource).to receive(:get).and_raise(RestClient::Forbidden) + end + + it { is_expected.to be_nil } + end + end +end \ No newline at end of file