diff --git a/.gitignore b/.gitignore index 8a54bad..de2523f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,9 @@ -.rspec_status +# bundler +.bundle Gemfile.lock + +# rspec +.rspec_status + +# For MacOS: +.DS_Store diff --git a/.rspec b/.rspec index fb15b93..6c6110e 100644 --- a/.rspec +++ b/.rspec @@ -1,4 +1,4 @@ +--format documentation --color ---order random --require spec_helper ---format documentation +--order random diff --git a/football_api.gemspec b/football_api.gemspec index bfd5a97..c8eefb6 100644 --- a/football_api.gemspec +++ b/football_api.gemspec @@ -12,6 +12,8 @@ Gem::Specification.new do |spec| spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0") + spec.metadata["homepage_uri"] = spec.homepage + # Specify which files should be added to the gem when it is released. # The `git ls-files -z` loads the files in the RubyGem that have been added into git. spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do diff --git a/spec/sideline_spec.rb b/spec/sideline_spec.rb new file mode 100644 index 0000000..765d1cf --- /dev/null +++ b/spec/sideline_spec.rb @@ -0,0 +1,25 @@ +RSpec.describe FootballApi::Sideline do + let(:response) { load_response('sidelined') } + + before(:each) do + stub_request(:get, uri) + .with(headers: @headers) + .to_return(status: 200, body: response.to_json, headers: {}) + end + + describe '.all_by_player' do + let(:uri) { "#{@api_host}/sidelined/player/276" } + + it "requests the sidelined by player endpoint" do + expect(described_class.all_by_player(276)).to eq(response.dig('api', 'sidelined')) + end + end + + describe '.all_by_coach' do + let(:uri) { "#{@api_host}/sidelined/coach/2" } + + it "requests the sidelined by coach endpoint" do + expect(described_class.all_by_coach(2)).to eq(response.dig('api', 'sidelined')) + end + end +end diff --git a/spec/support/json_responses/sidelined.json b/spec/support/json_responses/sidelined.json new file mode 100644 index 0000000..60e3af2 --- /dev/null +++ b/spec/support/json_responses/sidelined.json @@ -0,0 +1,27 @@ +{ + "api": { + "results": 25, + "sidelined": [ + { + "type": "Groin/Pelvis Injury", + "start": "11/10/19", + "end": "15/11/19" + }, + { + "type": "Ankle/Foot Injury", + "start": "01/08/19", + "end": "23/08/19" + }, + { + "type": "Suspended", + "start": "15/05/19", + "end": "27/05/19" + }, + { + "type": "Ankle/Foot Injury", + "start": "24/01/19", + "end": "20/04/19" + } + ] + } +} diff --git a/spec/support/json_responses/trophies.json b/spec/support/json_responses/trophies.json new file mode 100644 index 0000000..3afc16a --- /dev/null +++ b/spec/support/json_responses/trophies.json @@ -0,0 +1,37 @@ +{ + "api": { + "results": 38, + "trophies": [ + { + "league": "Trophée des Champions", + "country": "France", + "season": "2019/2020", + "place": "Winner" + }, + { + "league": "Copa America", + "country": "South-America", + "season": "2019 Brazil", + "place": "Winner" + }, + { + "league": "Ligue 1", + "country": "France", + "season": "2018/2019", + "place": "Winner" + }, + { + "league": "Coupe de France", + "country": "France", + "season": "2018/2019", + "place": "2nd Place" + }, + { + "league": "Trophée des Champions", + "country": "France", + "season": "2018/2019", + "place": "Winner" + } + ] + } +} diff --git a/spec/trophey_spec.rb b/spec/trophey_spec.rb new file mode 100644 index 0000000..f920e22 --- /dev/null +++ b/spec/trophey_spec.rb @@ -0,0 +1,25 @@ +RSpec.describe FootballApi::Trophey do + let(:response) { load_response('trophies') } + + before(:each) do + stub_request(:get, uri) + .with(headers: @headers) + .to_return(status: 200, body: response.to_json, headers: {}) + end + + describe '.all_by_player' do + let(:uri) { "#{@api_host}/trophies/player/276" } + + it "requests the trophies by player endpoint" do + expect(described_class.all_by_player(276)).to eq(response.dig('api', 'trophies')) + end + end + + describe '.all_by_coach' do + let(:uri) { "#{@api_host}/trophies/coach/2" } + + it "requests the trophies by coach endpoint" do + expect(described_class.all_by_coach(2)).to eq(response.dig('api', 'trophies')) + end + end +end