forked from hashicorp/vagrant
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Configuration classes can now be validated. Nice error message shown …
…in case of failure.
- Loading branch information
Showing
9 changed files
with
130 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module Vagrant | ||
class Config | ||
# A class which is passed into the various {Base#validate} methods and | ||
# can be used as a helper to add error messages about a single config | ||
# class. | ||
class ErrorRecorder | ||
attr_reader :errors | ||
|
||
def initialize | ||
@errors = [] | ||
end | ||
|
||
# Adds an error to the list of errors. The message key must be a key | ||
# to an I18n translatable error message. Opts can be specified as | ||
# interpolation variables for the message. | ||
def add(message_key, opts=nil) | ||
@errors << I18n.t(message_key, opts) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<% errors.each do |key, container| -%> | ||
<%= key %>: | ||
<% container.errors.each do |error| -%> | ||
* <%= error %> | ||
<% end -%> | ||
|
||
<% end -%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require "test_helper" | ||
|
||
class ConfigErrorsTest < Test::Unit::TestCase | ||
setup do | ||
@klass = Vagrant::Config::ErrorRecorder | ||
@instance = @klass.new | ||
end | ||
|
||
should "not have any errors to start" do | ||
assert @instance.errors.empty? | ||
end | ||
|
||
should "add errors" do | ||
key = "vagrant.test.errors.test_key" | ||
@instance.add(key) | ||
assert_equal I18n.t(key), @instance.errors.first | ||
end | ||
|
||
should "interpolate error messages if options given" do | ||
key = "vagrant.test.errors.test_key_with_interpolation" | ||
@instance.add(key, :key => "hey") | ||
assert_equal I18n.t(key, :key => "hey"), @instance.errors.first | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters