"Fossies" - the Fresh Open Source Software Archive

Member "vagrant-2.2.14/test/unit/vagrant/alias_test.rb" (20 Nov 2020, 1912 Bytes) of package /linux/misc/vagrant-2.2.14.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Ruby source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 require_relative "../base"
    2 
    3 require "vagrant/alias"
    4 
    5 describe Vagrant::Alias do
    6   include_context "unit"
    7   include_context "command plugin helpers"
    8 
    9   let(:iso_env) { isolated_environment }
   10   let(:env)     { iso_env.create_vagrant_env }
   11 
   12   describe "#interpret" do
   13     let(:interpreter) { described_class.new(env) }
   14 
   15     it "returns nil for comments" do
   16       comments = [
   17         "# this is a comment",
   18         "# so is this       ",
   19         "       # and this",
   20         "       # this too       "
   21       ]
   22 
   23       comments.each do |comment|
   24         expect(interpreter.interpret(comment)).to be_nil
   25       end
   26     end
   27 
   28     it "raises an error on invalid keywords" do
   29       keywords = [
   30         "keyword with a space = command",
   31         "keyword\twith a tab = command",
   32         "keyword\nwith a newline = command",
   33       ]
   34 
   35       keywords.each do |keyword|
   36         expect { interpreter.interpret(keyword) }.to raise_error(Vagrant::Errors::AliasInvalidError)
   37       end
   38     end
   39 
   40     it "properly interprets a simple alias" do
   41       keyword, command = interpreter.interpret("keyword=command")
   42 
   43       expect(keyword).to eq("keyword")
   44       expect(command).to eq("command")
   45     end
   46 
   47     it "properly interprets an alias with excess whitespace" do
   48       keyword, command = interpreter.interpret("     keyword      =     command    ")
   49 
   50       expect(keyword).to eq("keyword")
   51       expect(command).to eq("command")
   52     end
   53 
   54     it "properly interprets an alias with an equals sign in the command" do
   55       keyword, command = interpreter.interpret("     keyword      =     command = command    ")
   56 
   57       expect(keyword).to eq("keyword")
   58       expect(command).to eq("command = command")
   59     end
   60 
   61     it "allows keywords with non-alpha-numeric characters" do
   62       keyword, command = interpreter.interpret("keyword! = command")
   63 
   64       expect(keyword).to eq("keyword!")
   65       expect(command).to eq("command")
   66     end
   67   end
   68 end