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
27 changes: 27 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
AllCops:
TargetRubyVersion: 2.4
Exclude:
- '**/bin/**/*'
- '**/db/**/*'
- '**/script/setup'
- '**/vendor/**/*'

Lint/AssignmentInCondition:
Enabled: false

Metrics/BlockLength:
Enabled: false

Metrics/LineLength:
Max: 100
IgnoredPatterns: ['\A\s*#']

Style/FrozenStringLiteralComment:
Enabled: false

Style/StringLiterals:
EnforcedStyle: double_quotes

Style/TrailingCommaInLiteral:
EnforcedStyleForMultiline: consistent_comma

1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.4.1
12 changes: 5 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
language: ruby
cache: bundler
sudo: false
install:
- bundle install
notifications:
email: false
script: rake
cache:
bundler: true
bundler_args: --jobs=3 --retry=3
before_install: ./script/setup
script: ./script/cibuild
6 changes: 6 additions & 0 deletions Brewfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
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
Expand Up @@ -3,5 +3,6 @@ source "https://rubygems.org"
group :test do
gem "minitest", "~> 5.10.3"
gem "rake"
gem "rubocop", "~> 0.50.0"
gem "safe_yaml", "~> 1.0.4"
end
17 changes: 17 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
GEM
remote: https://rubygems.org/
specs:
ast (2.3.0)
minitest (5.10.3)
parallel (1.12.0)
parser (2.4.0.0)
ast (~> 2.2)
powerpack (0.1.1)
rainbow (2.2.2)
rake
rake (12.0.0)
rubocop (0.50.0)
parallel (~> 1.10)
parser (>= 2.3.3.1, < 3.0)
powerpack (~> 0.1)
rainbow (>= 2.2.2, < 3.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.9.0)
safe_yaml (1.0.4)
unicode-display_width (1.3.0)

PLATFORMS
ruby

DEPENDENCIES
minitest (~> 5.10.3)
rake
rubocop (~> 0.50.0)
safe_yaml (~> 1.0.4)

BUNDLED WITH
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ There are some lint tests in place to ensure each topic is formatted in the way
run the tests using:

```bash
bundle install
rake
./script/cibuild
```
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ Rake::TestTask.new do |t|
t.verbose = false
end

task :default => :test
task default: :test
14 changes: 14 additions & 0 deletions script/cibuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
set -e

cd "$(dirname "$0")/.."

./script/setup

set +e
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why does this get run again after line 2?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

To allow not failing immediately if rake test fails but also outputting the rubocop failure output (if any)


bundle exec rake test
RAKE_EXIT="$?"
bundle exec rubocop --display-cop-names
RUBOCOP_EXIT="$?"
[[ "$RAKE_EXIT" == 0 && "$RUBOCOP_EXIT" == 0 ]]
11 changes: 11 additions & 0 deletions script/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
set -e

cd "$(dirname "$0")/.."

if [ "$(uname -s)" = "Darwin" ]; then
brew bundle check &>/dev/null || brew bundle
rbenv version-name &>/dev/null || brew bootstrap-rbenv-ruby
fi

bundle check &>/dev/null || bundle install
12 changes: 6 additions & 6 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
require "minitest/autorun"
require "yaml"

IMAGE_EXTENSIONS = [".jpg", ".jpeg", ".png"].freeze
IMAGE_EXTENSIONS = %w[.jpg .jpeg .png].freeze

VALID_METADATA_KEYS = ["aliases", "created_by", "display_name", "github_url", "logo", "related",
"released", "short_description", "topic", "url", "wikipedia_url"].freeze
VALID_METADATA_KEYS = %w[aliases created_by display_name github_url logo related
released short_description topic url wikipedia_url].freeze

REQUIRED_METADATA_KEYS = ["topic", "short_description"].freeze
REQUIRED_METADATA_KEYS = %w[topic short_description].freeze

def topics_dir
File.expand_path("../topics", File.dirname(__FILE__))
Expand Down Expand Up @@ -39,8 +39,8 @@ def metadata_for(topic)
parts = File.read(path).split("---", 3)
return unless parts.size >= 2

metadata = begin
YAML.load(parts[1])
begin
YAML.safe_load(parts[1])
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Today Rubocop Autocorrected For Me 😜

rescue Psych::SyntaxError => ex
flunk "invalid YAML: #{ex.message}"
end
Expand Down
10 changes: 5 additions & 5 deletions test/topics_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

if path = paths.first
assert_equal topic, File.basename(path, File.extname(path)),
"expected image to be named [topic].[extension]"
"expected image to be named [topic].[extension]"
end
end

Expand All @@ -38,7 +38,7 @@
if File.file?(path)
lines = File.readlines(path)

assert lines.size > 0
refute lines.empty?
assert_equal "---\n", lines[0], "expected file to start with Jekyll front matter ---"

end_index = lines.slice(1..-1).index("---\n")
Expand All @@ -50,14 +50,14 @@
metadata = metadata_for(topic)
refute_empty metadata, "expected some metadata for topic"

metadata.each do |key, value|
metadata.each_key do |key|
assert_includes VALID_METADATA_KEYS, key, "unexpected metadata key '#{key}'"
end

REQUIRED_METADATA_KEYS.each do |key|
assert metadata.key?(key), "expected to have '#{key}' defined for topic"
assert metadata[key] && metadata[key].strip.size > 0,
"expected to have a value for '#{key}'"
assert metadata[key]&.strip&.size&.positive?,
"expected to have a value for '#{key}'"
end
end
end
Expand Down