|
1 | 1 | require 'spec_helper'
|
2 | 2 |
|
3 | 3 | describe OmniAuth::Strategies::GitHub do
|
4 |
| - let(:access_token) { stub('AccessToken', :options => {}) } |
5 |
| - let(:parsed_response) { stub('ParsedResponse') } |
6 |
| - let(:response) { stub('Response', :parsed => parsed_response) } |
| 4 | + let(:access_token) { instance_double('AccessToken', :options => {}) } |
| 5 | + let(:parsed_response) { instance_double('ParsedResponse') } |
| 6 | + let(:response) { instance_double('Response', :parsed => parsed_response) } |
7 | 7 |
|
8 | 8 | let(:enterprise_site) { 'https://some.other.site.com/api/v3' }
|
9 | 9 | let(:enterprise_authorize_url) { 'https://some.other.site.com/login/oauth/authorize' }
|
|
25 | 25 | end
|
26 | 26 |
|
27 | 27 | before(:each) do
|
28 |
| - subject.stub!(:access_token).and_return(access_token) |
| 28 | + allow(subject).to receive(:access_token).and_return(access_token) |
29 | 29 | end
|
30 | 30 |
|
31 |
| - context "client options" do |
| 31 | + context 'client options' do |
32 | 32 | it 'should have correct site' do
|
33 |
| - subject.options.client_options.site.should eq("https://api.github.com") |
| 33 | + expect(subject.options.client_options.site).to eq('https://api.github.com') |
34 | 34 | end
|
35 | 35 |
|
36 | 36 | it 'should have correct authorize url' do
|
37 |
| - subject.options.client_options.authorize_url.should eq('https://github.com/login/oauth/authorize') |
| 37 | + expect(subject.options.client_options.authorize_url).to eq('https://github.com/login/oauth/authorize') |
38 | 38 | end
|
39 | 39 |
|
40 | 40 | it 'should have correct token url' do
|
41 |
| - subject.options.client_options.token_url.should eq('https://github.com/login/oauth/access_token') |
| 41 | + expect(subject.options.client_options.token_url).to eq('https://github.com/login/oauth/access_token') |
42 | 42 | end
|
43 | 43 |
|
44 |
| - describe "should be overrideable" do |
45 |
| - it "for site" do |
46 |
| - enterprise.options.client_options.site.should eq(enterprise_site) |
| 44 | + describe 'should be overrideable' do |
| 45 | + it 'for site' do |
| 46 | + expect(enterprise.options.client_options.site).to eq(enterprise_site) |
47 | 47 | end
|
48 | 48 |
|
49 |
| - it "for authorize url" do |
50 |
| - enterprise.options.client_options.authorize_url.should eq(enterprise_authorize_url) |
| 49 | + it 'for authorize url' do |
| 50 | + expect(enterprise.options.client_options.authorize_url).to eq(enterprise_authorize_url) |
51 | 51 | end
|
52 | 52 |
|
53 |
| - it "for token url" do |
54 |
| - enterprise.options.client_options.token_url.should eq(enterprise_token_url) |
| 53 | + it 'for token url' do |
| 54 | + expect(enterprise.options.client_options.token_url).to eq(enterprise_token_url) |
55 | 55 | end
|
56 | 56 | end
|
57 | 57 | end
|
58 | 58 |
|
59 |
| - context "#email_access_allowed?" do |
60 |
| - it "should not allow email if scope is nil" do |
61 |
| - subject.options['scope'].should be_nil |
62 |
| - subject.should_not be_email_access_allowed |
| 59 | + context '#email_access_allowed?' do |
| 60 | + it 'should not allow email if scope is nil' do |
| 61 | + expect(subject.options['scope']).to be_nil |
| 62 | + expect(subject).to_not be_email_access_allowed |
63 | 63 | end
|
64 | 64 |
|
65 |
| - it "should allow email if scope is user" do |
| 65 | + it 'should allow email if scope is user' do |
66 | 66 | subject.options['scope'] = 'user'
|
67 |
| - subject.should be_email_access_allowed |
| 67 | + expect(subject).to be_email_access_allowed |
68 | 68 | end
|
69 | 69 |
|
70 |
| - it "should allow email if scope is a bunch of stuff including user" do |
| 70 | + it 'should allow email if scope is a bunch of stuff including user' do |
71 | 71 | subject.options['scope'] = 'public_repo,user,repo,delete_repo,gist'
|
72 |
| - subject.should be_email_access_allowed |
| 72 | + expect(subject).to be_email_access_allowed |
73 | 73 | end
|
74 | 74 |
|
75 |
| - it "should not allow email if scope does not grant email access" do |
| 75 | + it 'should not allow email if scope does not grant email access' do |
76 | 76 | subject.options['scope'] = 'repo,user:follow'
|
77 |
| - subject.should_not be_email_access_allowed |
| 77 | + expect(subject).to_not be_email_access_allowed |
78 | 78 | end
|
79 | 79 |
|
80 |
| - it "should assume email access not allowed if scope is something currently not documented " do |
| 80 | + it 'should assume email access not allowed if scope is something currently not documented' do |
81 | 81 | subject.options['scope'] = 'currently_not_documented'
|
82 |
| - subject.should_not be_email_access_allowed |
| 82 | + expect(subject).to_not be_email_access_allowed |
83 | 83 | end
|
84 | 84 | end
|
85 | 85 |
|
86 |
| - context "#email" do |
87 |
| - it "should return email from raw_info if available" do |
88 |
| - subject.stub!(:raw_info).and_return({'email' => '[email protected]'}) |
89 |
| - subject.email.should eq('[email protected]') |
| 86 | + context '#email' do |
| 87 | + it 'should return email from raw_info if available' do |
| 88 | + allow(subject).to receive(:raw_info).and_return({ 'email' => '[email protected]' }) |
| 89 | + expect(subject.email).to eq('[email protected]') |
90 | 90 | end
|
91 | 91 |
|
92 |
| - it "should return nil if there is no raw_info and email access is not allowed" do |
93 |
| - subject.stub!(:raw_info).and_return({}) |
94 |
| - subject.email.should be_nil |
| 92 | + it 'should return nil if there is no raw_info and email access is not allowed' do |
| 93 | + allow(subject).to receive(:raw_info).and_return({}) |
| 94 | + expect(subject.email).to be_nil |
95 | 95 | end
|
96 | 96 |
|
97 |
| - it "should not return the primary email if there is no raw_info and email access is allowed" do |
| 97 | + it 'should not return the primary email if there is no raw_info and email access is allowed' do |
98 | 98 | emails = [
|
99 | 99 | { 'email' => '[email protected]', 'primary' => false },
|
100 | 100 | { 'email' => '[email protected]', 'primary' => true }
|
101 | 101 | ]
|
102 |
| - subject.stub!(:raw_info).and_return({}) |
| 102 | + allow(subject).to receive(:raw_info).and_return({}) |
103 | 103 | subject.options['scope'] = 'user'
|
104 |
| - subject.stub!(:emails).and_return(emails) |
105 |
| - subject.email.should eq(nil) |
| 104 | + allow(subject).to receive(:emails).and_return(emails) |
| 105 | + expect(subject.email).to be_nil |
106 | 106 | end
|
107 | 107 |
|
108 |
| - it "should not return the first email if there is no raw_info and email access is allowed" do |
| 108 | + it 'should not return the first email if there is no raw_info and email access is allowed' do |
109 | 109 | emails = [
|
110 | 110 | { 'email' => '[email protected]', 'primary' => false },
|
111 | 111 | { 'email' => '[email protected]', 'primary' => false }
|
112 | 112 | ]
|
113 |
| - subject.stub!(:raw_info).and_return({}) |
| 113 | + allow(subject).to receive(:raw_info).and_return({}) |
114 | 114 | subject.options['scope'] = 'user'
|
115 |
| - subject.stub!(:emails).and_return(emails) |
116 |
| - subject.email.should eq(nil) |
| 115 | + allow(subject).to receive(:emails).and_return(emails) |
| 116 | + expect(subject.email).to be_nil |
117 | 117 | end
|
118 | 118 | end
|
119 | 119 |
|
120 |
| - context "#raw_info" do |
121 |
| - it "should use relative paths" do |
122 |
| - access_token.should_receive(:get).with('user').and_return(response) |
123 |
| - subject.raw_info.should eq(parsed_response) |
| 120 | + context '#raw_info' do |
| 121 | + it 'should use relative paths' do |
| 122 | + expect(access_token).to receive(:get).with('user').and_return(response) |
| 123 | + expect(subject.raw_info).to eq(parsed_response) |
124 | 124 | end
|
125 | 125 | end
|
126 | 126 |
|
127 |
| - context "#emails" do |
128 |
| - it "should use relative paths" do |
129 |
| - access_token.should_receive(:get).with('user/emails', :headers=>{"Accept"=>"application/vnd.github.v3"}).and_return(response) |
| 127 | + context '#emails' do |
| 128 | + it 'should use relative paths' do |
| 129 | + expect(access_token).to receive(:get).with('user/emails', :headers => { |
| 130 | + 'Accept' => 'application/vnd.github.v3' |
| 131 | + }).and_return(response) |
| 132 | + |
130 | 133 | subject.options['scope'] = 'user'
|
131 |
| - subject.emails.should eq(parsed_response) |
| 134 | + expect(subject.emails).to eq(parsed_response) |
132 | 135 | end
|
133 | 136 | end
|
134 | 137 |
|
135 | 138 | context '#info.urls' do
|
136 | 139 | it 'should use html_url from raw_info' do
|
137 |
| - subject.stub(:raw_info).and_return({ 'login' => 'me', 'html_url' => 'http://enterprise/me' }) |
138 |
| - subject.info['urls']['GitHub'].should == 'http://enterprise/me' |
| 140 | + allow(subject).to receive(:raw_info).and_return({ 'login' => 'me', 'html_url' => 'http://enterprise/me' }) |
| 141 | + expect(subject.info['urls']['GitHub']).to eq('http://enterprise/me') |
139 | 142 | end
|
140 | 143 | end
|
141 |
| - |
142 | 144 | end
|
0 commit comments