Skip to content

Commit

Permalink
Merge pull request #45 from esaio/add-specs-for-headers
Browse files Browse the repository at this point in the history
Add specs for default_headers
  • Loading branch information
fukayatsu authored Jan 20, 2020
2 parents 698ec93 + 82d5f15 commit eb6f487
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 14 deletions.
1 change: 0 additions & 1 deletion esa.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'pry', '~> 0.12'
spec.add_development_dependency 'rake', '~> 13.0'
spec.add_development_dependency 'rspec', '~> 3.9'
spec.add_development_dependency 'vcr', '~> 5.0.0'
spec.add_development_dependency 'webmock', '~> 3.7.6'
end
64 changes: 59 additions & 5 deletions spec/esa/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
let(:access_token) { nil }
let(:api_endpoint) { nil }
let(:current_team) { nil }
let(:default_headers) { {} }
let(:options) do
{
access_token: access_token,
api_endpoint: api_endpoint,
current_team: current_team,
default_headers: default_headers
}
end
subject(:client) { described_class.new(**options) }
Expand Down Expand Up @@ -42,9 +44,61 @@
end
end

# describe "#send_request", :vcr do
# it 'returns Esa::Response' do
# expect(client.teams).to be_a Esa::Response
# end
# end
describe 'default_headers' do
before do
stub_request(:any, 'https://api.esa.io/v1/teams')
.to_return do |request|
{
body: request.body,
headers: request.headers
}
end
end

context 'no default_headers option' do
it 'request with basic headers' do
response = client.teams
expect(response.headers).to eq(
'Accept' => 'application/json',
'User-Agent' => "Esa Ruby Gem #{Esa::VERSION}",
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3'
)
end

it 'request with basic headers and additional headers ' do
response = client.teams(nil, { 'X-Foo' => 'bar' })
expect(response.headers).to eq(
'Accept' => 'application/json',
'User-Agent' => "Esa Ruby Gem #{Esa::VERSION}",
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'X-Foo' => 'bar'
)
end
end

context 'with default_headers option' do
let(:default_headers) { { 'X-Default-Foo' => 'Bar' } }

it 'request with basic headers and default_headers' do
response = client.teams
expect(response.headers).to eq(
'Accept' => 'application/json',
'User-Agent' => "Esa Ruby Gem #{Esa::VERSION}",
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'X-Default-Foo' => 'Bar'
)
end

it 'request with basic headers and additional headers ' do
response = client.teams(nil, { 'X-Foo' => 'baz', 'X-Default-Foo' => 'qux' })
expect(response.headers).to eq(
'Accept' => 'application/json',
'User-Agent' => "Esa Ruby Gem #{Esa::VERSION}",
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'X-Default-Foo' => 'qux',
'X-Foo' => 'baz'
)
end
end
end
end
8 changes: 0 additions & 8 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require 'esa'
require 'webmock/rspec'
require 'vcr'

# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
RSpec.configure do |config|
Expand All @@ -26,10 +25,3 @@
config.order = :random
Kernel.srand config.seed
end

VCR.configure do |c|
c.cassette_library_dir = 'spec/cassettes'
c.hook_into :webmock
c.configure_rspec_metadata!
c.filter_sensitive_data('<ACCESS_TOKEN>') { ENV['ESA_ACCESS_TOKEN'] }
end

0 comments on commit eb6f487

Please sign in to comment.