From 05296323a84357e2e97e783d2817d1608e111f77 Mon Sep 17 00:00:00 2001 From: Dan Garland Date: Mon, 7 Mar 2016 16:05:21 +0000 Subject: [PATCH 1/4] Ignoring CTag plugin files --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 2ff3096..68ad383 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,5 @@ log *.sqlite3 features/settings.yml *.gem - +.tags +.tags_sorted_by_file \ No newline at end of file From 01e3beb9669de8d6b3a19b7acd330d158ed03169 Mon Sep 17 00:00:00 2001 From: Dan Garland Date: Mon, 7 Mar 2016 16:11:10 +0000 Subject: [PATCH 2/4] Removing Cucumber and Guard --- Gemfile | 6 ------ bitbucket_rest_api.gemspec | 4 ---- 2 files changed, 10 deletions(-) diff --git a/Gemfile b/Gemfile index d9f3811..c80ee36 100644 --- a/Gemfile +++ b/Gemfile @@ -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 diff --git a/bitbucket_rest_api.gemspec b/bitbucket_rest_api.gemspec index 8346bf7..acc8978 100644 --- a/bitbucket_rest_api.gemspec +++ b/bitbucket_rest_api.gemspec @@ -22,13 +22,9 @@ Gem::Specification.new do |gem| gem.add_dependency 'simple_oauth' gem.add_development_dependency 'rspec', '>= 0' - gem.add_development_dependency 'cucumber', '>= 0' gem.add_development_dependency 'webmock', '~> 1.8.0' gem.add_development_dependency 'vcr', '~> 2.2.0' gem.add_development_dependency 'simplecov', '~> 0.6.1' - gem.add_development_dependency 'guard' - gem.add_development_dependency 'guard-rspec' - gem.add_development_dependency 'guard-cucumber' gem.add_development_dependency 'rake' gem.add_development_dependency 'bundler' end From 8d37d637b27c86d6c82cbb3e2fcbafb344798943 Mon Sep 17 00:00:00 2001 From: Dan Garland Date: Mon, 7 Mar 2016 16:12:06 +0000 Subject: [PATCH 3/4] Installing RSpec and SimpleCov --- .gitignore | 3 +- spec/spec_helper.rb | 101 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 spec/spec_helper.rb diff --git a/.gitignore b/.gitignore index 68ad383..ec9becf 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,5 @@ log features/settings.yml *.gem .tags -.tags_sorted_by_file \ No newline at end of file +.tags_sorted_by_file +coverage diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..cb43c65 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,101 @@ +require 'simplecov' +SimpleCov.start + +require 'bitbucket_rest_api' + +# This file was generated by the `rspec --init` command. Conventionally, all +# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. +# The generated `.rspec` file contains `--require spec_helper` which will cause +# this file to always be loaded, without a need to explicitly require it in any +# files. +# +# Given that it is always loaded, you are encouraged to keep this file as +# light-weight as possible. Requiring heavyweight dependencies from this file +# will add to the boot time of your test suite on EVERY test run, even for an +# individual file that may not need all of that loaded. Instead, consider making +# a separate helper file that requires the additional dependencies and performs +# the additional setup, and require it from the spec files that actually need +# it. +# +# The `.rspec` file also contains a few flags that are not defaults but that +# users commonly want. +# +# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration +RSpec.configure do |config| + # rspec-expectations config goes here. You can use an alternate + # assertion/expectation library such as wrong or the stdlib/minitest + # assertions if you prefer. + config.expect_with :rspec do |expectations| + # This option will default to `true` in RSpec 4. It makes the `description` + # and `failure_message` of custom matchers include text for helper methods + # defined using `chain`, e.g.: + # be_bigger_than(2).and_smaller_than(4).description + # # => "be bigger than 2 and smaller than 4" + # ...rather than: + # # => "be bigger than 2" + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + end + + # rspec-mocks config goes here. You can use an alternate test double + # library (such as bogus or mocha) by changing the `mock_with` option here. + config.mock_with :rspec do |mocks| + # Prevents you from mocking or stubbing a method that does not exist on + # a real object. This is generally recommended, and will default to + # `true` in RSpec 4. + mocks.verify_partial_doubles = true + end + +# The settings below are suggested to provide a good initial experience +# with RSpec, but feel free to customize to your heart's content. +=begin + # These two settings work together to allow you to limit a spec run + # to individual examples or groups you care about by tagging them with + # `:focus` metadata. When nothing is tagged with `:focus`, all examples + # get run. + config.filter_run :focus + config.run_all_when_everything_filtered = true + + # Allows RSpec to persist some state between runs in order to support + # the `--only-failures` and `--next-failure` CLI options. We recommend + # you configure your source control system to ignore this file. + config.example_status_persistence_file_path = "spec/examples.txt" + + # Limits the available syntax to the non-monkey patched syntax that is + # recommended. For more details, see: + # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ + # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ + # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode + config.disable_monkey_patching! + + # This setting enables warnings. It's recommended, but in some cases may + # be too noisy due to issues in dependencies. + config.warnings = true + + # Many RSpec users commonly either run the entire suite or an individual + # file, and it's useful to allow more verbose output when running an + # individual spec file. + if config.files_to_run.one? + # Use the documentation formatter for detailed output, + # unless a formatter has already been configured + # (e.g. via a command-line flag). + config.default_formatter = 'doc' + end + + # Print the 10 slowest examples and example groups at the + # end of the spec run, to help surface which specs are running + # particularly slow. + config.profile_examples = 10 + + # Run specs in random order to surface order dependencies. If you find an + # order dependency and want to debug it, you can fix the order by providing + # the seed, which is printed after each run. + # --seed 1234 + config.order = :random + + # Seed global randomization in this process using the `--seed` CLI option. + # Setting this allows you to use `--seed` to deterministically reproduce + # test failures related to randomization by passing the same `--seed` value + # as the one that triggered the failure. + Kernel.srand config.seed +=end +end From a1c50d352d2dd68a139be17750f0aedd058723a7 Mon Sep 17 00:00:00 2001 From: Dan Garland Date: Mon, 7 Mar 2016 17:26:43 +0000 Subject: [PATCH 4/4] Adding rspec tests --- .gitignore | 1 + bitbucket_rest_api.gemspec | 2 + lib/bitbucket_rest_api/core_ext/array.rb | 1 + lib/bitbucket_rest_api/core_ext/hash.rb | 1 + spec/bitbucket_rest_api/api_factory_spec.rb | 30 ++++++ spec/bitbucket_rest_api/api_spec.rb | 86 +++++++++++++++++ spec/bitbucket_rest_api/authorization_spec.rb | 59 ++++++++++++ .../bitbucket_rest_api/core_ext/array_spec.rb | 30 ++++++ spec/bitbucket_rest_api/core_ext/hash_spec.rb | 67 +++++++++++++ spec/bitbucket_rest_api/normalizer_spec.rb | 30 ++++++ .../parameter_filter_spec.rb | 31 ++++++ spec/bitbucket_rest_api/request_spec.rb | 81 ++++++++++++++++ spec/bitbucket_rest_api/user_spec.rb | 77 +++++++++++++++ spec/spec_helper.rb | 95 ++----------------- 14 files changed, 505 insertions(+), 86 deletions(-) create mode 100644 spec/bitbucket_rest_api/api_factory_spec.rb create mode 100644 spec/bitbucket_rest_api/api_spec.rb create mode 100644 spec/bitbucket_rest_api/authorization_spec.rb create mode 100644 spec/bitbucket_rest_api/core_ext/array_spec.rb create mode 100644 spec/bitbucket_rest_api/core_ext/hash_spec.rb create mode 100644 spec/bitbucket_rest_api/normalizer_spec.rb create mode 100644 spec/bitbucket_rest_api/parameter_filter_spec.rb create mode 100644 spec/bitbucket_rest_api/request_spec.rb create mode 100644 spec/bitbucket_rest_api/user_spec.rb diff --git a/.gitignore b/.gitignore index ec9becf..69ab872 100644 --- a/.gitignore +++ b/.gitignore @@ -11,5 +11,6 @@ log features/settings.yml *.gem .tags +TAGS .tags_sorted_by_file coverage diff --git a/bitbucket_rest_api.gemspec b/bitbucket_rest_api.gemspec index acc8978..63b5dea 100644 --- a/bitbucket_rest_api.gemspec +++ b/bitbucket_rest_api.gemspec @@ -27,4 +27,6 @@ Gem::Specification.new do |gem| gem.add_development_dependency 'simplecov', '~> 0.6.1' gem.add_development_dependency 'rake' gem.add_development_dependency 'bundler' + gem.add_development_dependency 'pry' + gem.add_development_dependency 'mocha' end diff --git a/lib/bitbucket_rest_api/core_ext/array.rb b/lib/bitbucket_rest_api/core_ext/array.rb index 03ec2e9..28b48f4 100644 --- a/lib/bitbucket_rest_api/core_ext/array.rb +++ b/lib/bitbucket_rest_api/core_ext/array.rb @@ -4,6 +4,7 @@ def except(*keys) # :nodoc: self.dup.except!(*keys) end unless method_defined?(:except) + # TODO except! should moodify self not a copy def except!(*items) # :nodoc: copy = self.dup copy.reject! { |item| items.include? item } diff --git a/lib/bitbucket_rest_api/core_ext/hash.rb b/lib/bitbucket_rest_api/core_ext/hash.rb index 081e691..fcae187 100644 --- a/lib/bitbucket_rest_api/core_ext/hash.rb +++ b/lib/bitbucket_rest_api/core_ext/hash.rb @@ -6,6 +6,7 @@ def except(*items) # :nodoc: def except!(*keys) # :nodoc: copy = self.dup + # FIXME delete! is not a hash instance method keys.each { |key| copy.delete!(key) } copy end unless method_defined?(:except!) diff --git a/spec/bitbucket_rest_api/api_factory_spec.rb b/spec/bitbucket_rest_api/api_factory_spec.rb new file mode 100644 index 0000000..da1dc05 --- /dev/null +++ b/spec/bitbucket_rest_api/api_factory_spec.rb @@ -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 diff --git a/spec/bitbucket_rest_api/api_spec.rb b/spec/bitbucket_rest_api/api_spec.rb new file mode 100644 index 0000000..235d464 --- /dev/null +++ b/spec/bitbucket_rest_api/api_spec.rb @@ -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 diff --git a/spec/bitbucket_rest_api/authorization_spec.rb b/spec/bitbucket_rest_api/authorization_spec.rb new file mode 100644 index 0000000..470e73b --- /dev/null +++ b/spec/bitbucket_rest_api/authorization_spec.rb @@ -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 diff --git a/spec/bitbucket_rest_api/core_ext/array_spec.rb b/spec/bitbucket_rest_api/core_ext/array_spec.rb new file mode 100644 index 0000000..f9ba932 --- /dev/null +++ b/spec/bitbucket_rest_api/core_ext/array_spec.rb @@ -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 diff --git a/spec/bitbucket_rest_api/core_ext/hash_spec.rb b/spec/bitbucket_rest_api/core_ext/hash_spec.rb new file mode 100644 index 0000000..bacc520 --- /dev/null +++ b/spec/bitbucket_rest_api/core_ext/hash_spec.rb @@ -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 diff --git a/spec/bitbucket_rest_api/normalizer_spec.rb b/spec/bitbucket_rest_api/normalizer_spec.rb new file mode 100644 index 0000000..abaab76 --- /dev/null +++ b/spec/bitbucket_rest_api/normalizer_spec.rb @@ -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 diff --git a/spec/bitbucket_rest_api/parameter_filter_spec.rb b/spec/bitbucket_rest_api/parameter_filter_spec.rb new file mode 100644 index 0000000..287434f --- /dev/null +++ b/spec/bitbucket_rest_api/parameter_filter_spec.rb @@ -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 diff --git a/spec/bitbucket_rest_api/request_spec.rb b/spec/bitbucket_rest_api/request_spec.rb new file mode 100644 index 0000000..88c5f0c --- /dev/null +++ b/spec/bitbucket_rest_api/request_spec.rb @@ -0,0 +1,81 @@ +require 'spec_helper' +require 'bitbucket_rest_api/request' + +describe BitBucket::Request do + let(:fake_api) { (Class.new { include BitBucket::Request })} + let(:faraday_connection) { Faraday.new(:url => 'https://bitbucket.org/api') } + + describe "request" do + it "raises an ArgumentError if an unsupported HTTP verb is used" do + expect { fake_api.new.request(:i_am_a_teapot, '/', {}, {}) }.to raise_error(ArgumentError) + end + + context "with a connection" do + before do + (fake_api).any_instance.stubs(:connection).returns(faraday_connection) + (fake_api).any_instance.stubs(:new_access_token).returns("12345") + end + + it "supports get" do + stub_request(:get, "https://bitbucket.org/api/1.0/repositories"). + with(:headers => { + 'Accept' => '*/*', + 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + 'Authorization' => 'Bearer 12345', + 'User-Agent' => 'Faraday v0.9.2' + }) + + fake_api.new.request(:get, '/1.0/repositories', {}, {}) + end + + it "supports put" do + stub_request(:put, "https://bitbucket.org/api/1.0/repositories"). + with(:body => { "data" => "payload" }, + :headers => { + 'Accept' => '*/*', + 'Content-Type'=>'application/x-www-form-urlencoded', + 'Authorization' => 'Bearer 12345', + 'User-Agent' => 'Faraday v0.9.2' + }) + + fake_api.new.request(:put, '/1.0/repositories', { :data => "payload" }, {}) + end + + it "supports patch" do + stub_request(:patch, "https://bitbucket.org/api/1.0/repositories"). + with(:body => { "data" => "payload" }, + :headers => { + 'Accept' => '*/*', + 'Content-Type'=>'application/x-www-form-urlencoded', + 'Authorization' => 'Bearer 12345', + 'User-Agent' => 'Faraday v0.9.2' + }) + + fake_api.new.request(:patch, '/1.0/repositories', { :data => "payload" }, {}) + end + + it "supports delete" do + stub_request(:delete, "https://bitbucket.org/api/1.0/repositories"). + with(:headers => { + 'Accept' => '*/*', + 'Authorization' => 'Bearer 12345', + 'User-Agent' => 'Faraday v0.9.2' + }) + fake_api.new.request(:delete, '/1.0/repositories', {}, {}) + end + + it "supports post" do + stub_request(:post, "https://bitbucket.org/api/1.0/repositories"). + with(:body => { "data" => "payload" }, + :headers => { + 'Accept' => '*/*', + 'Content-Type'=>'application/x-www-form-urlencoded', + 'Authorization' => 'Bearer 12345', + 'User-Agent' => 'Faraday v0.9.2' + }) + + fake_api.new.request(:post, '/1.0/repositories', { :data => "payload" }, {}) + end + end + end +end \ No newline at end of file diff --git a/spec/bitbucket_rest_api/user_spec.rb b/spec/bitbucket_rest_api/user_spec.rb new file mode 100644 index 0000000..5d32e58 --- /dev/null +++ b/spec/bitbucket_rest_api/user_spec.rb @@ -0,0 +1,77 @@ +require 'spec_helper' + +describe BitBucket::User do + let(:options) do + { + client_id: 'example_client_id', + client_secret: 'example_client_secret', + oauth_token: 'example_oauth_token', + oauth_secret: 'example_oauth_secret', + adapter: :net_http + } + end + + before do + @user = BitBucket::User.new(options) + end + + describe '#profile' do + it 'sends the request to the right url' do + expect(@user).to receive(:request).with(:get, '/1.0/user', {}, {}) + @user.profile + end + end + + describe '#update' do + let(:params) do + { first_name: 'first-name', last_name: 'last-name', avatar: '' } + end + + it 'sends the request to the right url' do + expect(@user).to receive(:request).with(:put, '/1.0/user', params, {}) + @user.update(params) + end + end + + describe '#privileges' do + it 'sends the request to the right url' do + expect(@user).to receive(:request).with(:get, '/1.0/user/privileges', {}, {}) + @user.privileges + end + end + + describe '#follows' do + it 'sends the request to the right url' do + expect(@user).to receive(:request).with(:get, '/1.0/user/follows', {}, {}) + @user.follows + end + end + + describe '#repositories' do + it 'sends the request to the right url' do + expect(@user).to receive(:request).with(:get, '/1.0/user/repositories', {}, {}) + @user.repositories + end + end + + describe '#repos' do + it 'sends the request to the right url' do + expect(@user).to receive(:request).with(:get, '/1.0/user/repositories', {}, {}) + @user.repos + end + end + + describe '#overview' do + it 'sends the request to the right url' do + expect(@user).to receive(:request).with(:get, '/1.0/user/repositories/overview', {}, {}) + @user.overview + end + end + + describe '#dashboard' do + it 'sends the request to the right url' do + expect(@user).to receive(:request).with(:get, '/1.0/user/repositories/dashboard', {}, {}) + @user.dashboard + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index cb43c65..821823c 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,101 +1,24 @@ require 'simplecov' SimpleCov.start +require 'webmock/rspec' +require 'pry' +require 'vcr' + require 'bitbucket_rest_api' -# This file was generated by the `rspec --init` command. Conventionally, all -# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. -# The generated `.rspec` file contains `--require spec_helper` which will cause -# this file to always be loaded, without a need to explicitly require it in any -# files. -# -# Given that it is always loaded, you are encouraged to keep this file as -# light-weight as possible. Requiring heavyweight dependencies from this file -# will add to the boot time of your test suite on EVERY test run, even for an -# individual file that may not need all of that loaded. Instead, consider making -# a separate helper file that requires the additional dependencies and performs -# the additional setup, and require it from the spec files that actually need -# it. -# -# The `.rspec` file also contains a few flags that are not defaults but that -# users commonly want. -# -# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration RSpec.configure do |config| - # rspec-expectations config goes here. You can use an alternate - # assertion/expectation library such as wrong or the stdlib/minitest - # assertions if you prefer. config.expect_with :rspec do |expectations| - # This option will default to `true` in RSpec 4. It makes the `description` - # and `failure_message` of custom matchers include text for helper methods - # defined using `chain`, e.g.: - # be_bigger_than(2).and_smaller_than(4).description - # # => "be bigger than 2 and smaller than 4" - # ...rather than: - # # => "be bigger than 2" expectations.include_chain_clauses_in_custom_matcher_descriptions = true + config.mock_with :mocha end - # rspec-mocks config goes here. You can use an alternate test double - # library (such as bogus or mocha) by changing the `mock_with` option here. config.mock_with :rspec do |mocks| - # Prevents you from mocking or stubbing a method that does not exist on - # a real object. This is generally recommended, and will default to - # `true` in RSpec 4. mocks.verify_partial_doubles = true end +end -# The settings below are suggested to provide a good initial experience -# with RSpec, but feel free to customize to your heart's content. -=begin - # These two settings work together to allow you to limit a spec run - # to individual examples or groups you care about by tagging them with - # `:focus` metadata. When nothing is tagged with `:focus`, all examples - # get run. - config.filter_run :focus - config.run_all_when_everything_filtered = true - - # Allows RSpec to persist some state between runs in order to support - # the `--only-failures` and `--next-failure` CLI options. We recommend - # you configure your source control system to ignore this file. - config.example_status_persistence_file_path = "spec/examples.txt" - - # Limits the available syntax to the non-monkey patched syntax that is - # recommended. For more details, see: - # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ - # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ - # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode - config.disable_monkey_patching! - - # This setting enables warnings. It's recommended, but in some cases may - # be too noisy due to issues in dependencies. - config.warnings = true - - # Many RSpec users commonly either run the entire suite or an individual - # file, and it's useful to allow more verbose output when running an - # individual spec file. - if config.files_to_run.one? - # Use the documentation formatter for detailed output, - # unless a formatter has already been configured - # (e.g. via a command-line flag). - config.default_formatter = 'doc' - end - - # Print the 10 slowest examples and example groups at the - # end of the spec run, to help surface which specs are running - # particularly slow. - config.profile_examples = 10 - - # Run specs in random order to surface order dependencies. If you find an - # order dependency and want to debug it, you can fix the order by providing - # the seed, which is printed after each run. - # --seed 1234 - config.order = :random - - # Seed global randomization in this process using the `--seed` CLI option. - # Setting this allows you to use `--seed` to deterministically reproduce - # test failures related to randomization by passing the same `--seed` value - # as the one that triggered the failure. - Kernel.srand config.seed -=end +VCR.configure do |config| + config.cassette_library_dir = 'spec/fixtures/vcr_cassettes' + config.hook_into :webmock end