forked from bitbucket-rest-api/bitbucket
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request bitbucket-rest-api#48 from dmgarland/master
RSpec additions
- Loading branch information
Showing
15 changed files
with
523 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,7 @@ log | |
*.sqlite3 | ||
features/settings.yml | ||
*.gem | ||
|
||
.tags | ||
TAGS | ||
.tags_sorted_by_file | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,3 @@ | ||
source "http://rubygems.org" | ||
|
||
gemspec | ||
|
||
group :development, :test do | ||
gem 'rb-fsevent', :require => false if RUBY_PLATFORM =~ /darwin/i | ||
gem 'growl', :require => false if RUBY_PLATFORM =~ /darwin/i | ||
gem 'growl_notify', :require => false if RUBY_PLATFORM =~ /darwin/i | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# encoding: utf-8 | ||
|
||
require 'spec_helper' | ||
|
||
describe BitBucket::ApiFactory do | ||
|
||
subject(:factory) { described_class } | ||
|
||
context '#new' do | ||
it 'throws error if klass type is ommitted' do | ||
expect { factory.new nil }.to raise_error(ArgumentError) | ||
end | ||
|
||
it 'instantiates a new object' do | ||
expect(factory.new('Issues')).to be_a BitBucket::Issues | ||
end | ||
end | ||
|
||
context '#create_instance' do | ||
it 'creates class instance' do | ||
expect(factory.create_instance('User', {})).to be_kind_of(BitBucket::User) | ||
end | ||
end | ||
|
||
context '#convert_to_constant' do | ||
it 'knows how to convert nested classes' do | ||
expect(factory.convert_to_constant('Repos::Changesets')).to eql(BitBucket::Repos::Changesets) | ||
end | ||
end | ||
end # BitBucket::ApiFactory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
require 'spec_helper' | ||
|
||
describe BitBucket::API do | ||
let(:setup_options) { { user: 'test_user' } } | ||
let(:bitbucket_api) { described_class.new(setup_options) } | ||
after do | ||
[:user, :login, :password].each do |key| | ||
bitbucket_api.send "clear_#{key}".to_sym | ||
end | ||
end | ||
|
||
describe '#new' do | ||
it 'passes options to bitbucket' do | ||
described_class.new(setup_options) | ||
|
||
expect(bitbucket_api.user).to eq(setup_options[:user]) | ||
end | ||
|
||
context 'valid options' do | ||
it 'sets valid options' do | ||
setup_options = { | ||
login: 'johnwick', | ||
password: 'password' | ||
} | ||
bitbucket_api = described_class.new(setup_options) | ||
|
||
expect(bitbucket_api.login).to eq('johnwick') | ||
expect(bitbucket_api.password).to eq('password') | ||
end | ||
|
||
it 'ignores invalid options' do | ||
setup_options = { | ||
invalid_option: 'invalid option' | ||
} | ||
|
||
bitbucket_api = described_class.new(setup_options) | ||
|
||
expect{ bitbucket_api.invalid_option }.to raise_error(NoMethodError) | ||
end | ||
end | ||
end | ||
|
||
describe '#method_missing' do | ||
let(:setup_options) { { user: 'test_user' } } | ||
|
||
it 'responds to attribute query' do | ||
expect(bitbucket_api.user?).to eq(true) | ||
end | ||
|
||
it 'clears the attributes' do | ||
bitbucket_api.clear_user | ||
|
||
expect(bitbucket_api.user).to be_nil | ||
end | ||
end | ||
|
||
describe '#_update_user_repo_params' do | ||
it 'sets the username and repo_name' do | ||
bitbucket_api._update_user_repo_params('test_user1', 'test_repo') | ||
|
||
expect(bitbucket_api.user).to eq('test_user1') | ||
expect(bitbucket_api.repo).to eq('test_repo') | ||
end | ||
end | ||
|
||
describe '#_merge_user_into_params!' do | ||
let(:params) { {} } | ||
|
||
it 'takes a hash and merges user into it' do | ||
bitbucket_api._merge_user_into_params!(params) | ||
|
||
expect(params).to include('user') | ||
end | ||
end | ||
|
||
describe '#_merge_user_repo_into_params!' do | ||
let(:params) { {} } | ||
|
||
it 'takes a hash and merges user into it' do | ||
new_params = bitbucket_api._merge_user_repo_into_params!(params) | ||
|
||
expect(new_params).to include('user') | ||
expect(new_params).to include('repo') | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
require 'spec_helper' | ||
|
||
describe BitBucket::Authorization do | ||
let(:oauth_api) { BitBucket::API.new(oauth_token: 'example_oauth_token') } | ||
let(:basic_auth_api) { BitBucket::API.new(basic_auth: 'example_login:example_password') } | ||
let(:login_and_password_api) do | ||
BitBucket::API.new( | ||
login: 'example_login', | ||
password: 'example_password', | ||
basic_auth: nil | ||
) | ||
end | ||
|
||
describe '#authenticated?' do | ||
context 'context: oauth authentication' do | ||
it 'should return true of oauth is used' do | ||
expect(oauth_api.authenticated?).to eq(true) | ||
end | ||
end | ||
|
||
context 'context: basic authentication' do | ||
it 'should return true if basic authentication is used' do | ||
expect(basic_auth_api.authenticated?).to eq(true) | ||
end | ||
end | ||
end | ||
|
||
describe '#basic_authed?' do | ||
context 'context: with basic_auth' do | ||
it 'should return true if basic_auth is set' do | ||
expect(basic_auth_api.basic_authed?).to eq(true) | ||
end | ||
end | ||
|
||
context 'context: with login and password' do | ||
it 'should return true if a login and password are set' do | ||
expect(login_and_password_api.basic_authed?).to eq(true) | ||
end | ||
end | ||
end | ||
|
||
describe '#authentication' do | ||
context 'context: with basic_auth' do | ||
it 'should return a hash containing the value for :basic_auth' do | ||
expectation = { basic_auth: 'example_login:example_password' } | ||
|
||
expect(basic_auth_api.authentication).to eq(expectation) | ||
end | ||
end | ||
|
||
context 'context: with login and password' do | ||
it 'should return a hash containing values for :login and :password' do | ||
expectation = { login: 'example_login', password: 'example_password' } | ||
|
||
expect(login_and_password_api.authentication).to eq(expectation) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require 'spec_helper' | ||
require 'bitbucket_rest_api/core_ext/array' | ||
|
||
describe Array do | ||
let(:array) { [:a, :b, :c, :d, { key: :value }] } | ||
describe '#except' do | ||
it 'removes the keys' do | ||
new_array = array.except(:a, :b) | ||
|
||
expect(new_array).to_not include(:a) | ||
expect(new_array).to_not include(:b) | ||
end | ||
end | ||
|
||
describe '#except!' do | ||
xit 'removes the keys from the self' do | ||
array = [:a, :b, :c, :d] | ||
array.except!(:a, :b) | ||
|
||
expect(array).to_not include(:a) | ||
expect(array).to_not include(:b) | ||
end | ||
end | ||
|
||
describe '#extract_options!' do | ||
it 'selects a hash from the arguments list' do | ||
expect(array.extract_options!).to eq({ key: :value }) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# encoding: utf-8 | ||
|
||
require 'spec_helper' | ||
|
||
describe Hash do | ||
|
||
before do | ||
BitBucket.new | ||
@hash = { :a => 1, :b => 2, :c => 'e'} | ||
@serialized = "a=1&b=2&c=e" | ||
@nested_hash = { 'a' => { 'b' => {'c' => 1 } } } | ||
@symbols = { :a => { :b => { :c => 1 } } } | ||
end | ||
|
||
context '#except!' do | ||
# TODO fix this test after fixing except! | ||
xit 'should respond to except!' do | ||
@nested_hash.should respond_to :except! | ||
copy = @nested_hash.dup | ||
copy.except!('b', 'a') | ||
copy.should be_empty | ||
end | ||
end | ||
|
||
context '#except' do | ||
it 'should respond to except' do | ||
@nested_hash.should respond_to :except | ||
end | ||
|
||
# TODO fix this test after fixing except! | ||
xit 'should remove key from the hash' do | ||
@nested_hash.except('a').should be_empty | ||
end | ||
end | ||
|
||
context '#symbolize_keys' do | ||
it 'should respond to symbolize_keys' do | ||
@nested_hash.should respond_to :symbolize_keys | ||
end | ||
end | ||
|
||
context '#symbolize_keys!' do | ||
it 'should respond to symbolize_keys!' do | ||
@nested_hash.should respond_to :symbolize_keys! | ||
end | ||
|
||
it 'should convert nested keys to symbols' do | ||
@nested_hash.symbolize_keys!.should == @symbols | ||
end | ||
end | ||
|
||
context '#serialize' do | ||
it 'should respond to serialize' do | ||
@nested_hash.should respond_to :serialize | ||
end | ||
|
||
it 'should serialize hash' do | ||
@hash.serialize.should == @serialized | ||
end | ||
end | ||
|
||
context '#deep_key?' do | ||
it 'should find key inside nested hash' do | ||
@nested_hash.has_deep_key?('c').should be_truthy | ||
end | ||
end | ||
end # Hash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# encoding: utf-8 | ||
|
||
require 'spec_helper' | ||
require 'bitbucket_rest_api/core_ext/hash' | ||
|
||
describe BitBucket::Normalizer, '#normalize!' do | ||
let(:hash) { { 'a' => { :b => { 'c' => 1 }, 'd' => ['a', { :e => 2 }] } } } | ||
|
||
let(:klass) do | ||
Class.new do | ||
include BitBucket::Normalizer | ||
end | ||
end | ||
|
||
subject(:instance) { klass.new } | ||
|
||
context '#normalize!' do | ||
it 'converts hash keys to string' do | ||
['a', 'b', 'c'].each do |key| | ||
expect(subject.normalize!(hash).has_deep_key?(key)).to eq(true) | ||
end | ||
end | ||
|
||
it 'should stringify all the keys inside nested hash' do | ||
actual = subject.normalize! hash | ||
expected = { 'a' => { 'b'=> { 'c' => 1 }, 'd' => ['a', { 'e'=> 2 }] } } | ||
actual.should be_eql expected | ||
end | ||
end | ||
end # BitBucket::Normalizer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
require 'spec_helper' | ||
require 'bitbucket_rest_api/core_ext/hash' | ||
|
||
describe BitBucket::ParameterFilter, '#filter!' do | ||
let(:hash) { { :a => { :b => { :c => 1 } } } } | ||
|
||
let(:klass) { | ||
Class.new do | ||
include BitBucket::ParameterFilter | ||
end | ||
} | ||
|
||
subject(:instance) { klass.new } | ||
|
||
it 'removes unwanted keys from hash' do | ||
instance.filter!([:a], hash) | ||
expect(hash.has_deep_key?(:a)).to eq(true) | ||
expect(hash.has_deep_key?(:b)).to eq(false) | ||
expect(hash.has_deep_key?(:c)).to eq(false) | ||
end | ||
|
||
it 'recursively filters inputs tree' do | ||
instance.filter!([:a, :b], hash) | ||
expect(hash.has_deep_key?(:c)).to eq(false) | ||
end | ||
|
||
it 'filters inputs tree only on top level' do | ||
instance.filter!([:a, :b], hash, :recursive => false) | ||
expect(hash.has_deep_key?(:c)).to eq(true) | ||
end | ||
end |
Oops, something went wrong.