Skip to content

Commit

Permalink
Allow to stub error codes without changing the helper too much
Browse files Browse the repository at this point in the history
  • Loading branch information
dmacvicar committed Feb 20, 2018
1 parent a956ed0 commit 0aff171
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@
class ActiveSupport::TestCase
# Helper to associate queries to OBS with the corresponding file in
# test/support
def stub_content(url, body)
def stub_content(url, what = {})
what = { body: what } if what.is_a?(String)
%w[http https].each do |protocol|
stub = stub_request(:any, "#{protocol}://#{url}").to_return(body: body)
stub = stub_request(:any, "#{protocol}://#{url}").to_return(what)
stub.with(basic_auth: ['test', 'test']) if url =~ /^api/
end
end

def stub_remote_file(url, filename)
stub_content(url, File.read(Rails.root.join('test', 'support', filename)))
stub_content(url, body: File.read(Rails.root.join('test', 'support', filename)))
end

setup do
Expand Down

0 comments on commit 0aff171

Please sign in to comment.