From 740285471c4f233256be3ece1934640a251a88dd Mon Sep 17 00:00:00 2001 From: Sarah Vessels Date: Thu, 28 Sep 2017 15:03:27 -0500 Subject: [PATCH 01/20] Add minitest gem --- Gemfile | 5 +++++ Gemfile.lock | 13 +++++++++++++ test/test_helper.rb | 1 + 3 files changed, 19 insertions(+) create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100644 test/test_helper.rb diff --git a/Gemfile b/Gemfile new file mode 100644 index 000000000000..da338771a262 --- /dev/null +++ b/Gemfile @@ -0,0 +1,5 @@ +source "https://rubygems.org" + +group :test do + gem "minitest", "~> 5.10.3" +end diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 000000000000..c1f2ff097fdd --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,13 @@ +GEM + remote: https://rubygems.org/ + specs: + minitest (5.10.3) + +PLATFORMS + ruby + +DEPENDENCIES + minitest (~> 5.10.3) + +BUNDLED WITH + 1.15.3 diff --git a/test/test_helper.rb b/test/test_helper.rb new file mode 100644 index 000000000000..9a4ca351c9d3 --- /dev/null +++ b/test/test_helper.rb @@ -0,0 +1 @@ +require "minitest/autorun" From 7d30785ff75e8433f0743d831d06e53587d51305 Mon Sep 17 00:00:00 2001 From: Sarah Vessels Date: Thu, 28 Sep 2017 15:08:40 -0500 Subject: [PATCH 02/20] Setup Rake to run tests --- Gemfile | 1 + Gemfile.lock | 2 ++ Rakefile | 10 ++++++++++ 3 files changed, 13 insertions(+) create mode 100644 Rakefile diff --git a/Gemfile b/Gemfile index da338771a262..67714d14b54b 100644 --- a/Gemfile +++ b/Gemfile @@ -2,4 +2,5 @@ source "https://rubygems.org" group :test do gem "minitest", "~> 5.10.3" + gem "rake" end diff --git a/Gemfile.lock b/Gemfile.lock index c1f2ff097fdd..d5b5923e62fa 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,12 +2,14 @@ GEM remote: https://rubygems.org/ specs: minitest (5.10.3) + rake (12.0.0) PLATFORMS ruby DEPENDENCIES minitest (~> 5.10.3) + rake BUNDLED WITH 1.15.3 diff --git a/Rakefile b/Rakefile new file mode 100644 index 000000000000..172685d948c2 --- /dev/null +++ b/Rakefile @@ -0,0 +1,10 @@ +require "rake/testtask" + +Rake::TestTask.new do |t| + t.libs << "test" + t.test_files = FileList["test/*_test.rb"] + t.warning = false + t.verbose = false +end + +task :default => :test From d37e78c87c3502212e915e6e1ef9d6bd1e0ddad3 Mon Sep 17 00:00:00 2001 From: Sarah Vessels Date: Thu, 28 Sep 2017 15:11:37 -0500 Subject: [PATCH 03/20] Test each topic has an index.md --- test/test_helper.rb | 14 ++++++++++++++ test/topics_test.rb | 13 +++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 test/topics_test.rb diff --git a/test/test_helper.rb b/test/test_helper.rb index 9a4ca351c9d3..4d33f27abf21 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1 +1,15 @@ require "minitest/autorun" + +def topics_dir + File.expand_path("../topics", File.dirname(__FILE__)) +end + +def topic_dirs + @topic_dirs ||= Dir["#{topics_dir}/*"].select do |entry| + entry != "." && entry != ".." && File.directory?(entry) + end +end + +def topics + @topics ||= topic_dirs.map { |dir_path| File.basename(dir_path) } +end diff --git a/test/topics_test.rb b/test/topics_test.rb new file mode 100644 index 000000000000..170bd2237352 --- /dev/null +++ b/test/topics_test.rb @@ -0,0 +1,13 @@ +require_relative "./test_helper" + +describe "topics" do + topics.each do |topic| + describe "#{topic} topic" do + it "has an index.md" do + path = File.join(topics_dir, topic, "index.md") + + assert File.file?(path), "expected #{path} to be a file" + end + end + end +end From f46ad4a15af0b8d73b37f5413ccb16db9a265965 Mon Sep 17 00:00:00 2001 From: Sarah Vessels Date: Thu, 28 Sep 2017 15:24:25 -0500 Subject: [PATCH 04/20] Add Travis CI config file --- .travis.yml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 000000000000..0d826c7e2145 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,8 @@ +sudo: false +install: + - bundle install +notifications: + email: false +script: rake +cache: + bundler: true From a52cd024c1a2a41325bb97abe85c5eb1d0c7ca6b Mon Sep 17 00:00:00 2001 From: Sarah Vessels Date: Thu, 28 Sep 2017 15:34:51 -0500 Subject: [PATCH 05/20] Test at most one image with the right name --- test/test_helper.rb | 8 ++++++++ test/topics_test.rb | 11 +++++++++++ 2 files changed, 19 insertions(+) diff --git a/test/test_helper.rb b/test/test_helper.rb index 4d33f27abf21..03e2fee328df 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -13,3 +13,11 @@ def topic_dirs def topics @topics ||= topic_dirs.map { |dir_path| File.basename(dir_path) } end + +IMAGE_EXTENSIONS = [".jpg", ".jpeg", ".png"] + +def image_paths_for(topic) + Dir["#{topics_dir}/#{topic}/*"].select do |entry| + File.file?(entry) && IMAGE_EXTENSIONS.include?(File.extname(entry).downcase) + end +end diff --git a/test/topics_test.rb b/test/topics_test.rb index 170bd2237352..57066ba511fa 100644 --- a/test/topics_test.rb +++ b/test/topics_test.rb @@ -8,6 +8,17 @@ assert File.file?(path), "expected #{path} to be a file" end + + it "has only one image with the right name" 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]" + end + end end end end From 587c7dbf850cb24e50cb93b57c3b12ac2b797941 Mon Sep 17 00:00:00 2001 From: Sarah Vessels Date: Thu, 28 Sep 2017 15:38:53 -0500 Subject: [PATCH 06/20] Ensure no extra files or directories --- test/test_helper.rb | 4 ++++ test/topics_test.rb | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/test/test_helper.rb b/test/test_helper.rb index 03e2fee328df..72032513a38d 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -21,3 +21,7 @@ def image_paths_for(topic) File.file?(entry) && IMAGE_EXTENSIONS.include?(File.extname(entry).downcase) end end + +def possible_image_file_names_for(topic) + IMAGE_EXTENSIONS.map { |ext| "#{topic}#{ext}" } +end diff --git a/test/topics_test.rb b/test/topics_test.rb index 57066ba511fa..76b57fdd6b62 100644 --- a/test/topics_test.rb +++ b/test/topics_test.rb @@ -19,6 +19,18 @@ "expected image to be named [topic].[extension]" end end + + it "has no unexpected files or directories" do + files = Dir["#{topics_dir}/#{topic}/**/*"].reject do |entry| + file_name = File.basename(entry) + image_files = possible_image_file_names_for(topic) + + entry == "." || entry == ".." || file_name == "index.md" || + image_files.include?(file_name) + end + + assert_empty files, "expected only index.md and a single image" + end end end end From ddcd119ffe25bb92f8099909fa3a83dcb0de7842 Mon Sep 17 00:00:00 2001 From: Sarah Vessels Date: Thu, 28 Sep 2017 15:47:54 -0500 Subject: [PATCH 07/20] Ensure front matter is in each index.md --- test/topics_test.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/topics_test.rb b/test/topics_test.rb index 76b57fdd6b62..71b663a78428 100644 --- a/test/topics_test.rb +++ b/test/topics_test.rb @@ -31,6 +31,20 @@ assert_empty files, "expected only index.md and a single image" end + + it "has Jekyll front matter in index.md" do + path = File.join(topics_dir, topic, "index.md") + + if File.file?(path) + lines = File.readlines(path) + + assert lines.size > 0 + assert_equal "---\n", lines[0], "expected file to start with Jekyll front matter ---" + + end_index = lines.slice(1..-1).index("---\n") + assert end_index, "expected Jekyll front matter to end with ---" + end + end end end end From 4a5855abf1394cc75c33ae933cb1168a2679d692 Mon Sep 17 00:00:00 2001 From: Sarah Vessels Date: Thu, 28 Sep 2017 16:03:59 -0500 Subject: [PATCH 08/20] Validate Jekyll front matter in Markdown --- Gemfile | 1 + Gemfile.lock | 2 ++ test/test_helper.rb | 24 ++++++++++++++++++++++-- test/topics_test.rb | 15 +++++++++++++++ 4 files changed, 40 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 67714d14b54b..1c1c0e181f12 100644 --- a/Gemfile +++ b/Gemfile @@ -3,4 +3,5 @@ source "https://rubygems.org" group :test do gem "minitest", "~> 5.10.3" gem "rake" + gem "safe_yaml", "~> 1.0.4" end diff --git a/Gemfile.lock b/Gemfile.lock index d5b5923e62fa..052618af6259 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -3,6 +3,7 @@ GEM specs: minitest (5.10.3) rake (12.0.0) + safe_yaml (1.0.4) PLATFORMS ruby @@ -10,6 +11,7 @@ PLATFORMS DEPENDENCIES minitest (~> 5.10.3) rake + safe_yaml (~> 1.0.4) BUNDLED WITH 1.15.3 diff --git a/test/test_helper.rb b/test/test_helper.rb index 72032513a38d..55447b3068e2 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,4 +1,12 @@ require "minitest/autorun" +require "yaml" + +IMAGE_EXTENSIONS = [".jpg", ".jpeg", ".png"].freeze + +VALID_METADATA_KEYS = ["aliases", "created_by", "display_name", "github_url", "logo", "related", + "released", "short_description", "topic", "url", "wikipedia_url"].freeze + +REQUIRED_METADATA_KEYS = ["topic", "short_description"].freeze def topics_dir File.expand_path("../topics", File.dirname(__FILE__)) @@ -14,8 +22,6 @@ def topics @topics ||= topic_dirs.map { |dir_path| File.basename(dir_path) } end -IMAGE_EXTENSIONS = [".jpg", ".jpeg", ".png"] - def image_paths_for(topic) Dir["#{topics_dir}/#{topic}/*"].select do |entry| File.file?(entry) && IMAGE_EXTENSIONS.include?(File.extname(entry).downcase) @@ -25,3 +31,17 @@ def image_paths_for(topic) def possible_image_file_names_for(topic) IMAGE_EXTENSIONS.map { |ext| "#{topic}#{ext}" } end + +def metadata_for(topic) + path = File.join(topics_dir, topic, "index.md") + return unless File.file?(path) + + parts = File.read(path).split("---", 3) + return unless parts.size >= 2 + + metadata = begin + YAML.load(parts[1]) + rescue Psych::SyntaxError => ex + flunk "invalid YAML: #{ex.message}" + end +end diff --git a/test/topics_test.rb b/test/topics_test.rb index 71b663a78428..107a6e566a1e 100644 --- a/test/topics_test.rb +++ b/test/topics_test.rb @@ -45,6 +45,21 @@ assert end_index, "expected Jekyll front matter to end with ---" end end + + it "has expected metadata in Jekyll front matter" do + metadata = metadata_for(topic) + refute_empty metadata, "expected some metadata for topic" + + metadata.each do |key, value| + 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}'" + end + end end end end From 4fb3c089bd8e693dcec0186ab4bd6ce7e9e3e5ee Mon Sep 17 00:00:00 2001 From: Sarah Vessels Date: Thu, 28 Sep 2017 16:08:52 -0500 Subject: [PATCH 09/20] =?UTF-8?q?Was=20this=20memoization=20even=20doing?= =?UTF-8?q?=20anything=3F=20=F0=9F=A4=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/test_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index 55447b3068e2..1911b181321b 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -13,13 +13,13 @@ def topics_dir end def topic_dirs - @topic_dirs ||= Dir["#{topics_dir}/*"].select do |entry| + Dir["#{topics_dir}/*"].select do |entry| entry != "." && entry != ".." && File.directory?(entry) end end def topics - @topics ||= topic_dirs.map { |dir_path| File.basename(dir_path) } + topic_dirs.map { |dir_path| File.basename(dir_path) } end def image_paths_for(topic) From 9da358079167717eafbb82f5d06026089978071d Mon Sep 17 00:00:00 2001 From: Sarah Vessels Date: Thu, 28 Sep 2017 16:10:58 -0500 Subject: [PATCH 10/20] Update readme about tests --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 225355792726..2645d371e7ff 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,12 @@ # explore 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: + +```bash +bundle install +rake +``` From 7ce507710018d3368b13f3c29820bfb061cdca24 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Tue, 3 Oct 2017 17:27:24 +0100 Subject: [PATCH 11/20] Add Rubocop and sensible default rules. --- .rubocop.yml | 27 +++++++++++++++++++++++++++ Gemfile | 1 + Gemfile.lock | 17 +++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 .rubocop.yml diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 000000000000..78bc878098f2 --- /dev/null +++ b/.rubocop.yml @@ -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 + diff --git a/Gemfile b/Gemfile index 1c1c0e181f12..e6a3f1f7973c 100644 --- a/Gemfile +++ b/Gemfile @@ -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 diff --git a/Gemfile.lock b/Gemfile.lock index 052618af6259..0b30e41424f8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,9 +1,25 @@ 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 @@ -11,6 +27,7 @@ PLATFORMS DEPENDENCIES minitest (~> 5.10.3) rake + rubocop (~> 0.50.0) safe_yaml (~> 1.0.4) BUNDLED WITH From a9d13ec1377b405d1f9d7d872e48c1f95242b198 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Tue, 3 Oct 2017 17:28:18 +0100 Subject: [PATCH 12/20] Fix all Rubocop warnings. --- Rakefile | 2 +- test/test_helper.rb | 12 ++++++------ test/topics_test.rb | 12 +++++++----- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/Rakefile b/Rakefile index 172685d948c2..5dfa61083876 100644 --- a/Rakefile +++ b/Rakefile @@ -7,4 +7,4 @@ Rake::TestTask.new do |t| t.verbose = false end -task :default => :test +task default: :test diff --git a/test/test_helper.rb b/test/test_helper.rb index 1911b181321b..036d9710f7cd 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -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__)) @@ -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]) rescue Psych::SyntaxError => ex flunk "invalid YAML: #{ex.message}" end diff --git a/test/topics_test.rb b/test/topics_test.rb index 107a6e566a1e..2f828c84d7bc 100644 --- a/test/topics_test.rb +++ b/test/topics_test.rb @@ -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 @@ -38,7 +38,7 @@ if File.file?(path) lines = File.readlines(path) - assert lines.size > 0 + assert !lines.empty? assert_equal "---\n", lines[0], "expected file to start with Jekyll front matter ---" end_index = lines.slice(1..-1).index("---\n") @@ -50,14 +50,16 @@ 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 end end From e86b48a48a64b546d1870c220819d71c17c826c3 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Tue, 3 Oct 2017 17:29:13 +0100 Subject: [PATCH 13/20] Use scripts-to-rule-them-all format --- .ruby-version | 1 + .travis.yml | 12 +++++------- Brewfile | 6 ++++++ README.md | 3 +-- script/cibuild | 14 ++++++++++++++ script/setup | 11 +++++++++++ 6 files changed, 38 insertions(+), 9 deletions(-) create mode 100644 .ruby-version create mode 100644 Brewfile create mode 100755 script/cibuild create mode 100755 script/setup diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 000000000000..005119baaa06 --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +2.4.1 diff --git a/.travis.yml b/.travis.yml index 0d826c7e2145..85ff3f8817b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/Brewfile b/Brewfile new file mode 100644 index 000000000000..be87f11be92f --- /dev/null +++ b/Brewfile @@ -0,0 +1,6 @@ +tap "github/bootstrap" + +brew "rbenv" +brew "ruby-build" + +brew "imagemagick" diff --git a/README.md b/README.md index 2645d371e7ff..66181b8ac593 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/script/cibuild b/script/cibuild new file mode 100755 index 000000000000..89bb5f3d4fa7 --- /dev/null +++ b/script/cibuild @@ -0,0 +1,14 @@ +#!/bin/bash +set -e + +cd "$(dirname "$0")/.." + +./script/setup + +set +e + +bundle exec rake test +RAKE_EXIT="$?" +bundle exec rubocop --display-cop-names +RUBOCOP_EXIT="$?" +[[ "$RAKE_EXIT" == 0 && "$RUBOCOP_EXIT" == 0 ]] diff --git a/script/setup b/script/setup new file mode 100755 index 000000000000..2474f498f8c9 --- /dev/null +++ b/script/setup @@ -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 From dc2e13f08cc0e62e7478c09a6f506001f4d341b2 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Tue, 3 Oct 2017 17:35:38 +0100 Subject: [PATCH 14/20] Add Topic Page Style Guide tests --- test/test_helper.rb | 10 +++++++++ test/topics_test.rb | 50 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/test/test_helper.rb b/test/test_helper.rb index 1911b181321b..90b8029ef6cd 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -45,3 +45,13 @@ def metadata_for(topic) flunk "invalid YAML: #{ex.message}" end end + +def text_for(topic) + path = File.join(topics_dir, topic, "index.md") + return "" unless File.file?(path) + + parts = File.read(path).split("---", 3) + return "" unless parts.size >= 2 + + parts[2] +end diff --git a/test/topics_test.rb b/test/topics_test.rb index 107a6e566a1e..5908d2e69a10 100644 --- a/test/topics_test.rb +++ b/test/topics_test.rb @@ -58,6 +58,56 @@ 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}'" + end + + it "follows the Topic Page Style Guide" do + text = text_for(topic) + end_punctuation = %w[. , ; :] + text.lines do |line| + line.chomp! + + refute_includes line, "&", 'Use "and" rather than an ampersand' + refute_includes line, "!", "Avoid exclamation points in topic pages" + refute_includes line, "open-source", + "Use open source without a hyphen" + + %w[Jan Feb Mar Apr Jun Jul Aug Sep Oct Nov Dec].each do |month| + refute_includes line, "#{month} ", "Include and spell out the month" + end + + %w[1st 2nd 3rd 1th 2th 3th 4th 5th 6th 7th 8th 9th].each do |date_end| + refute_includes line, date_end, + 'Include the day number without the "th" or "nd" at the end' + end + + %w[GitHubbing Gitting].each do |no_git_verb| + refute_includes line, no_git_verb, + "Never use “GitHub” or “Git” as a verb." + end + + %w[Github github].each do |wrong_github| + refute_includes line, wrong_github, + 'Always use correct capitalization when referring to "GitHub"' + end + + (end_punctuation + [" "]).each do |punctuation| + refute_includes line, "git#{punctuation}", + 'Always use correct capitalization when referring to "Git"' + + (1..10).each do |digit| + refute_includes line, " #{digit}#{punctuation}", + 'Write out "one" and every number less than 10' + end + end + end + text.delete("\n").split(".").each do |sentence| + # This is arbitrary; 2 is more correct but 3 avoids false positives. + next if sentence.count(",") < 3 + + %w[and or].each do |conjunction| + next unless sentence.include? " #{conjunction} " + assert_includes sentence, ", #{conjunction}", "Always use the Oxford comma" + end end end end From 0f504f6d776bff005811017565b82f7277bea31b Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Tue, 3 Oct 2017 17:35:46 +0100 Subject: [PATCH 15/20] Fix Topic Page Style Guide tests --- topics/csharp/index.md | 2 +- topics/database/index.md | 2 +- topics/gulp/index.md | 2 +- topics/ios/index.md | 2 +- topics/mysql/index.md | 2 +- topics/react-native/index.md | 2 +- topics/redux/index.md | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/topics/csharp/index.md b/topics/csharp/index.md index 8ad07fc78d67..04573f3c1962 100644 --- a/topics/csharp/index.md +++ b/topics/csharp/index.md @@ -9,4 +9,4 @@ topic: csharp url: https://docs.microsoft.com/en-us/dotnet/csharp/csharp wikipedia_url: https://en.wikipedia.org/wiki/C_Sharp_(programming_language) --- -C# is a programming language used for web development. It is a hybrid of C & C++ that functions similar to Java and is meant for Microsoft's .NET framework. +C# is a programming language used for web development. It is a hybrid of C and C++ that functions similar to Java and is meant for Microsoft's .NET framework. diff --git a/topics/database/index.md b/topics/database/index.md index b72448864cba..2a56dc0ad725 100644 --- a/topics/database/index.md +++ b/topics/database/index.md @@ -6,4 +6,4 @@ short_description: A database is a structured set of data held in a computer, us topic: database wikipedia_url: https://en.wikipedia.org/wiki/Database --- -A database is a structured set of data held in a computer, most often a server. Databases use a database management system (DBMS) that interacts with users, similar to a lookup table. Modern databases are designed to allow for creation, querying, updating and administration of the data it holds. +A database is a structured set of data held in a computer, most often a server. Databases use a database management system (DBMS) that interacts with users, similar to a lookup table. Modern databases are designed to allow for creation, querying, updating, and administration of the data it holds. diff --git a/topics/gulp/index.md b/topics/gulp/index.md index f1e30c9d9fdb..79c5f9cbe306 100644 --- a/topics/gulp/index.md +++ b/topics/gulp/index.md @@ -10,4 +10,4 @@ topic: gulp url: http://gulpjs.com/ wikipedia_url: https://en.wikipedia.org/wiki/Gulp.js --- -Gulp is an open source toolkit built on Node.js & npm. It is used for automating and streamlining repetitive tasks in front-end web development. +Gulp is an open source toolkit built on Node.js and npm. It is used for automating and streamlining repetitive tasks in front-end web development. diff --git a/topics/ios/index.md b/topics/ios/index.md index 7dcd8b95154b..ea558eb6a4f0 100644 --- a/topics/ios/index.md +++ b/topics/ios/index.md @@ -9,4 +9,4 @@ topic: ios url: https://www.apple.com/ios/ wikipedia_url: https://en.wikipedia.org/wiki/IOS --- -iOS is the operating system for all of Apple’s mobile products. The operating system was unveiled at Macworld Conference & Expo in 2007 to support the company’s new venture, the iPhone. Since then, the operating system has grown to incorporate other products, including the iPad and iPod Touch. +iOS is the operating system for all of Apple’s mobile products. The operating system was unveiled at Macworld Conference and Expo in 2007 to support the company’s new venture, the iPhone. Since then, the operating system has grown to incorporate other products, including the iPad and iPod Touch. diff --git a/topics/mysql/index.md b/topics/mysql/index.md index 8c314e96fc44..1c14e6e38899 100644 --- a/topics/mysql/index.md +++ b/topics/mysql/index.md @@ -10,4 +10,4 @@ topic: mysql url: https://www.mysql.com/ wikipedia_url: https://en.wikipedia.org/wiki/MySQL --- -MySQL is an open source relational database management system. Based in Structured Query Language (SQL), MySQL can run on most platforms and is mainly used for web-based applications. It is written in C & C++. +MySQL is an open source relational database management system. Based in Structured Query Language (SQL), MySQL can run on most platforms and is mainly used for web-based applications. It is written in C and C++. diff --git a/topics/react-native/index.md b/topics/react-native/index.md index b2061deab5dd..4f5e840464e0 100644 --- a/topics/react-native/index.md +++ b/topics/react-native/index.md @@ -10,4 +10,4 @@ topic: react-native url: http://reactnative.com/ wikipedia_url: https://en.wikipedia.org/wiki/React_(JavaScript_library)#React_Native --- -React Native is a JavaScript mobile framework developed by Facebook. It allows developers to build Android & iOS mobile apps using JavaScript and reuse code across web & mobile applications. +React Native is a JavaScript mobile framework developed by Facebook. It allows developers to build Android and iOS mobile apps using JavaScript and reuse code across web and mobile applications. diff --git a/topics/redux/index.md b/topics/redux/index.md index f73ebe9e1518..8d902d96dde1 100644 --- a/topics/redux/index.md +++ b/topics/redux/index.md @@ -9,4 +9,4 @@ topic: redux url: http://redux.js.org/ wikipedia_url: https://en.wikipedia.org/wiki/Redux_(JavaScript_library) --- -Redux is an open-source JavaScript library, designed to allow for state management of JavaScript applications. Inspired by Elm, Redux is a debugging tool and supports robust application data-flow architecture. Redux is frequently used in combination with React. +Redux is an open source JavaScript library, designed to allow for state management of JavaScript applications. Inspired by Elm, Redux is a debugging tool and supports robust application data-flow architecture. Redux is frequently used in combination with React. From 93e03ae1f497db76861ab0831227017d7e68ef97 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Tue, 3 Oct 2017 17:43:16 +0100 Subject: [PATCH 16/20] Address review feedback. --- test/topics_test.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/topics_test.rb b/test/topics_test.rb index 2f828c84d7bc..720c32ab4d0d 100644 --- a/test/topics_test.rb +++ b/test/topics_test.rb @@ -38,7 +38,7 @@ if File.file?(path) lines = File.readlines(path) - assert !lines.empty? + refute lines.empty? assert_equal "---\n", lines[0], "expected file to start with Jekyll front matter ---" end_index = lines.slice(1..-1).index("---\n") @@ -50,7 +50,7 @@ metadata = metadata_for(topic) refute_empty metadata, "expected some metadata for topic" - metadata.each_key do |key,| + metadata.each_key do |key| assert_includes VALID_METADATA_KEYS, key, "unexpected metadata key '#{key}'" end @@ -60,8 +60,6 @@ "expected to have a value for '#{key}'" end end - end - end end end end From 30c9997bd47242d87d2db65902102db668ed1183 Mon Sep 17 00:00:00 2001 From: Sarah Vessels Date: Tue, 3 Oct 2017 11:46:54 -0500 Subject: [PATCH 17/20] Rename to #body_for --- test/test_helper.rb | 2 +- test/topics_test.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index 90b8029ef6cd..991a119e5fc0 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -46,7 +46,7 @@ def metadata_for(topic) end end -def text_for(topic) +def body_for(topic) path = File.join(topics_dir, topic, "index.md") return "" unless File.file?(path) diff --git a/test/topics_test.rb b/test/topics_test.rb index 5908d2e69a10..2e9b7d0a40e4 100644 --- a/test/topics_test.rb +++ b/test/topics_test.rb @@ -61,7 +61,7 @@ end it "follows the Topic Page Style Guide" do - text = text_for(topic) + text = body_for(topic) end_punctuation = %w[. , ; :] text.lines do |line| line.chomp! From 8939340b97a003539659f0fb66a7930f56f2f733 Mon Sep 17 00:00:00 2001 From: Sarah Vessels Date: Tue, 3 Oct 2017 11:53:44 -0500 Subject: [PATCH 18/20] Pull arrays out into variables --- test/topics_test.rb | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/test/topics_test.rb b/test/topics_test.rb index 2e9b7d0a40e4..a2504f24f96b 100644 --- a/test/topics_test.rb +++ b/test/topics_test.rb @@ -62,44 +62,50 @@ it "follows the Topic Page Style Guide" do text = body_for(topic) - end_punctuation = %w[. , ; :] + end_punctuation = %w[. , ; :] + [" "] + month_abbreviations = %w[Jan Feb Mar Apr Jun Jul Aug Sep Oct Nov Dec] + day_ordinals = %w[1st 2nd 3rd 1th 2th 3th 4th 5th 6th 7th 8th 9th] + git_verbs = %w[GitHubbing Gitting] + bad_github_variants = %w[Github github] + numbers_to_be_spelled_out = 1..9 + text.lines do |line| line.chomp! refute_includes line, "&", 'Use "and" rather than an ampersand' refute_includes line, "!", "Avoid exclamation points in topic pages" - refute_includes line, "open-source", - "Use open source without a hyphen" + refute_includes line, "open-source", "Use open source without a hyphen" - %w[Jan Feb Mar Apr Jun Jul Aug Sep Oct Nov Dec].each do |month| + month_abbreviations.each do |month| refute_includes line, "#{month} ", "Include and spell out the month" end - %w[1st 2nd 3rd 1th 2th 3th 4th 5th 6th 7th 8th 9th].each do |date_end| + day_ordinals.each do |date_end| refute_includes line, date_end, 'Include the day number without the "th" or "nd" at the end' end - %w[GitHubbing Gitting].each do |no_git_verb| + git_verbs.each do |no_git_verb| refute_includes line, no_git_verb, "Never use “GitHub” or “Git” as a verb." end - %w[Github github].each do |wrong_github| + bad_github_variants.each do |wrong_github| refute_includes line, wrong_github, 'Always use correct capitalization when referring to "GitHub"' end - (end_punctuation + [" "]).each do |punctuation| + end_punctuation.each do |punctuation| refute_includes line, "git#{punctuation}", 'Always use correct capitalization when referring to "Git"' - (1..10).each do |digit| + numbers_to_be_spelled_out.each do |digit| refute_includes line, " #{digit}#{punctuation}", 'Write out "one" and every number less than 10' end end end + text.delete("\n").split(".").each do |sentence| # This is arbitrary; 2 is more correct but 3 avoids false positives. next if sentence.count(",") < 3 From 41df3d0411706fbaaab12ac7065bffb42a589e82 Mon Sep 17 00:00:00 2001 From: Sarah Vessels Date: Tue, 3 Oct 2017 11:53:51 -0500 Subject: [PATCH 19/20] Restore missing block end --- test/topics_test.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/test/topics_test.rb b/test/topics_test.rb index a2504f24f96b..0277eaa9012f 100644 --- a/test/topics_test.rb +++ b/test/topics_test.rb @@ -58,6 +58,7 @@ 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}'" + end end it "follows the Topic Page Style Guide" do From 6e091f51f5d0deaf0eb2331913dee0a47bd229a2 Mon Sep 17 00:00:00 2001 From: Sarah Vessels Date: Tue, 3 Oct 2017 11:54:09 -0500 Subject: [PATCH 20/20] Add missing Oxford comma to 3d topic --- topics/3d/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/topics/3d/index.md b/topics/3d/index.md index cc37c56de46d..d99b05fd2557 100644 --- a/topics/3d/index.md +++ b/topics/3d/index.md @@ -6,4 +6,4 @@ short_description: 3D modeling is the process of virtually developing the surfac topic: 3d wikipedia_url: https://en.wikipedia.org/wiki/3D_modeling --- -3D modeling uses specialized software to create a digital model of a physical object. It is an aspect of 3D computer graphics, used for video games, 3D printing and VR, among other applications. +3D modeling uses specialized software to create a digital model of a physical object. It is an aspect of 3D computer graphics, used for video games, 3D printing, and VR, among other applications.