Skip to content

Commit

Permalink
Add more spec examples
Browse files Browse the repository at this point in the history
  • Loading branch information
radkomih committed Oct 10, 2020
1 parent e05fff4 commit 82b3818
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 3 deletions.
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
.rspec_status
# bundler
.bundle
Gemfile.lock

# rspec
.rspec_status

# For MacOS:
.DS_Store
4 changes: 2 additions & 2 deletions .rspec
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
--format documentation
--color
--order random
--require spec_helper
--format documentation
--order random
2 changes: 2 additions & 0 deletions football_api.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions spec/sideline_spec.rb
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions spec/support/json_responses/sidelined.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
}
37 changes: 37 additions & 0 deletions spec/support/json_responses/trophies.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
}
25 changes: 25 additions & 0 deletions spec/trophey_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 82b3818

Please sign in to comment.