start working through tests
This commit is contained in:
parent
17f13785ce
commit
f16751a46d
|
@ -9,13 +9,12 @@ module Vagrant
|
|||
aliases_file = env.home_path.join("aliases")
|
||||
if aliases_file.file?
|
||||
aliases_file.readlines.each do |line|
|
||||
# skip comments
|
||||
next if line.strip.start_with?("#")
|
||||
|
||||
# separate keyword-command pairs
|
||||
keyword, command = line.split("=").collect(&:strip)
|
||||
keyword, command = interpret(line)
|
||||
|
||||
register(keyword, command)
|
||||
if keyword && command
|
||||
register(keyword, command)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -25,6 +24,16 @@ module Vagrant
|
|||
@aliases
|
||||
end
|
||||
|
||||
# This interprets a raw line from the aliases file.
|
||||
def interpret(line)
|
||||
# is it a comment?
|
||||
return nil if line.strip.start_with?("#")
|
||||
|
||||
keyword, command = line.split("=", 2).collect(&:strip)
|
||||
|
||||
[keyword, command]
|
||||
end
|
||||
|
||||
# This registers an alias.
|
||||
def register(keyword, command)
|
||||
@aliases.register(keyword.to_sym) do
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
require_relative "../base"
|
||||
|
||||
require "vagrant/alias"
|
||||
|
||||
describe Vagrant::Alias do
|
||||
include_context "unit"
|
||||
include_context "command plugin helpers"
|
||||
|
||||
let(:iso_env) { isolated_environment }
|
||||
let(:env) { iso_env.create_vagrant_env }
|
||||
|
||||
describe "#interpret" do
|
||||
let(:interpreter) { described_class.new(env) }
|
||||
|
||||
it "returns nil for comments" do
|
||||
comments = [
|
||||
"# this is a comment",
|
||||
"# so is this ",
|
||||
" # and this",
|
||||
" # this too "
|
||||
]
|
||||
|
||||
comments.each do |comment|
|
||||
expect(interpreter.interpret(comment)).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
it "properly interprets a simple alias" do
|
||||
keyword, command = interpreter.interpret("keyword=command")
|
||||
|
||||
expect(keyword).to eq("keyword")
|
||||
expect(command).to eq("command")
|
||||
end
|
||||
|
||||
it "properly interprets an alias with excess whitespace" do
|
||||
keyword, command = interpreter.interpret(" keyword = command ")
|
||||
|
||||
expect(keyword).to eq("keyword")
|
||||
expect(command).to eq("command")
|
||||
end
|
||||
|
||||
it "properly interprets an alias with an equals sign in the command" do
|
||||
keyword, command = interpreter.interpret(" keyword = command = command ")
|
||||
|
||||
expect(keyword).to eq("keyword")
|
||||
expect(command).to eq("command = command")
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue