Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Brewfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,3 @@ tap "github/bootstrap"

brew "rbenv"
brew "ruby-build"

brew "imagemagick"
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
4 changes: 3 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: add a Brewfile for imagemagick and follow the https://github.com/github/scripts-to-rule-them-all pattern to allow running tests with a single command.


You can run the tests using:

```bash
./script/cibuild
Expand Down
6 changes: 4 additions & 2 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
14 changes: 13 additions & 1 deletion test/topics_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,26 @@
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}"

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

Expand Down
Binary file modified topics/bitcoin/bitcoin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.