Skip to content

Commit

Permalink
add rspec instead unit testing
Browse files Browse the repository at this point in the history
  • Loading branch information
adaoraul committed Feb 25, 2019
1 parent 891c225 commit 129859a
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 189 deletions.
11 changes: 4 additions & 7 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
require 'bundler/gem_tasks'
require 'rake/testtask'
require 'rspec/core/rake_task'

Rake::TestTask.new do |task|
task.libs << 'lib'
task.libs << 'test'
task.test_files = FileList['test/*_test.rb']
end
RSpec::Core::RakeTask.new

task :default => :test
desc 'Run specs'
task default: :spec
31 changes: 15 additions & 16 deletions omniauth-discord.gemspec
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
# coding: utf-8
$:.push File.expand_path('../lib', __FILE__)
$LOAD_PATH.push File.expand_path('lib', __dir__)
require 'omniauth/discord/version'

Gem::Specification.new do |spec|
spec.name = "omniauth-discord"
spec.name = 'omniauth-discord'
spec.version = Omniauth::Discord::VERSION
spec.authors = ["Adão Raul"]
spec.email = ["adao.raul@gmail.com"]
spec.authors = ['Adão Raul']
spec.email = ['adao.raul@gmail.com']

spec.summary = "Discord OAuth2 Strategy for OmniAuth"
spec.summary = 'Discord OAuth2 Strategy for OmniAuth'
spec.description = spec.summary
spec.homepage = "http://github.com/adaoraul/omniauth-discord"
spec.license = "MIT"
spec.homepage = 'http://github.com/adaoraul/omniauth-discord'
spec.license = 'MIT'

spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]
spec.require_paths = ['lib']

spec.add_runtime_dependency 'omniauth-oauth2', '~> 1.4'
spec.add_runtime_dependency 'omniauth'
spec.add_runtime_dependency 'omniauth-oauth2'

spec.add_development_dependency "dotenv"
spec.add_development_dependency "bundler"
spec.add_development_dependency "rake"
spec.add_development_dependency "minitest-utils"
spec.add_development_dependency "mocha"
spec.add_development_dependency 'rack-test'
spec.add_development_dependency 'rspec'
spec.add_development_dependency 'simplecov'
spec.add_development_dependency 'webmock'
end
71 changes: 71 additions & 0 deletions spec/omniauth/strategies/discord_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
require 'spec_helper'

describe OmniAuth::Strategies::Discord do
let(:access_token) { instance_double('AccessToken', options: {}) }
let(:parsed_response) { instance_double('ParsedResponse') }
let(:response) { instance_double('Response', parsed: parsed_response) }

let(:enterprise_site) { 'https://some.other.site.com/api/v3' }
let(:enterprise_authorize_url) { 'https://some.other.site.com/login/oauth/authorize' }
let(:enterprise_token_url) { 'https://some.other.site.com/login/oauth/access_token' }
let(:enterprise) do
OmniAuth::Strategies::Discord.new('GITHUB_KEY', 'GITHUB_SECRET',
client_options: {
site: enterprise_site,
authorize_url: enterprise_authorize_url,
token_url: enterprise_token_url
})
end

subject do
OmniAuth::Strategies::Discord.new({})
end

before(:each) do
allow(subject).to receive(:access_token).and_return(access_token)
end

context 'client options' do
it 'should have correct site' do
expect(subject.options.client_options.site).to eq('https://discordapp.com/api')
end

it 'should have correct authorize url' do
expect(subject.options.client_options.authorize_url).to eq('oauth2/authorize')
end

it 'should have correct token url' do
expect(subject.options.client_options.token_url).to eq('oauth2/token')
end

describe 'should be overrideable' do
it 'for site' do
expect(enterprise.options.client_options.site).to eq(enterprise_site)
end

it 'for authorize url' do
expect(enterprise.options.client_options.authorize_url).to eq(enterprise_authorize_url)
end

it 'for token url' do
expect(enterprise.options.client_options.token_url).to eq(enterprise_token_url)
end
end
end

context '#raw_info' do
it 'should use relative paths' do
expect(access_token).to receive(:get).with('users/@me').and_return(response)
expect(subject.raw_info).to eq(parsed_response)
end
end

describe '#callback_url' do
it 'is a combination of host, script name, and callback path' do
allow(subject).to receive(:full_host).and_return('https://example.com')
allow(subject).to receive(:script_name).and_return('/sub_uri')

expect(subject.callback_url).to eq('https://example.com/sub_uri/auth/discord/callback')
end
end
end
15 changes: 15 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
$LOAD_PATH.unshift File.expand_path(__dir__)
$LOAD_PATH.unshift File.expand_path('../lib', __dir__)
require 'simplecov'
SimpleCov.start
require 'rspec'
require 'rack/test'
require 'webmock/rspec'
require 'omniauth'
require 'omniauth-discord'

RSpec.configure do |config|
config.include WebMock::API
config.include Rack::Test::Methods
config.extend OmniAuth::Test::StrategyMacros, type: :strategy
end
61 changes: 0 additions & 61 deletions test/helper.rb

This file was deleted.

20 changes: 0 additions & 20 deletions test/strategy_test.rb

This file was deleted.

85 changes: 0 additions & 85 deletions test/support/shared_examples.rb

This file was deleted.

0 comments on commit 129859a

Please sign in to comment.