Permalink
Browse files

Restored the hashr dependency

Pushed the use of Hashr down to Travis::Lint::Linter#validate to allow use as API by third-parties.

Restored majority use of symbols to minimize churn.

Use string keys in validation messages instead of symbol keys to match travis-ci documentation.

Add an explicit test for keys as String.

Add a missing test for erlang otp_release key.
  • Loading branch information...
drbrain committed Feb 16, 2012
1 parent b4cd0f9 commit 302adb92c827e40d60fc67f0930f183e9fa799bf
Showing with 60 additions and 36 deletions.
  1. +25 −21 lib/travis/lint/linter.rb
  2. +33 −15 spec/travis_lint_spec.rb
  3. +2 −0 travis-lint.gemspec
View
@@ -1,5 +1,7 @@
require "travis/lint/dsl"
+require "hashr"
+
module Travis
module Lint
class Linter
@@ -16,7 +18,9 @@ class Linter
#
def self.validate(hsh)
- issues = find_validators_for(hsh["language"]).inject([]) do |acc, val|
+ hsh = Hashr.new hsh
+
+ issues = find_validators_for(hsh[:language]).inject([]) do |acc, val|
acc << val.call(hsh)
acc
end.reject(&:first).map { |pair| pair[1] }
@@ -31,56 +35,56 @@ def self.valid?(hsh)
# General
#
- validator_for "all", "language", "Language: key is mandatory" do |hsh|
- blank? hsh["language"]
+ validator_for :all, :language, "The \"language\" key is mandatory" do |hsh|
+ blank? hsh[:language]
end
#
# Erlang
#
- validator_for "erlang", "otp_release", "Specify OTP releases you want to test against using the \"otp_release\" key" do |hsh|
- hsh["language"].to_s.downcase == "erlang" && blank?(hsh["otp_release"])
+ validator_for :erlang, :otp_release, "Specify OTP releases you want to test against using the \"otp_release\" key" do |hsh|
+ hsh[:language].to_s.downcase == "erlang" && blank?(hsh[:otp_release])
end
#
# Ruby
#
- validator_for "ruby", "rvm", "Specify Ruby versions/implementations you want to test against using the \"rvm\" key" do |hsh|
- hsh["language"].to_s.downcase == "ruby" && blank?(hsh["rvm"])
+ validator_for :ruby, :rvm, "Specify Ruby versions/implementations you want to test against using the \"rvm\" key" do |hsh|
+ hsh[:language].to_s.downcase == "ruby" && blank?(hsh[:rvm])
end
- validator_for "ruby", "rvm", "Prefer jruby-18mode RVM alias to jruby" do |hsh|
- hsh["rvm"].is_a?(Array) && hsh["rvm"].include?("jruby")
+ validator_for :ruby, :rvm, "Prefer jruby-18mode RVM alias to jruby" do |hsh|
+ hsh[:rvm].is_a?(Array) && hsh[:rvm].include?("jruby")
end
- validator_for "ruby", "rvm", "Prefer rbx-18mode RVM alias to rbx" do |hsh|
- hsh["rvm"].is_a?(Array) && hsh["rvm"].include?("rbx")
+ validator_for :ruby, :rvm, "Prefer rbx-18mode RVM alias to rbx" do |hsh|
+ hsh[:rvm].is_a?(Array) && hsh[:rvm].include?("rbx")
end
- validator_for "ruby", "rvm", "rbx-2.0 RVM alias is no longer provided. Please use rbx-18mode or rbx-19mode instead." do |hsh|
- hsh["rvm"].is_a?(Array) && hsh["rvm"].include?("rbx-2.0")
+ validator_for :ruby, :rvm, "rbx-2.0 RVM alias is no longer provided. Please use rbx-18mode or rbx-19mode instead." do |hsh|
+ hsh[:rvm].is_a?(Array) && hsh[:rvm].include?("rbx-2.0")
end
- validator_for "ruby", "rvm", "rbx-2.0.0pre RVM alias is no longer provided. Please use rbx-18mode or rbx-19mode instead." do |hsh|
- hsh["rvm"].is_a?(Array) && hsh["rvm"].include?("rbx-2.0.0pre")
+ validator_for :ruby, :rvm, "rbx-2.0.0pre RVM alias is no longer provided. Please use rbx-18mode or rbx-19mode instead." do |hsh|
+ hsh[:rvm].is_a?(Array) && hsh[:rvm].include?("rbx-2.0.0pre")
end
- validator_for "ruby", "rvm", "Ruby 1.9.1 is no longer maintained and is no longer provided on travis-ci.org. Please move to 1.9.3." do |hsh|
- hsh["rvm"].is_a?(Array) && hsh["rvm"].include?("1.9.1")
+ validator_for :ruby, :rvm, "Ruby 1.9.1 is no longer maintained and is no longer provided on travis-ci.org. Please move to 1.9.3." do |hsh|
+ hsh[:rvm].is_a?(Array) && hsh[:rvm].include?("1.9.1")
end
- validator_for "ruby", "rvm", "Ruby 1.8.6 is no longer maintained and is no longer provided on travis-ci.org. Please move to 1.8.7." do |hsh|
- hsh["rvm"].is_a?(Array) && hsh["rvm"].include?("1.8.6")
+ validator_for :ruby, :rvm, "Ruby 1.8.6 is no longer maintained and is no longer provided on travis-ci.org. Please move to 1.8.7." do |hsh|
+ hsh[:rvm].is_a?(Array) && hsh[:rvm].include?("1.8.6")
end
- validator_for "ruby", "language", "Language is set to Ruby but \"node_js\" key is present. Ruby builder will ignore node_js key." do |hsh|
- hsh["language"].to_s.downcase == "ruby" && ! blank?(hsh["node_js"])
+ validator_for :ruby, :language, "Language is set to Ruby but node_js key is present. Ruby builder will ignore node_js key." do |hsh|
+ hsh[:language].to_s.downcase == "ruby" && ! blank?(hsh[:node_js])
end
end
end
View
@@ -2,27 +2,31 @@
describe "A .travis.yml" do
let(:language_key_is_mandatory) do
- { :key => "language", :issue => "Language: key is mandatory" }
+ { :key => :language, :issue => "The \"language\" key is mandatory" }
end
let(:rvm_key_is_recommended) do
- { :key => "rvm", :issue => "Specify Ruby versions/implementations you want to test against using the \"rvm\" key" }
+ { :key => :rvm, :issue => "Specify Ruby versions/implementations you want to test against using the \"rvm\" key" }
end
let(:prefer_jruby18mode_over_jruby) do
- { :key => "rvm", :issue => "Prefer jruby-18mode RVM alias to jruby" }
+ { :key => :rvm, :issue => "Prefer jruby-18mode RVM alias to jruby" }
end
let(:prefer_rbx18mode_over_rbx) do
- { :key => "rvm", :issue => "Prefer rbx-18mode RVM alias to rbx" }
+ { :key => :rvm, :issue => "Prefer rbx-18mode RVM alias to rbx" }
end
let(:rbx20_is_no_longer_provided) do
- { :key => "rvm", :issue => "rbx-2.0 RVM alias is no longer provided. Please use rbx-18mode or rbx-19mode instead." }
+ { :key => :rvm, :issue => "rbx-2.0 RVM alias is no longer provided. Please use rbx-18mode or rbx-19mode instead." }
end
let(:rbx200pre_is_no_longer_provided) do
- { :key => "rvm", :issue => "rbx-2.0.0pre RVM alias is no longer provided. Please use rbx-18mode or rbx-19mode instead." }
+ { :key => :rvm, :issue => "rbx-2.0.0pre RVM alias is no longer provided. Please use rbx-18mode or rbx-19mode instead." }
+ end
+
+ let(:otp_release_key_is_required) do
+ { :key => :otp_release, :issue => "Specify OTP releases you want to test against using the \"otp_release\" key" }
end
@@ -32,7 +36,6 @@ def content_of_sample_file(name)
YAML.load_file(path.to_s)
end
-
context "that is blank" do
it "is invalid" do
Travis::Lint::Linter.validate({}).should include(language_key_is_mandatory)
@@ -41,18 +44,24 @@ def content_of_sample_file(name)
end
end
+ context "using String keys" do
+ it "is validates as with Symbol keys" do
+ Travis::Lint::Linter.validate({ "language" => "ruby" }).should include(rvm_key_is_recommended)
+ end
+ end
+
context "that has language set to Ruby" do
- context "but has no :rvm key" do
+ context "but has no \"rvm\" key" do
it "is invalid" do
- Travis::Lint::Linter.validate({ "language" => "ruby" }).should include(rvm_key_is_recommended)
+ Travis::Lint::Linter.validate({ :language => "ruby" }).should include(rvm_key_is_recommended)
Travis::Lint::Linter.valid?(content_of_sample_file("no_rvm_key.yml")).should be_false
end
end
context "and uses jruby instead of jruby-18mode" do
let(:travis_yml) do
- { "language" => "ruby", "rvm" => ["jruby"] }
+ { :language => "ruby", :rvm => ["jruby"] }
end
it "is invalid" do
@@ -64,7 +73,7 @@ def content_of_sample_file(name)
context "and uses rbx instead of rbx-18mode" do
let(:travis_yml) do
- { "language" => "ruby", "rvm" => ["rbx", "1.9.3"] }
+ { :language => "ruby", :rvm => ["rbx", "1.9.3"] }
end
it "is invalid" do
@@ -75,7 +84,7 @@ def content_of_sample_file(name)
context "and uses rbx-2.0 instead of rbx-18mode" do
let(:travis_yml) do
- { "language" => "ruby", "rvm" => ["rbx-2.0", "1.9.3"] }
+ { :language => "ruby", :rvm => ["rbx-2.0", "1.9.3"] }
end
it "is invalid" do
@@ -87,7 +96,7 @@ def content_of_sample_file(name)
context "and uses rbx-2.0.0pre instead of rbx-18mode" do
let(:travis_yml) do
- { "language" => "ruby", "rvm" => ["rbx-2.0.0pre", "1.9.3"] }
+ { :language => "ruby", :rvm => ["rbx-2.0.0pre", "1.9.3"] }
end
it "is invalid" do
@@ -98,11 +107,20 @@ def content_of_sample_file(name)
context "that specifies Ruby as the language but tries to set node_js version" do
let(:travis_yml) do
- { "language" => "ruby", "rvm" => ["1.9.3"], "node_js" => ["0.6"] }
+ { :language => "ruby", :rvm => ["1.9.3"], :node_js => ["0.6"] }
end
it "is invalid" do
- Travis::Lint::Linter.validate(travis_yml).should include({ :key => "language", :issue => "Language is set to Ruby but \"node_js\" key is present. Ruby builder will ignore node_js key." })
+ Travis::Lint::Linter.validate(travis_yml).should include({ :key => :language, :issue => "Language is set to Ruby but node_js key is present. Ruby builder will ignore node_js key." })
+ end
+ end
+ end
+
+ context "that has language set to erlang" do
+ context "but has no \"otp_release\" key" do
+ it "is invalid" do
+ Travis::Lint::Linter.validate({ :language => "erlang" }).should include(otp_release_key_is_required)
+ Travis::Lint::Linter.valid?({ :language => "erlang" }).should be_false
end
end
end
View
@@ -16,5 +16,7 @@ Gem::Specification.new do |s|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
+ s.add_runtime_dependency("hashr", [">= 0.0.19"])
+
s.add_development_dependency("rspec", ["~> 2.8.0"])
end

0 comments on commit 302adb9

Please sign in to comment.