|
| 1 | +require 'spec_helper' |
| 2 | + |
| 3 | +describe BitBucket::API do |
| 4 | + let(:setup_options) { { user: 'test_user' } } |
| 5 | + let(:bitbucket_api) { described_class.new(setup_options) } |
| 6 | + after do |
| 7 | + [:user, :login, :password].each do |key| |
| 8 | + bitbucket_api.send "clear_#{key}".to_sym |
| 9 | + end |
| 10 | + end |
| 11 | + |
| 12 | + describe '#new' do |
| 13 | + it 'passes options to bitbucket' do |
| 14 | + described_class.new(setup_options) |
| 15 | + |
| 16 | + expect(bitbucket_api.user).to eq(setup_options[:user]) |
| 17 | + end |
| 18 | + |
| 19 | + context 'valid options' do |
| 20 | + it 'sets valid options' do |
| 21 | + setup_options = { |
| 22 | + login: 'johnwick', |
| 23 | + password: 'password' |
| 24 | + } |
| 25 | + bitbucket_api = described_class.new(setup_options) |
| 26 | + |
| 27 | + expect(bitbucket_api.login).to eq('johnwick') |
| 28 | + expect(bitbucket_api.password).to eq('password') |
| 29 | + end |
| 30 | + |
| 31 | + it 'ignores invalid options' do |
| 32 | + setup_options = { |
| 33 | + invalid_option: 'invalid option' |
| 34 | + } |
| 35 | + |
| 36 | + bitbucket_api = described_class.new(setup_options) |
| 37 | + |
| 38 | + expect{ bitbucket_api.invalid_option }.to raise_error(NoMethodError) |
| 39 | + end |
| 40 | + end |
| 41 | + end |
| 42 | + |
| 43 | + describe '#method_missing' do |
| 44 | + let(:setup_options) { { user: 'test_user' } } |
| 45 | + |
| 46 | + it 'responds to attribute query' do |
| 47 | + expect(bitbucket_api.user?).to eq(true) |
| 48 | + end |
| 49 | + |
| 50 | + it 'clears the attributes' do |
| 51 | + bitbucket_api.clear_user |
| 52 | + |
| 53 | + expect(bitbucket_api.user).to be_nil |
| 54 | + end |
| 55 | + end |
| 56 | + |
| 57 | + describe '#_update_user_repo_params' do |
| 58 | + it 'sets the username and repo_name' do |
| 59 | + bitbucket_api._update_user_repo_params('test_user1', 'test_repo') |
| 60 | + |
| 61 | + expect(bitbucket_api.user).to eq('test_user1') |
| 62 | + expect(bitbucket_api.repo).to eq('test_repo') |
| 63 | + end |
| 64 | + end |
| 65 | + |
| 66 | + describe '#_merge_user_into_params!' do |
| 67 | + let(:params) { {} } |
| 68 | + |
| 69 | + it 'takes a hash and merges user into it' do |
| 70 | + bitbucket_api._merge_user_into_params!(params) |
| 71 | + |
| 72 | + expect(params).to include('user') |
| 73 | + end |
| 74 | + end |
| 75 | + |
| 76 | + describe '#_merge_user_repo_into_params!' do |
| 77 | + let(:params) { {} } |
| 78 | + |
| 79 | + it 'takes a hash and merges user into it' do |
| 80 | + new_params = bitbucket_api._merge_user_repo_into_params!(params) |
| 81 | + |
| 82 | + expect(new_params).to include('user') |
| 83 | + expect(new_params).to include('repo') |
| 84 | + end |
| 85 | + end |
| 86 | +end |
0 commit comments