diff --git a/.gitignore b/.gitignore index 9e667f6..35f7844 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,8 @@ spec/reports test/tmp test/version_tmp tmp +Gemfile.lock +.rspec #chargebee ignores snippets.rb diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..b4e2a20 --- /dev/null +++ b/Gemfile @@ -0,0 +1,3 @@ +source "https://rubygems.org" + +gemspec diff --git a/lib/chargebee/errors.rb b/lib/chargebee/errors.rb index 6371621..9736552 100644 --- a/lib/chargebee/errors.rb +++ b/lib/chargebee/errors.rb @@ -3,9 +3,9 @@ module ChargeBee class Error < StandardError attr_reader :original_error - def initialize(message=nil,original_error = nil) - super message - @original_error = original_error + def initialize(message = nil, original_error = {}) + super message + @original_error = original_error end end @@ -16,8 +16,8 @@ class APIError < Error attr_reader :http_status_code, :type, :api_error_code, :param, :json_obj, #Deprecated attributes :http_code, :http_body, :error_code - - def initialize(http_code=nil, json_obj = nil) + + def initialize(http_code = nil, json_obj = {}) super json_obj[:message] @json_obj = json_obj @http_status_code = http_code @@ -30,7 +30,7 @@ def initialize(http_code=nil, json_obj = nil) @http_code = http_code @http_body = json_obj.to_s end - + end diff --git a/spec/errors_spec.rb b/spec/errors_spec.rb index 9638763..33cc9a7 100644 --- a/spec/errors_spec.rb +++ b/spec/errors_spec.rb @@ -1,6 +1,7 @@ require 'spec_helper' describe 'ChargeBee::InvalidRequestError' do + let(:invalid_request_json) do { message: 'id: The value chargebee_account is already present.', @@ -14,10 +15,14 @@ } end - it "provide message from error api response" do + it 'provide message from error api response' do error = ChargeBee::InvalidRequestError.new(400, invalid_request_json) error.message.should eq 'id: The value chargebee_account is already present.' end -end + it 'allows empty arguments' do + error = ChargeBee::InvalidRequestError.new + error.message.should eq 'ChargeBee::InvalidRequestError' + end +end