Commit 759ffbb9 authored by Sergey Gernyak's avatar Sergey Gernyak

REFACTOR: integration specs

ref #17
parent 4aa4ab50
require 'spec_helper'
module TestModule
extend BetfairApiNgRails::Api::RequestMethods
end
describe "listCompetitions request method" do
it_behaves_like 'simple list filtering request', 'listCompetitions' do
let(:method_name) { "list_competitions" }
let(:result_class) { BetfairApiNgRails::CompetitionResult }
let(:result_hash) { "{\"result\": [{\"marketCount\": 1, \"competition\": { \"id\": 1, \"name\": \"World Cup 2014\" }, \"competitionRegion\": \"BR\"}]}" }
let(:result_hash) do
<<-JSON
{"result":
[{"marketCount": 1, "competition": { "id": 1, "name": "World Cup 2014" }, "competitionRegion": "BR"}
]}
JSON
end
end
end
require 'spec_helper'
module TestModule
extend BetfairApiNgRails::Api::RequestMethods
end
describe "listCountries request method" do
it_behaves_like 'simple list filtering request', 'listCountries' do
let(:method_name) { "list_countries" }
let(:result_class) { BetfairApiNgRails::CountryCodeResult }
let(:result_hash) { "{\"result\": [{\"marketCount\": 1, \"event\": \"UA\"}]}" }
let(:result_hash) do
<<-JSON
{"result":
[{"marketCount": 1, "event": "UA"}
]}
JSON
end
end
end
require 'spec_helper'
module TestModule
extend BetfairApiNgRails::Api::RequestMethods
end
describe "listEventTypes request method" do
it_behaves_like 'simple list filtering request', 'listEventTypes' do
let(:method_name) { "list_event_types" }
let(:result_class) { BetfairApiNgRails::EventTypeResult }
let(:result_hash) { "{\"result\": [{\"marketCount\": 1, \"eventType\": { \"id\": 1, \"name\": \"Soccer\" }}]}" }
let(:result_hash) do
<<-JSON
{"result":
[{"marketCount": 1, "eventType": { "id": 1, "name": "Soccer" }}
]}
JSON
end
end
end
require 'spec_helper'
module TestModule
extend BetfairApiNgRails::Api::RequestMethods
end
describe "listEvents request method" do
it_behaves_like 'simple list filtering request', 'listEvents' do
let(:method_name) { "list_events" }
let(:result_class) { BetfairApiNgRails::EventResult }
let(:result_hash) { "{\"result\": [{\"marketCount\": 1, \"event\": { \"id\": 1, \"name\": \"Chelsea - PSG\" }}]}" }
let(:result_hash) do
<<-JSON
{"result":
[{"marketCount": 1, "event": { "id": 1, "name": "Chelsea - PSG" }}
]}
JSON
end
end
end
require 'spec_helper'
module TestModule
extend BetfairApiNgRails::Api::RequestMethods
end
describe "listMarketBook request method" do
it_behaves_like 'simple list filtering request', 'listMarketBook' do
let(:parameters) { {market_ids: [1]} }
let(:method_name) { "list_market_book" }
let(:result_class) { BetfairApiNgRails::MarketBook }
let(:result_hash) { "{\"result\": [{\"marketId\": 1, \"isMarketDataDelayed\": \"true\"}]}" }
let(:result_hash) do
<<-JSON
{"result":
[{"marketId": 1, "isMarketDataDelayed": "true"}
]}
JSON
end
end
end
require 'spec_helper'
module TestModule
extend BetfairApiNgRails::Api::RequestMethods
end
describe "listMarketCatalogue request method" do
it_behaves_like 'simple list filtering request', 'listMarketCatalogue' do
let(:method_name) { "list_market_catalogue" }
let(:result_class) { BetfairApiNgRails::MarketCatalogue }
let(:result_hash) { "{\"result\": [{\"marketId\": 1, \"marketName\": \"Madrid\", \"marketStartTime\": \"23-04-2014\", \"description\": \"Madrid\", \"totalMatched\": \"1\", \"competition\": {\"id\": 1, \"name\": \"name\"}}]}" }
let(:result_hash) do
<<-JSON
{"result":
[{"marketId": 1, "marketName": "Madrid", "marketStartTime": "23-04-2014", "description": "Madrid", "totalMatched": "1", "competition": {"id": 1, "name": "name"}}
]}
JSON
end
describe 'checking attribute' do
context 'competition' do
it_behaves_like 'request method' do
subject { TestModule.send(method_name, parameters).first }
its(:competition) { is_expected.not_to be_nil }
its('competition.name') { is_expected.to eq 'name' }
end
end
end
end
end
require 'spec_helper'
module TestModule
extend BetfairApiNgRails::Api::RequestMethods
end
describe "listMarketTypes request method" do
it_behaves_like 'simple list filtering request', 'listMarketTypes' do
let(:method_name) { "list_market_types" }
let(:result_class) { BetfairApiNgRails::MarketTypeResult }
let(:result_hash) { "{\"result\": [{\"marketCount\": 1, \"marketType\": \"MATCH_ODDS\"}]}" }
let(:result_hash) do
<<-JSON
{"result":
[{"marketCount": 1, "marketType": "MATCH_ODDS"}
]}
JSON
end
end
end
require 'spec_helper'
module TestModule
extend BetfairApiNgRails::Api::RequestMethods
end
describe "listTimeRanges request method" do
it_behaves_like 'simple list filtering request', 'listTimeRanges' do
let(:method_name) { "list_time_ranges" }
let(:result_class) { BetfairApiNgRails::TimeRangeResult }
let(:result_hash) { "{\"result\": [{\"marketCount\": 1, \"timeRange\": { \"to\": \"18-04-2014\", \"from\": \"18-04-2014\" }}]}" }
let(:result_hash) do
<<-JSON
{"result": [
{"marketCount": 1, "timeRange": { "to": "18-04-2014", "from": "18-04-2014" }}
]}
JSON
end
end
end
require 'spec_helper'
module TestModule
extend BetfairApiNgRails::Api::RequestMethods
end
describe "listVenues request method" do
it_behaves_like 'simple list filtering request', 'listVenues' do
let(:method_name) { "list_venues" }
let(:result_class) { BetfairApiNgRails::VenueResult }
let(:result_hash) { "{\"result\": [{\"marketCount\": 1, \"venue\": \"Madrid\"}]}" }
let(:result_hash) do
<<-JSON
{"result": [
{"marketCount": 1, "venue": "Madrid"}
]}
JSON
end
end
end
......@@ -6,6 +6,10 @@ require 'betfair_api_ng_rails'
Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require f }
module TestModule
extend BetfairApiNgRails::Api::RequestMethods
end
RSpec.configure do |config|
config.mock_with :rspec
......@@ -13,4 +17,4 @@ RSpec.configure do |config|
config.run_all_when_everything_filtered = true
config.order = "random"
end
\ No newline at end of file
end
require 'yaml'
class BaseYamlLoader
attr_reader :data
def initialize(file_name)
......@@ -12,10 +11,9 @@ class BaseYamlLoader
data.fetch resource_name, {}
end
private
private
def file_path(file_name)
File.join(File.dirname(__FILE__), "data/#{file_name}.yml")
end
end
\ No newline at end of file
end
class DataModelsYamlLoader < BaseYamlLoader
def initialize
super 'models'
end
end
\ No newline at end of file
end
class Helper
class << self
def key_to_attribute(key)
key.to_s.gsub(/^([a-z])/) { $1.capitalize }.scan(/[A-Z][a-z]*/).join("_").downcase
end
end
end
\ No newline at end of file
end
......@@ -6,30 +6,21 @@ shared_examples 'data model' do |resourceHash|
subject { data }
describe "loading from json" do
it { is_expected.to be_kind_of described_class }
resourceHash.each do |k, v|
next unless v.is_a?(String)
its(Helper.key_to_attribute(k)) { is_expected.to eq v }
its(Helper.key_to_attribute(k)) { is_expected.to eq v }
end
end
if described_class.method_defined?(:to_hash)
describe "serialize to hash" do
subject { data.to_hash }
it { is_expected.to be_kind_of Hash }
it { is_expected.to eq json }
end
end
end
\ No newline at end of file
end
......@@ -3,56 +3,40 @@ shared_examples 'simple list filtering request' do |method|
let(:parameters) { {filter: filter} }
let(:logger) { double(:logger) }
before(:each) do
before(:each) do
BetfairApiNgRails.config.formatter = nil
BetfairApiNgRails.log = logger
allow(logger).to receive(:write)
end
context 'when no error occured' do
it_behaves_like 'request method' do
it { is_expected.not_to be_empty }
its(:first) { is_expected.to be_kind_of result_class }
end
end
context 'when api error occured' do
it_behaves_like 'request method' do
let(:result_hash) { "{\"error\":{\"code\":-32700,\"message\":\"DSC-3000\"}}" }
it "raise APINGException" do
expect{ subject }.to raise_error
end
end
end
if BetfairApiNgRails::Api::Constants::ALLOWED_FORMATTING.include?(method)
context 'when enabled formatting' do
before(:each) { BetfairApiNgRails.config.formatter = :js_tree }
it_behaves_like 'request method' do
it { is_expected.not_to be_empty }
its(:first) { is_expected.to be_kind_of Hash }
its('first.keys') { is_expected.to include(:id, :text, :children, :data) }
end
end
end
end
\ No newline at end of file
end
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