Add test for detecting color proximity

This commit is contained in:
Garen Torikian
2015-04-01 10:14:52 -07:00
parent 78d4abe808
commit 3851b7c016
3 changed files with 22 additions and 0 deletions

View File

@@ -23,4 +23,5 @@ Gem::Specification.new do |s|
s.add_development_dependency 'pry'
s.add_development_dependency 'rake'
s.add_development_dependency 'yajl-ruby'
s.add_development_dependency 'color-proximity'
end

View File

@@ -2,6 +2,7 @@ require "bundler/setup"
require "minitest/autorun"
require "mocha/setup"
require "linguist"
require 'color-proximity'
def fixtures_path
File.expand_path("../fixtures", __FILE__)

View File

@@ -0,0 +1,20 @@
require_relative "./helper"
class TestColorThreshold < Minitest::Test
include Linguist
def test_color_threshold
langs_with_colors = Language.all.reject { |language| language.color.nil? }
cp = ColorProximity.new(20, langs_with_colors.map(&:color))
failing_threshold = []
langs_with_colors.each do |lang|
state = cp.within_threshold?(lang.color[1..-1])
unless state.first
failing_threshold << [lang, state.last]
end
end
message = "The following languages have failing color thresholds. Please modify the hex color.\n#{failing_threshold}"
assert failing_threshold.empty?, message
end
end