Skip to content

Commit 1934bf0

Browse files
committed
Change to update specs to remove global state mutation.
1 parent 929ec0a commit 1934bf0

9 files changed

Lines changed: 39 additions & 53 deletions

File tree

spec/github/authorization_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@
145145
let(:options) { { :basic_auth => 'github:pass' } }
146146

147147
it "should return hash with basic auth params" do
148-
expect(github.authentication).to be_a Hash
149-
expect(github.authentication).to have_key(:basic_auth)
148+
expect(github.authentication).to include({login: 'github'})
149+
expect(github.authentication).to include({password: 'pass'})
150150
end
151151
end
152152

spec/github/client/authorizations/app/check_spec.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,19 @@
22

33
require 'spec_helper'
44

5-
describe Github::Client::Authorizations::App, '#check' do
5+
RSpec.describe Github::Client::Authorizations::App, '#check' do
66
let(:basic_auth) { 'login:password' }
77
let(:host) { "https://#{basic_auth}@api.github.com" }
88
let(:request_path) { "/applications/#{client_id}/tokens/#{access_token}" }
99
let(:client_id) { 1 }
1010
let(:access_token) { 'abc123' }
1111

12-
before {
13-
subject.basic_auth = basic_auth
12+
subject { described_class.new(basic_auth: basic_auth) }
1413

14+
before do
1515
stub_get(request_path, host).to_return(body: body, status: status,
1616
headers: {content_type: 'application/json; charset=utf-8'})
17-
}
18-
19-
after { reset_authentication_for(subject) }
17+
end
2018

2119
context 'when app makes a request' do
2220
let(:body) { "" }

spec/github/client/authorizations/app/create_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22

33
require 'spec_helper'
44

5-
describe Github::Client::Authorizations::App, '#create' do
5+
RSpec.describe Github::Client::Authorizations::App, '#create' do
66
let(:basic_auth) { 'login:password' }
77
let(:host) { "https://#{basic_auth}@api.github.com" }
88
let(:inputs) { { :scopes => ['repo'] } }
99
let(:request_path) { "/authorizations/clients/#{client_id}" }
1010

11-
before {
12-
subject.basic_auth = basic_auth
11+
subject { described_class.new(basic_auth: basic_auth) }
1312

13+
before do
1414
stub_put(request_path, host).to_return(body: body, status: status,
1515
headers: {content_type: 'application/json; charset=utf-8'})
16-
}
16+
end
1717

1818
after { reset_authentication_for(subject) }
1919

spec/github/client/authorizations/app/delete_spec.rb

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,17 @@
22

33
require 'spec_helper'
44

5-
describe Github::Client::Authorizations::App, '#delete' do
5+
RSpec.describe Github::Client::Authorizations::App, '#delete' do
66
let(:basic_auth) { 'login:password' }
77
let(:host) { "https://#{basic_auth}@api.github.com" }
88
let(:client_id) { 1 }
99

10-
before {
11-
stub_delete(request_path, host).to_return(:body => body, :status => status,
12-
:headers => {:content_type => "application/json; charset=utf-8"})
13-
}
10+
subject { described_class.new(basic_auth: basic_auth) }
1411

15-
before { subject.basic_auth = basic_auth }
16-
17-
after { reset_authentication_for(subject) }
12+
before do
13+
stub_delete(request_path, host).to_return(body: body, status: status,
14+
headers: {content_type: "application/json; charset=utf-8"})
15+
end
1816

1917
context "when app revokes all tokens" do
2018
let(:request_path) { "/applications/#{client_id}/tokens" }

spec/github/client/authorizations/create_spec.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@
88
let(:inputs) { {scopes: ['repo'], note: 'admin script' } }
99
let(:request_path) { "/authorizations" }
1010

11-
before {
12-
subject.basic_auth = basic_auth
11+
subject { described_class.new(basic_auth: basic_auth) }
1312

13+
before do
1414
stub_post(request_path, host).to_return(body: body, status: status,
1515
headers: {content_type: 'application/json; charset=utf-8'})
16-
}
17-
18-
after { reset_authentication_for(subject) }
16+
end
1917

2018
context 'when user creates token' do
2119
let(:body) { fixture('auths/authorization.json') }

spec/github/client/authorizations/delete_spec.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,18 @@
66
let(:basic_auth) { 'login:password' }
77
let(:host) { "https://#{basic_auth}@api.github.com" }
88

9-
before { subject.basic_auth = basic_auth }
10-
11-
after { reset_authentication_for(subject) }
9+
subject { described_class.new(basic_auth: basic_auth) }
1210

1311
context "when an user" do
1412
let(:authorization_id) { 1 }
1513
let(:request_path) { "/authorizations/#{authorization_id}" }
1614
let(:body) { '' }
1715
let(:status) { 204 }
1816

19-
before {
17+
before do
2018
stub_delete(request_path, host).to_return(body: body, status: status,
2119
headers: {content_type: 'application/json; charset=utf-8'})
22-
}
20+
end
2321

2422
it "fails to get resource without basic authentication" do
2523
reset_authentication_for subject

spec/github/client/authorizations/get_spec.rb

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,18 @@
22

33
require 'spec_helper'
44

5-
describe Github::Client::Authorizations, '#get' do
5+
RSpec.describe Github::Client::Authorizations, '#get' do
66
let(:basic_auth) { 'login:password' }
77
let(:request_path) { "/authorizations/#{authorization_id}" }
88
let(:host) { "https://#{basic_auth}@api.github.com" }
99
let(:authorization_id) { 1 }
1010

11-
before {
12-
stub_get(request_path, host).to_return(:body => body, :status => status,
13-
:headers => {:content_type => "application/json; charset=utf-8"})
14-
}
11+
subject { described_class.new(basic_auth: basic_auth) }
1512

16-
before { subject.basic_auth = basic_auth }
17-
18-
after { reset_authentication_for(subject) }
13+
before do
14+
stub_get(request_path, host).to_return(body: body, status: status,
15+
headers: {content_type: "application/json; charset=utf-8"})
16+
end
1917

2018
context "resource found" do
2119
let(:body) { fixture('auths/authorization.json') }

spec/github/client/authorizations/list_spec.rb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,17 @@
22

33
require 'spec_helper'
44

5-
describe Github::Client::Authorizations, '#list' do
5+
RSpec.describe Github::Client::Authorizations, '#list' do
66
let(:basic_auth) { 'login:password' }
77
let(:request_path) { "/authorizations" }
88
let(:host) { "https://#{basic_auth}@api.github.com" }
99

10-
before {
10+
subject { described_class.new(basic_auth: basic_auth) }
11+
12+
before do
1113
stub_get(request_path, host).to_return(:body => body, :status => status,
1214
:headers => {:content_type => "application/json; charset=utf-8"})
13-
}
14-
15-
before { subject.basic_auth = basic_auth }
16-
17-
after { reset_authentication_for(subject) }
15+
end
1816

1917
context "resource found" do
2018
let(:body) { fixture('auths/authorizations.json') }

spec/github/client/authorizations/update_spec.rb

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,19 @@
22

33
require 'spec_helper'
44

5-
describe Github::Client::Authorizations, '#update' do
5+
RSpec.describe Github::Client::Authorizations, '#update' do
66
let(:basic_auth) { 'login:password' }
77
let(:request_path) { "/authorizations/#{authorization_id}" }
88
let(:host) { "https://#{basic_auth}@api.github.com" }
99
let(:authorization_id) { 1 }
1010
let(:inputs) { { :add_scopes => ['repo'] } }
1111

12-
before {
13-
stub_patch(request_path, host).to_return(:body => body, :status => status,
14-
:headers => {:content_type => "application/json; charset=utf-8"})
15-
}
12+
subject { described_class.new(basic_auth: basic_auth) }
1613

17-
before { subject.basic_auth = basic_auth }
18-
19-
after { reset_authentication_for(subject) }
14+
before do
15+
stub_patch(request_path, host).to_return(body: body, status: status,
16+
headers: {content_type: "application/json; charset=utf-8"})
17+
end
2018

2119
context "resouce updated" do
2220
let(:body) { fixture('auths/authorization.json') }

0 commit comments

Comments
 (0)