Skip to content

Commit

Permalink
chore: update spec tests
Browse files Browse the repository at this point in the history
  • Loading branch information
saiqulhaq committed Jan 22, 2022
1 parent e1fc05a commit 995313a
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Set up Ruby
uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
with:
ruby-version: 2.7
ruby-version: 3.0
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
- name: Install cc-test-reporter and prebuild notification
run: |
Expand Down
134 changes: 89 additions & 45 deletions spec/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,42 @@ def post(*)

describe '#shorten_link' do
shared_examples 'short link created correctly' do |api_key_location|
it 'shorten link correctly' do
link = 'http://saiqulhaq.com'
VCR.use_cassette("shorten_link-SHORT-#{ENV['BUNDLE_GEMFILE']}-#{api_key_location}") do
options = { suffix_option: 'SHORT' }
result = subject.shorten_link(link, options)
expect(result[:link]).not_to eq('')
expect(result[:link]).not_to eq(link)
context 'when faraday default adapter is not defined' do
it 'raises error' do
if FirebaseDynamicLink::USE_FARADAY_2
Faraday.default_adapter = nil

link = 'http://saiqulhaq.com'
options = { suffix_option: 'SHORT' }
expect {
subject.shorten_link(link, options)
}.to raise_error
else
expect(true).to be_truthy
end
end
end

context 'when faraday default adapter is defined' do
before do
Faraday.default_adapter = :net_http if FirebaseDynamicLink::USE_FARADAY_2
end

VCR.use_cassette("shorten_link-UNGUESSABLE-#{ENV['BUNDLE_GEMFILE']}-#{api_key_location}") do
options = { suffix_option: 'UNGUESSABLE', timout: 5 }
result = subject.shorten_link(link, options)
expect(result[:link]).not_to eq('')
expect(result[:link]).not_to eq(link)
it 'shorten link correctly' do
link = 'http://saiqulhaq.com'
VCR.use_cassette("shorten_link-SHORT-#{ENV['BUNDLE_GEMFILE']}-#{api_key_location}") do
options = { suffix_option: 'SHORT' }
result = subject.shorten_link(link, options)
expect(result[:link]).not_to eq('')
expect(result[:link]).not_to eq(link)
end

VCR.use_cassette("shorten_link-UNGUESSABLE-#{ENV['BUNDLE_GEMFILE']}-#{api_key_location}") do
options = { suffix_option: 'UNGUESSABLE', timout: 5 }
result = subject.shorten_link(link, options)
expect(result[:link]).not_to eq('')
expect(result[:link]).not_to eq(link)
end
end
end
end
Expand Down Expand Up @@ -112,46 +134,68 @@ def post(*)
}
end

it 'shorten link correctly' do
VCR.use_cassette("shorten_parameters-SHORT-#{ENV['BUNDLE_GEMFILE']}") do
options = {
suffix_option: 'SHORT'
# dynamic_link_domain: 'foo' # optional
}
context 'when faraday default adapter is not defined' do
it 'raises error' do
if FirebaseDynamicLink::USE_FARADAY_2
Faraday.default_adapter = nil

expect do
result = subject.shorten_parameters(parameters, options)
expect(result[:link]).not_to eq('')
expect(result[:link]).not_to eq(link)
end.not_to raise_error
link = 'http://saiqulhaq.com'
options = { suffix_option: 'SHORT' }
expect {
subject.shorten_parameters(parameters, options)
}.to raise_error
else
expect(true).to be_truthy
end
end
end

VCR.use_cassette("shorten_parameters-UNGUESSABLE-#{ENV['BUNDLE_GEMFILE']}") do
options = {
suffix_option: 'UNGUESSABLE'
# dynamic_link_domain: 'foo' # optional
}
context 'when faraday default adapter is defined' do
before do
Faraday.default_adapter = :net_http if FirebaseDynamicLink::USE_FARADAY_2
end

expect do
result = subject.shorten_parameters(parameters, options)
expect(result[:link]).not_to eq('')
expect(result[:link]).not_to eq(link)
end.not_to raise_error
it 'shorten link correctly' do
VCR.use_cassette("shorten_parameters-SHORT-#{ENV['BUNDLE_GEMFILE']}") do
options = {
suffix_option: 'SHORT'
# dynamic_link_domain: 'foo' # optional
}

expect do
result = subject.shorten_parameters(parameters, options)
expect(result[:link]).not_to eq('')
expect(result[:link]).not_to eq(link)
end.not_to raise_error
end

VCR.use_cassette("shorten_parameters-UNGUESSABLE-#{ENV['BUNDLE_GEMFILE']}") do
options = {
suffix_option: 'UNGUESSABLE'
# dynamic_link_domain: 'foo' # optional
}

expect do
result = subject.shorten_parameters(parameters, options)
expect(result[:link]).not_to eq('')
expect(result[:link]).not_to eq(link)
end.not_to raise_error
end
end
end

it 'raise FirebaseDynamicLink::ConnectionError if Faraday::ConnectionFailed raised' do
allow_any_instance_of(described_class).to receive(:connection).and_return(connection_failed_class.new)
expect do
subject.shorten_parameters(parameters)
end.to raise_error(FirebaseDynamicLink::ConnectionError)
end
it 'raise FirebaseDynamicLink::ConnectionError if Faraday::ConnectionFailed raised' do
allow_any_instance_of(described_class).to receive(:connection).and_return(connection_failed_class.new)
expect do
subject.shorten_parameters(parameters)
end.to raise_error(FirebaseDynamicLink::ConnectionError)
end

it 'raise FirebaseDynamicLink::ConnectionError if Faraday::TimeoutError raised' do
allow_any_instance_of(described_class).to receive(:connection).and_return(timout_error_class.new)
expect do
subject.shorten_link(parameters)
end.to raise_error(FirebaseDynamicLink::ConnectionError)
it 'raise FirebaseDynamicLink::ConnectionError if Faraday::TimeoutError raised' do
allow_any_instance_of(described_class).to receive(:connection).and_return(timout_error_class.new)
expect do
subject.shorten_parameters(parameters)
end.to raise_error(FirebaseDynamicLink::ConnectionError)
end
end
end
end
4 changes: 4 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ module FirebaseDynamicLink
config.expect_with :rspec do |c|
c.syntax = :expect
end

config.after(:each) do
Faraday.default_connection = nil
end
end

VCR.configure do |config|
Expand Down

0 comments on commit 995313a

Please sign in to comment.