bitbuckets 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +7 -0
  3. data/README.md +169 -0
  4. data/Rakefile +1 -0
  5. data/lib/bitbucket_rest_api.rb +86 -0
  6. data/lib/bitbucket_rest_api/api.rb +104 -0
  7. data/lib/bitbucket_rest_api/api/actions.rb +32 -0
  8. data/lib/bitbucket_rest_api/api_factory.rb +29 -0
  9. data/lib/bitbucket_rest_api/authorization.rb +31 -0
  10. data/lib/bitbucket_rest_api/client.rb +53 -0
  11. data/lib/bitbucket_rest_api/configuration.rb +103 -0
  12. data/lib/bitbucket_rest_api/connection.rb +97 -0
  13. data/lib/bitbucket_rest_api/constants.rb +57 -0
  14. data/lib/bitbucket_rest_api/core_ext/array.rb +6 -0
  15. data/lib/bitbucket_rest_api/core_ext/hash.rb +58 -0
  16. data/lib/bitbucket_rest_api/deprecation.rb +36 -0
  17. data/lib/bitbucket_rest_api/error.rb +37 -0
  18. data/lib/bitbucket_rest_api/error/bad_events.rb +10 -0
  19. data/lib/bitbucket_rest_api/error/bad_request.rb +11 -0
  20. data/lib/bitbucket_rest_api/error/blank_value.rb +10 -0
  21. data/lib/bitbucket_rest_api/error/client_error.rb +19 -0
  22. data/lib/bitbucket_rest_api/error/forbidden.rb +11 -0
  23. data/lib/bitbucket_rest_api/error/internal_server_error.rb +11 -0
  24. data/lib/bitbucket_rest_api/error/invalid_options.rb +17 -0
  25. data/lib/bitbucket_rest_api/error/no_events.rb +10 -0
  26. data/lib/bitbucket_rest_api/error/not_found.rb +11 -0
  27. data/lib/bitbucket_rest_api/error/required_params.rb +17 -0
  28. data/lib/bitbucket_rest_api/error/service_error.rb +18 -0
  29. data/lib/bitbucket_rest_api/error/service_unavailable.rb +11 -0
  30. data/lib/bitbucket_rest_api/error/unauthorized.rb +11 -0
  31. data/lib/bitbucket_rest_api/error/unknown_value.rb +17 -0
  32. data/lib/bitbucket_rest_api/error/unprocessable_entity.rb +11 -0
  33. data/lib/bitbucket_rest_api/error/validations.rb +17 -0
  34. data/lib/bitbucket_rest_api/invitations.rb +14 -0
  35. data/lib/bitbucket_rest_api/issues.rb +229 -0
  36. data/lib/bitbucket_rest_api/issues/comments.rb +116 -0
  37. data/lib/bitbucket_rest_api/issues/components.rb +105 -0
  38. data/lib/bitbucket_rest_api/issues/milestones.rb +105 -0
  39. data/lib/bitbucket_rest_api/normalizer.rb +24 -0
  40. data/lib/bitbucket_rest_api/parameter_filter.rb +29 -0
  41. data/lib/bitbucket_rest_api/repos.rb +276 -0
  42. data/lib/bitbucket_rest_api/repos/changesets.rb +52 -0
  43. data/lib/bitbucket_rest_api/repos/commits.rb +38 -0
  44. data/lib/bitbucket_rest_api/repos/components.rb +35 -0
  45. data/lib/bitbucket_rest_api/repos/default_reviewers.rb +60 -0
  46. data/lib/bitbucket_rest_api/repos/download.rb +15 -0
  47. data/lib/bitbucket_rest_api/repos/following.rb +38 -0
  48. data/lib/bitbucket_rest_api/repos/forks.rb +66 -0
  49. data/lib/bitbucket_rest_api/repos/keys.rb +86 -0
  50. data/lib/bitbucket_rest_api/repos/pull_request.rb +158 -0
  51. data/lib/bitbucket_rest_api/repos/services.rb +101 -0
  52. data/lib/bitbucket_rest_api/repos/sources.rb +36 -0
  53. data/lib/bitbucket_rest_api/repos/webhooks.rb +99 -0
  54. data/lib/bitbucket_rest_api/request.rb +71 -0
  55. data/lib/bitbucket_rest_api/request/basic_auth.rb +30 -0
  56. data/lib/bitbucket_rest_api/request/jsonize.rb +39 -0
  57. data/lib/bitbucket_rest_api/request/oauth.rb +50 -0
  58. data/lib/bitbucket_rest_api/response.rb +26 -0
  59. data/lib/bitbucket_rest_api/response/helpers.rb +18 -0
  60. data/lib/bitbucket_rest_api/response/jsonize.rb +25 -0
  61. data/lib/bitbucket_rest_api/response/mashify.rb +23 -0
  62. data/lib/bitbucket_rest_api/response/raise_error.rb +28 -0
  63. data/lib/bitbucket_rest_api/response/xmlize.rb +25 -0
  64. data/lib/bitbucket_rest_api/result.rb +136 -0
  65. data/lib/bitbucket_rest_api/teams.rb +91 -0
  66. data/lib/bitbucket_rest_api/user.rb +87 -0
  67. data/lib/bitbucket_rest_api/users.rb +20 -0
  68. data/lib/bitbucket_rest_api/users/account.rb +50 -0
  69. data/lib/bitbucket_rest_api/utils/url.rb +61 -0
  70. data/lib/bitbucket_rest_api/validations.rb +23 -0
  71. data/lib/bitbucket_rest_api/validations/format.rb +21 -0
  72. data/lib/bitbucket_rest_api/validations/presence.rb +21 -0
  73. data/lib/bitbucket_rest_api/validations/required.rb +37 -0
  74. data/lib/bitbucket_rest_api/validations/token.rb +38 -0
  75. data/lib/bitbucket_rest_api/version.rb +10 -0
  76. data/lib/bitbuckets.rb +2 -0
  77. data/spec/bitbucket_rest_api/api/actions_spec.rb +18 -0
  78. data/spec/bitbucket_rest_api/api_factory_spec.rb +28 -0
  79. data/spec/bitbucket_rest_api/api_spec.rb +87 -0
  80. data/spec/bitbucket_rest_api/authorization_spec.rb +74 -0
  81. data/spec/bitbucket_rest_api/client_spec.rb +17 -0
  82. data/spec/bitbucket_rest_api/core_ext/array_spec.rb +13 -0
  83. data/spec/bitbucket_rest_api/core_ext/hash_spec.rb +47 -0
  84. data/spec/bitbucket_rest_api/deprecation_spec.rb +31 -0
  85. data/spec/bitbucket_rest_api/error/bad_events_spec.rb +11 -0
  86. data/spec/bitbucket_rest_api/error/blank_value_spec.rb +14 -0
  87. data/spec/bitbucket_rest_api/error/no_events_spec.rb +11 -0
  88. data/spec/bitbucket_rest_api/invitations_spec.rb +21 -0
  89. data/spec/bitbucket_rest_api/issues/comments_spec.rb +89 -0
  90. data/spec/bitbucket_rest_api/issues/components_spec.rb +89 -0
  91. data/spec/bitbucket_rest_api/issues/milestones_spec.rb +89 -0
  92. data/spec/bitbucket_rest_api/issues_spec.rb +91 -0
  93. data/spec/bitbucket_rest_api/normalizer_spec.rb +29 -0
  94. data/spec/bitbucket_rest_api/parameter_filter_spec.rb +42 -0
  95. data/spec/bitbucket_rest_api/repos/changesets_spec.rb +44 -0
  96. data/spec/bitbucket_rest_api/repos/commits_spec.rb +21 -0
  97. data/spec/bitbucket_rest_api/repos/components_spec.rb +43 -0
  98. data/spec/bitbucket_rest_api/repos/default_reviewers_spec.rb +65 -0
  99. data/spec/bitbucket_rest_api/repos/download_spec.rb +10 -0
  100. data/spec/bitbucket_rest_api/repos/following_spec.rb +53 -0
  101. data/spec/bitbucket_rest_api/repos/forks_spec.rb +46 -0
  102. data/spec/bitbucket_rest_api/repos/keys_spec.rb +73 -0
  103. data/spec/bitbucket_rest_api/repos/pull_request_spec.rb +283 -0
  104. data/spec/bitbucket_rest_api/repos/sources_spec.rb +78 -0
  105. data/spec/bitbucket_rest_api/repos/webhooks_spec.rb +245 -0
  106. data/spec/bitbucket_rest_api/repos_spec.rb +158 -0
  107. data/spec/bitbucket_rest_api/request/jsonize_spec.rb +19 -0
  108. data/spec/bitbucket_rest_api/request/oauth_spec.rb +26 -0
  109. data/spec/bitbucket_rest_api/request_spec.rb +88 -0
  110. data/spec/bitbucket_rest_api/response/jsonize_spec.rb +13 -0
  111. data/spec/bitbucket_rest_api/response/mashify_spec.rb +33 -0
  112. data/spec/bitbucket_rest_api/response/raise_error_spec.rb +42 -0
  113. data/spec/bitbucket_rest_api/teams_spec.rb +136 -0
  114. data/spec/bitbucket_rest_api/user_spec.rb +78 -0
  115. data/spec/bitbucket_rest_api/utils/url_spec.rb +34 -0
  116. data/spec/bitbucket_rest_api/validations/format_spec.rb +30 -0
  117. data/spec/bitbucket_rest_api/validations/presence_spec.rb +13 -0
  118. data/spec/bitbucket_rest_api/validations/required_spec.rb +44 -0
  119. data/spec/bitbucket_rest_api/validations/token_spec.rb +17 -0
  120. data/spec/bitbucket_rest_api_spec.rb +17 -0
  121. data/spec/spec_helper.rb +24 -0
  122. metadata +358 -0
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+ module BitBucket
3
+ class Users::Account < API
4
+ # API about users/account , please refer to
5
+ # https://confluence.atlassian.com/display/BITBUCKET/account+Resource
6
+ #
7
+
8
+ # GET the account profile
9
+ #
10
+ def profile(accountname)
11
+ response = get_request("/1.0/users/#{accountname}")
12
+ end
13
+
14
+ # GET the account plan
15
+ def plan(accountname)
16
+ response = get_request("/1.0/users/#{accountname}/plan")
17
+ end
18
+
19
+ # GET the emails
20
+ def emails(accountname)
21
+ response = get_request("/1.0/users/#{accountname}/emails")
22
+ end
23
+
24
+ # GET the followers
25
+ def followers(accountname)
26
+ response = get_request("/1.0/users/#{accountname}/followers")
27
+ end
28
+
29
+ # GET the events
30
+ def events(accountname)
31
+ response = get_request("/1.0/users/#{accountname}/events")
32
+ end
33
+
34
+ # GET the keys
35
+ def keys(accountname)
36
+ response = get_request("/1.0/users/#{accountname}/ssh-keys")
37
+ end
38
+
39
+ # POST a new key
40
+ # params should be in format {key: "", label:""}
41
+ def new_key(accountname, params)
42
+ response = post_request("/1.0/users/#{accountname}/ssh-keys/", params)
43
+ end
44
+
45
+ # DELETE a key
46
+ def delete_key(accountname, key_id)
47
+ response = delete_request("/1.0/users/#{accountname}/ssh-keys/#{key_id}")
48
+ end
49
+ end # Users::Account
50
+ end # BitBucket
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+ require 'cgi'
3
+
4
+ module BitBucket
5
+ module Utils
6
+ module Url
7
+ module_function
8
+
9
+ DEFAULT_QUERY_SEP = /[&;] */n.freeze
10
+
11
+ KEY_VALUE_SEP = '='
12
+
13
+ def escape(s)
14
+ CGI.escape s.to_s
15
+ end
16
+
17
+ def unescape(s)
18
+ CGI.unescape s.to_s
19
+ end
20
+
21
+ def build_query(params)
22
+ params.map do |k, v|
23
+ if v.class == Array
24
+ build_query(v.map { |x| [k, x] })
25
+ else
26
+ v.nil? ? escape(k) : "#{escape(k)}=#{escape(v)}"
27
+ end
28
+ end.join('&')
29
+ end
30
+
31
+ def parse_query(query_string)
32
+ return '' if query_string.nil? || query_string.empty?
33
+
34
+ params = {}
35
+
36
+ query_string.split(DEFAULT_QUERY_SEP).each do |part|
37
+ k, v = part.split(KEY_VALUE_SEP, 2).map { |el| unescape(el) }
38
+
39
+ if cur = params[k]
40
+ if cur.class == Array
41
+ params[k] << v
42
+ else
43
+ params[k] = [cur, v]
44
+ end
45
+ else
46
+ params[k] = v
47
+ end
48
+ end
49
+ params
50
+ end
51
+
52
+ def parse_query_for_param(query_string, name)
53
+ parse_query(query_string).each do |key, val|
54
+ return val.first if (name == key) && val.is_a?(Array)
55
+ return val if name == key
56
+ end
57
+ nil
58
+ end
59
+ end # Url
60
+ end # Utils
61
+ end # BitBucket
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+ module BitBucket
3
+ module Validations
4
+ extend AutoloadHelper
5
+
6
+ autoload_all 'bitbucket_rest_api/validations',
7
+ Presence: 'presence',
8
+ Token: 'token',
9
+ Format: 'format',
10
+ Required: 'required'
11
+
12
+ include Presence
13
+ include Format
14
+ include Token
15
+ include Required
16
+
17
+ VALID_API_KEYS = %w[
18
+ page
19
+ per_page
20
+ jsonp_callback
21
+ ].freeze
22
+ end # Validation
23
+ end # BitBucket
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+ module BitBucket
3
+ module Validations
4
+ module Format
5
+ # Ensures that value for a given key is of the correct form whether
6
+ # matching regular expression or set of predefined values.
7
+ #
8
+ def assert_valid_values(permitted, params)
9
+ params.each do |k, v|
10
+ next unless permitted.keys.include?(k)
11
+ if permitted[k].is_a?(Array) && !permitted[k].include?(params[k])
12
+ raise BitBucket::Error::UnknownValue.new(k, v, permitted[k].join(', '))
13
+
14
+ elsif permitted[k].is_a?(Regexp) && permitted[k] !~ params[k]
15
+ raise BitBucket::Error::UnknownValue.new(k, v, permitted[k])
16
+ end
17
+ end
18
+ end
19
+ end # Format
20
+ end # Validations
21
+ end # BitBucket
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+ module BitBucket
3
+ module Validations
4
+ module Presence
5
+ # Ensures that essential arguments are present before request is made
6
+ #
7
+ def _validate_presence_of(*params)
8
+ params.each do |param|
9
+ raise ArgumentError, 'parameter cannot be nil' if param.nil?
10
+ end
11
+ end
12
+
13
+ # Check if user or repository parameters are passed
14
+ #
15
+ def _validate_user_repo_params(user_name, repo_name)
16
+ raise ArgumentError, '[user] parameter cannot be nil' if user_name.nil?
17
+ raise ArgumentError, '[repo] parameter cannot be nil' if repo_name.nil?
18
+ end
19
+ end # Presence
20
+ end # Validations
21
+ end # BitBucket
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+ module BitBucket
3
+ module Validations
4
+ module Required
5
+ # Validate all keys present in a provided hash against required set,
6
+ # on mismatch raise BitBucket::Error::RequiredParams
7
+ # Note that keys need to be in the same format i.e. symbols or strings,
8
+ # otherwise the comparison will fail.
9
+ #
10
+ def assert_required_keys(required, provided)
11
+ result = required.all? do |key|
12
+ provided.has_deep_key? key
13
+ end
14
+ raise BitBucket::Error::RequiredParams.new(provided, required) unless result
15
+
16
+ result
17
+ end
18
+
19
+ # Validate that required values are not blank
20
+ # the *required are colon separated strings
21
+ # e.g. 'source:branch:name' tests value of params[:source][:branch][:name]
22
+ #
23
+ def assert_required_values_present(params, *required)
24
+ required.each do |encoded_string|
25
+ keys = parse_values(encoded_string)
26
+ value = keys.inject(params) { |params, key| params[key] }
27
+ next unless value.is_a?(String)
28
+ raise BitBucket::Error::BlankValue, encoded_string if value.empty?
29
+ end
30
+ end
31
+
32
+ def parse_values(string)
33
+ string.split(':')
34
+ end
35
+ end # Required
36
+ end # Validations
37
+ end # BitBucket
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+ # TODO: Set token required calls
3
+
4
+ module BitBucket
5
+ module Validations
6
+ module Token
7
+ TOKEN_REQUIRED = [
8
+ 'get /user',
9
+ 'get /user/emails',
10
+ 'get /user/followers',
11
+ 'get /user/following',
12
+ 'get /user/keys',
13
+ 'get /user/repos',
14
+ 'patch /user',
15
+ 'post /user/emails',
16
+ 'post /user/keys',
17
+ 'post /user/repos'
18
+ ].freeze
19
+
20
+ TOKEN_REQUIRED_REGEXP = [
21
+ %r{repos/.*/.*/comments}
22
+ ].freeze
23
+
24
+ # Ensures that required authentication token is present before
25
+ # request is sent.
26
+ #
27
+ def validates_token_for(method, path)
28
+ return true unless TOKEN_REQUIRED.grep("#{method} #{path}").empty?
29
+
30
+ token_required = false
31
+ TOKEN_REQUIRED_REGEXP.each do |regex|
32
+ token_required = true if "#{method} #{path}" =~ regex
33
+ end
34
+ token_required
35
+ end
36
+ end # Token
37
+ end # Validations
38
+ end # BitBucket
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+ module BitBucket
3
+ module VERSION
4
+ MAJOR = 0
5
+ MINOR = 2
6
+ PATCH = 0
7
+
8
+ STRING = [MAJOR, MINOR, PATCH].compact.join('.')
9
+ end
10
+ end # BitBucket
@@ -0,0 +1,2 @@
1
+ # frozen_string_literal: true
2
+ require_relative 'bitbucket_rest_api'
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+
4
+ describe BitBucket::API, '#actions' do
5
+ let(:api) { BitBucket::Repos::Keys }
6
+
7
+ context 'when class' do
8
+ it 'lists all available actions for an api' do
9
+ expect(api.actions).to match_array(%i[actions all create delete edit list])
10
+ end
11
+ end
12
+
13
+ context 'when instance' do
14
+ it 'lists all available actions for an api' do
15
+ expect(api.new.actions).to match_array(%i[actions all create delete edit list])
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+
4
+ describe BitBucket::ApiFactory do
5
+ subject(:factory) { described_class }
6
+
7
+ context '#new' do
8
+ it 'throws error if klass type is ommitted' do
9
+ expect { factory.new nil }.to raise_error(ArgumentError)
10
+ end
11
+
12
+ it 'instantiates a new object' do
13
+ expect(factory.new('Issues')).to be_a BitBucket::Issues
14
+ end
15
+ end
16
+
17
+ context '#create_instance' do
18
+ it 'creates class instance' do
19
+ expect(factory.create_instance('User', {})).to be_kind_of(BitBucket::User)
20
+ end
21
+ end
22
+
23
+ context '#convert_to_constant' do
24
+ it 'knows how to convert nested classes' do
25
+ expect(factory.convert_to_constant('Repos::Changesets')).to eql(BitBucket::Repos::Changesets)
26
+ end
27
+ end
28
+ end # BitBucket::ApiFactory
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+
4
+ describe BitBucket::API do
5
+ let(:setup_options) { { user: 'test_user' } }
6
+ let(:bitbucket_api) { described_class.new(setup_options) }
7
+ after do
8
+ %i[user login password].each do |key|
9
+ bitbucket_api.send "clear_#{key}".to_sym
10
+ end
11
+ end
12
+
13
+ describe '#new' do
14
+ it 'passes options to bitbucket' do
15
+ described_class.new(setup_options)
16
+
17
+ expect(bitbucket_api.user).to eq(setup_options[:user])
18
+ end
19
+
20
+ context 'valid options' do
21
+ it 'sets valid options' do
22
+ setup_options = {
23
+ login: 'johnwick',
24
+ password: 'password'
25
+ }
26
+ bitbucket_api = described_class.new(setup_options)
27
+
28
+ expect(bitbucket_api.login).to eq('johnwick')
29
+ expect(bitbucket_api.password).to eq('password')
30
+ end
31
+
32
+ it 'ignores invalid options' do
33
+ setup_options = {
34
+ invalid_option: 'invalid option'
35
+ }
36
+
37
+ bitbucket_api = described_class.new(setup_options)
38
+
39
+ expect { bitbucket_api.invalid_option }.to raise_error(NoMethodError)
40
+ end
41
+ end
42
+ end
43
+
44
+ describe '#method_missing' do
45
+ let(:setup_options) { { user: 'test_user' } }
46
+
47
+ it 'responds to attribute query' do
48
+ expect(bitbucket_api.user?).to eq(true)
49
+ end
50
+
51
+ it 'clears the attributes' do
52
+ bitbucket_api.clear_user
53
+
54
+ expect(bitbucket_api.user).to be_nil
55
+ end
56
+ end
57
+
58
+ describe '#_update_user_repo_params' do
59
+ it 'sets the username and repo_name' do
60
+ bitbucket_api._update_user_repo_params('test_user1', 'test_repo')
61
+
62
+ expect(bitbucket_api.user).to eq('test_user1')
63
+ expect(bitbucket_api.repo).to eq('test_repo')
64
+ end
65
+ end
66
+
67
+ describe '#_merge_user_into_params!' do
68
+ let(:params) { {} }
69
+
70
+ it 'takes a hash and merges user into it' do
71
+ bitbucket_api._merge_user_into_params!(params)
72
+
73
+ expect(params).to include('user')
74
+ end
75
+ end
76
+
77
+ describe '#_merge_user_repo_into_params!' do
78
+ let(:params) { {} }
79
+
80
+ it 'takes a hash and merges user into it' do
81
+ new_params = bitbucket_api._merge_user_repo_into_params!(params)
82
+
83
+ expect(new_params).to include('user')
84
+ expect(new_params).to include('repo')
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+
4
+ describe BitBucket::Authorization do
5
+ let(:oauth_api) { BitBucket::API.new(oauth_token: 'example_oauth_token') }
6
+ let(:basic_auth_api) { BitBucket::API.new(basic_auth: 'example_login:example_password') }
7
+ let(:basic_auth_api_hash) do
8
+ BitBucket::API.new(
9
+ basic_auth: { login: 'example_login', password: 'example_password' }
10
+ )
11
+ end
12
+ let(:login_and_password_api) do
13
+ BitBucket::API.new(
14
+ login: 'example_login',
15
+ password: 'example_password',
16
+ basic_auth: nil
17
+ )
18
+ end
19
+
20
+ describe '#authenticated?' do
21
+ context 'oauth authentication' do
22
+ it 'should return true if oauth is used' do
23
+ expect(oauth_api.authenticated?).to eq(true)
24
+ end
25
+ end
26
+
27
+ context 'basic authentication' do
28
+ it 'should return true if basic authentication is used' do
29
+ expect(basic_auth_api.authenticated?).to eq(true)
30
+ end
31
+ end
32
+ end
33
+
34
+ describe '#basic_authed?' do
35
+ context 'with basic_auth' do
36
+ it 'should return true if basic_auth is set' do
37
+ expect(basic_auth_api.basic_authed?).to eq(true)
38
+ expect(basic_auth_api_hash.basic_authed?).to eq(true)
39
+ end
40
+ end
41
+
42
+ context 'with login and password' do
43
+ it 'should return true if a login and password are set' do
44
+ expect(login_and_password_api.basic_authed?).to eq(true)
45
+ end
46
+ end
47
+ end
48
+
49
+ describe '#authentication' do
50
+ context 'with basic_auth as a string' do
51
+ it 'should return a hash containing the value for :basic_auth' do
52
+ expectation = { basic_auth: 'example_login:example_password' }
53
+
54
+ expect(basic_auth_api.authentication).to eq(expectation)
55
+ end
56
+ end
57
+
58
+ context 'with basic_auth as a hash' do
59
+ it 'should return a hash containing the value for :basic_auth' do
60
+ expectation = { basic_auth: { login: 'example_login', password: 'example_password' } }
61
+
62
+ expect(basic_auth_api_hash.authentication).to eq(expectation)
63
+ end
64
+ end
65
+
66
+ context 'with login and password' do
67
+ it 'should return a hash containing values for :login and :password' do
68
+ expectation = { login: 'example_login', password: 'example_password' }
69
+
70
+ expect(login_and_password_api.authentication).to eq(expectation)
71
+ end
72
+ end
73
+ end
74
+ end