From c891d749bc4dbaf621cf7afeb70c3d08178df098 Mon Sep 17 00:00:00 2001 From: Koza Date: Wed, 12 Apr 2023 19:54:44 +0200 Subject: Mock out external image requests to make the CI more stable --- Gemfile | 1 + test/drawing/tc_pic.rb | 5 ++++- test/tc_helper.rb | 1 + test/util/tc_mime_type_utils.rb | 5 ++++- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 432b4503..fb69c977 100644 --- a/Gemfile +++ b/Gemfile @@ -9,6 +9,7 @@ group :test do gem 'rake' gem 'simplecov', '>= 0.14.1' gem 'test-unit' + gem 'webmock' end group :profile do diff --git a/test/drawing/tc_pic.rb b/test/drawing/tc_pic.rb index 34f24eb3..21d3f931 100644 --- a/test/drawing/tc_pic.rb +++ b/test/drawing/tc_pic.rb @@ -2,13 +2,16 @@ require 'tc_helper.rb' class TestPic < Test::Unit::TestCase def setup + stub_request(:get, 'https://example.com/sample-image.png') + .to_return(body: File.new('examples/sample.png'), status: 200) + @p = Axlsx::Package.new ws = @p.workbook.add_worksheet @test_img = @test_img_jpg = File.dirname(__FILE__) + "/../fixtures/image1.jpeg" @test_img_png = File.dirname(__FILE__) + "/../fixtures/image1.png" @test_img_gif = File.dirname(__FILE__) + "/../fixtures/image1.gif" @test_img_fake = File.dirname(__FILE__) + "/../fixtures/image1_fake.jpg" - @test_img_remote_png = "https://via.placeholder.com/150.png" + @test_img_remote_png = "https://example.com/sample-image.png" @test_img_remote_fake = "invalid_URI" @image = ws.add_image :image_src => @test_img, :hyperlink => 'https://github.com/randym', :tooltip => "What's up doc?", :opacity => 5 @image_remote = ws.add_image :image_src => @test_img_remote_png, remote: true, :hyperlink => 'https://github.com/randym', :tooltip => "What's up doc?", :opacity => 5 diff --git a/test/tc_helper.rb b/test/tc_helper.rb index af40a1e4..fb85870a 100644 --- a/test/tc_helper.rb +++ b/test/tc_helper.rb @@ -7,4 +7,5 @@ end require 'test/unit' require "timecop" +require 'webmock/test_unit' require "axlsx.rb" diff --git a/test/util/tc_mime_type_utils.rb b/test/util/tc_mime_type_utils.rb index 9d116931..52c49e2e 100644 --- a/test/util/tc_mime_type_utils.rb +++ b/test/util/tc_mime_type_utils.rb @@ -1,8 +1,11 @@ require 'tc_helper.rb' class TestMimeTypeUtils < Test::Unit::TestCase def setup + stub_request(:get, 'https://example.com/sample-image.png') + .to_return(body: File.new('examples/sample.png'), status: 200) + @test_img = File.dirname(__FILE__) + "/../fixtures/image1.jpeg" - @test_img_url = "https://via.placeholder.com/150.png" + @test_img_url = "https://example.com/sample-image.png" end def teardown -- cgit v1.2.3