Skip to content

Commit

Permalink
fix rubocop warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ta committed Feb 14, 2019
1 parent e32aa4e commit 98acd39
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Gemfile
@@ -1,4 +1,4 @@
source 'https://rubygems.org'
source "https://rubygems.org"

# Specify your gem's dependencies in quickpay-ruby-client.gemspec
gemspec
10 changes: 4 additions & 6 deletions lib/quickpay/api/error.rb
Expand Up @@ -40,12 +40,10 @@ def initialize(status, body, headers)
end

def self.by_status_code(status, body, headers)
if CLASS_MAP[status]
klass = QuickPay::API::Error.const_get(CLASS_MAP[status])
fail klass.new(status, body, headers)
else
fail QuickPay::API::Error.new(status, body, headers)
end
raise QuickPay::API::Error.new(status, body, headers) unless CLASS_MAP[status]

klass = QuickPay::API::Error.const_get(CLASS_MAP[status])
raise klass.new(status, body, headers)
end
end
end
Expand Down
3 changes: 1 addition & 2 deletions quickpay-ruby-client.gemspec
@@ -1,4 +1,3 @@
# coding: utf-8
lib = File.expand_path("lib", __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "quickpay/api/version"
Expand All @@ -19,8 +18,8 @@ Gem::Specification.new do |spec|
spec.require_paths = ["lib"]

spec.add_development_dependency "bundler"
spec.add_development_dependency "rake", "~> 12.3.2"
spec.add_development_dependency "minitest", "~> 5.11.3"
spec.add_development_dependency "rake", "~> 12.3.2"
spec.add_development_dependency "rubocop"

spec.add_dependency "excon", "~> 0.62.0"
Expand Down
57 changes: 47 additions & 10 deletions test/client.rb
Expand Up @@ -5,17 +5,29 @@

Excon.defaults[:mock] = true

# Excon expects two hashes
# rubocop:disable Style/BracesAroundHashParameters

describe QuickPay::API::Client do
before do
Excon.stub({}, { body: "Uknown Stub", status: 500})
Excon.stub({}, { body: "Uknown Stub", status: 500 })
end

after do
Excon.stubs.clear
end

it "set default headers" do
Excon.stub({ path: "/ping" }, lambda { |request_params| { headers: request_params[:headers], :status => 200 } })
Excon.stub(
{ path: "/ping" },
lambda do |request_params|
{
headers: request_params[:headers],
status: 200
}
end
)

client = QuickPay::API::Client.new
_, _, headers = *client.get("/ping", raw: true)

Expand All @@ -24,7 +36,16 @@
end

it "handles authentication" do
Excon.stub({ path: "/ping" }, lambda { |request_params| { headers: request_params[:headers], :status => 200 } })
Excon.stub(
{ path: "/ping" },
lambda do |request_params|
{
headers: request_params[:headers],
status: 200
}
end
)

client = QuickPay::API::Client.new(password: "secret")
_, _, headers = *client.get("/ping", raw: true)

Expand All @@ -34,7 +55,17 @@
it "handles convenient JSON <=> Hash conversion of body" do
client = QuickPay::API::Client.new

Excon.stub({ path: "/ping" }, lambda { |request_params| { body: request_params[:body], :status => 200 } })
Excon.stub(
{ path: "/ping" },
lambda do |request_params|
{
body: request_params[:body],
status: 200
}
end
)

# client return JSON string
client.post(
"/ping",
body: { "foo" => "bar" },
Expand All @@ -43,13 +74,18 @@
JSON.parse(response).must_equal({ "foo" => "bar" })
end

Excon.stub({ path: "/ping" },
lambda { |request_params| {
body: request_params[:body],
headers: { "Content-Type" => "application/json" },
:status => 200 }
}
Excon.stub(
{ path: "/ping" },
lambda do |request_params|
{
body: request_params[:body],
headers: { "Content-Type" => "application/json" },
status: 200
}
end
)

# client returns Ruby Hash
client.post(
"/ping",
body: { "foo" => "bar" },
Expand Down Expand Up @@ -133,3 +169,4 @@
end
end
end
# rubocop:enable Style/BracesAroundHashParameters

0 comments on commit 98acd39

Please sign in to comment.