diff --git a/Brewfile b/Brewfile index be87f11be92f..dc23f8cdcf17 100644 --- a/Brewfile +++ b/Brewfile @@ -2,5 +2,3 @@ tap "github/bootstrap" brew "rbenv" brew "ruby-build" - -brew "imagemagick" diff --git a/Gemfile b/Gemfile index e6a3f1f7973c..8e5218d6b7ad 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,7 @@ source "https://rubygems.org" group :test do + gem "fastimage", "~> 2.1.0" gem "minitest", "~> 5.10.3" gem "rake" gem "rubocop", "~> 0.50.0" diff --git a/Gemfile.lock b/Gemfile.lock index 0b30e41424f8..986b8ed94a6a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,6 +2,7 @@ GEM remote: https://rubygems.org/ specs: ast (2.3.0) + fastimage (2.1.0) minitest (5.10.3) parallel (1.12.0) parser (2.4.0.0) @@ -25,10 +26,11 @@ PLATFORMS ruby DEPENDENCIES + fastimage (~> 2.1.0) minitest (~> 5.10.3) rake rubocop (~> 0.50.0) safe_yaml (~> 1.0.4) BUNDLED WITH - 1.15.3 + 1.15.4 diff --git a/README.md b/README.md index 66181b8ac593..b6aeb4f486ec 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,11 @@ Curated topics and collections from the community ## How to Run Tests -There are some lint tests in place to ensure each topic is formatted in the way we expect. You can -run the tests using: +There are some lint tests in place to ensure each topic is formatted in the way we expect. Travis +CI will run the tests automatically. If you want to run the tests yourself locally, you will need +Ruby, Bundler, and ImageMagick installed. + +You can run the tests using: ```bash ./script/cibuild diff --git a/test/test_helper.rb b/test/test_helper.rb index 6e96d95d9779..a8311a2a01ed 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,11 +1,13 @@ require "minitest/autorun" +require "fastimage" require "yaml" IMAGE_EXTENSIONS = %w[.jpg .jpeg .png].freeze - +IMAGE_WIDTH = 288 +IMAGE_HEIGHT = 288 +MAX_IMAGE_FILESIZE_IN_BYTES = 65_000 VALID_METADATA_KEYS = %w[aliases created_by display_name github_url logo related released short_description topic url wikipedia_url].freeze - REQUIRED_METADATA_KEYS = %w[topic short_description].freeze def topics_dir diff --git a/test/topics_test.rb b/test/topics_test.rb index 94c29a73edb4..af0daa1ff001 100644 --- a/test/topics_test.rb +++ b/test/topics_test.rb @@ -9,7 +9,7 @@ assert File.file?(path), "expected #{path} to be a file" end - it "has only one image with the right name" do + it "has at most one image with the right name, type, and dimensions" do paths = image_paths_for(topic) assert paths.size <= 1, "expected at most one image, found #{paths.size}" @@ -17,6 +17,18 @@ if path = paths.first assert_equal topic, File.basename(path, File.extname(path)), "expected image to be named [topic].[extension]" + + width, height = FastImage.size(path) + assert_equal IMAGE_WIDTH, width, "topic images should be #{IMAGE_WIDTH}px wide" + assert_equal IMAGE_HEIGHT, height, "topic images should be #{IMAGE_HEIGHT}px tall" + + assert_includes IMAGE_EXTENSIONS, ".#{FastImage.type(path)}", + "topic images should be one of #{IMAGE_EXTENSIONS.join(', ')}" + + file_size = FastImage.new(path).content_length + assert file_size <= MAX_IMAGE_FILESIZE_IN_BYTES, + "topic images should not exceed #{MAX_IMAGE_FILESIZE_IN_BYTES} bytes, got " \ + "#{file_size} bytes" end end diff --git a/topics/bitcoin/bitcoin.png b/topics/bitcoin/bitcoin.png index bf3ebe1b3f44..75c01c7ab232 100644 Binary files a/topics/bitcoin/bitcoin.png and b/topics/bitcoin/bitcoin.png differ