Commit 7f289103 authored by sergio1990's avatar sergio1990

Logging connection extension

Ref #13
parent 29630b75
require "rubygems"
# require 'rspec/core/rake_task'
# require 'rubygems/specification'
require 'rspec/core/rake_task'
require 'rubygems/specification'
# task default: :spec
# desc "Run specs"
# RSpec::Core::RakeTask.new do |t|
# t.pattern = FileList['spec/**/*_spec.rb']
# t.rspec_opts = %w(--color)
# end
task default: :spec
desc "Run specs"
RSpec::Core::RakeTask.new do |t|
t.pattern = FileList['spec/**/*_spec.rb']
t.rspec_opts = %w(--color)
end
......@@ -132,6 +132,7 @@ module BetfairApiNgRails
autoload :ErrorHandling, 'betfair_api_ng_rails/api/connection_ext/error_handling'
autoload :Parsing, 'betfair_api_ng_rails/api/connection_ext/parsing'
autoload :Formatting, 'betfair_api_ng_rails/api/connection_ext/formatting'
autoload :Logging, 'betfair_api_ng_rails/api/connection_ext/logging'
end
......
......@@ -14,6 +14,7 @@ module BetfairApiNgRails
provider.fetch method: method, params: hashing(params)
end
include Api::ConnectionExt::Logging
include Api::ConnectionExt::ErrorHandling
include Api::ConnectionExt::Parsing
include Api::ConnectionExt::Formatting
......
require 'active_support/inflector'
module BetfairApiNgRails
module Api
module ConnectionExt
module Logging
include BetfairApiNgRails::Api::Constants
def self.included(base)
base.send :class_eval, <<-CODE
def request_with_logging(method, params = {})
write_income_request method, params
request_without_logging(method, params).tap { |res| write_result(res) }
end
alias_method :request_without_logging, :request
alias_method :request, :request_with_logging
CODE
end
private
def write_income_request(method, params)
BetfairApiNgRails.log.write("--->Income request for #{method} with parameters #{hashing(params)}")
end
def write_result(res)
BetfairApiNgRails.log.write(" Result of request: #{res.result}")
end
end
end
end
end
\ No newline at end of file
......@@ -17,18 +17,21 @@ describe BetfairApiNgRails::Api::Connection do
let(:provider) { double(:provider) }
let(:parser) { double(:parser, process: true) }
let(:response) { double(:response) }
let(:response) { double(:response, result: "") }
let(:logger) { double(:logger) }
before(:each) do
expect_any_instance_of(described_class).to receive(:request_ssoid)
expect(subject).to receive(:init_parser).and_return parser
BetfairApiNgRails.log = logger
allow(logger).to receive(:write)
end
it "calls provider's fetch method" do
expect(subject).to receive(:provider).and_return provider
expect(provider).to receive(:fetch).with(method: 'method', params: {}).and_return response
expect(response).to receive(:has_error?).and_return false
expect(subject).to receive(:hashing).with({}).and_return({})
allow(subject).to receive(:hashing).with({}).and_return({})
subject.request 'method'
end
......
shared_examples 'simple list filtering request' do |method|
let(:parameters) { {filter: filter} }
let(:logger) { double(:logger) }
before(:each) { BetfairApiNgRails.config.formatter = nil }
before(:each) do
BetfairApiNgRails.config.formatter = nil
BetfairApiNgRails.log = logger
allow(logger).to receive(:write)
end
context 'when no error occured' do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment