derelict 0.2.6.travis.95 → 0.2.6.travis.100
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/lib/derelict/box/manager.rb +110 -0
- data/lib/derelict/box/not_found.rb +16 -0
- data/lib/derelict/box.rb +29 -0
- data/lib/derelict/instance.rb +6 -0
- data/lib/derelict/parser/box_list/invalid_format.rb +16 -0
- data/lib/derelict/parser/box_list.rb +52 -0
- data/lib/derelict/parser.rb +1 -0
- data/lib/derelict/plugin/manager.rb +0 -9
- data/lib/derelict/utils/logger.rb +7 -0
- data/lib/derelict.rb +1 -0
- data/spec/derelict/box/manager_spec.rb +159 -0
- data/spec/derelict/box/not_found_spec.rb +13 -0
- data/spec/derelict/box_spec.rb +37 -0
- data/spec/derelict/instance_spec.rb +6 -0
- data/spec/derelict/parser/box_list/invalid_format_spec.rb +16 -0
- data/spec/derelict/parser/box_list_spec.rb +55 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MTUwMGU3YzZmZTI3YjcwMmMzNDkyN2FlMzBmZTUwZDU5OTRiNzYxMA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MjdjMmYxN2E2OTJmN2Y4NTMxZjMxNTk1YWMzNjc0Y2I4ZWNmOTg1OQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MTA1ZDg4NWJkMjJmNWZiZmI4YmViZWVlZjE4NDBkNDk2NWQ3ODIyZDVlZTg4
|
10
|
+
MTU5MjUxMWFjYzRiOTRkNTdmNTRhNmMyMjAwNjQ3YjYwYjBlOGFiNDczMDcy
|
11
|
+
YjIxMTZkZjEzMWVlYTY5NGM0YjcxYzQ5YTQxMTVhMThlNjJjNzU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZTM4N2NhNmE0MDNjNjAyNjY4MDIwMWZiMzM1MWQ1Y2VhNTBiODg1MzE4ZDYx
|
14
|
+
NWRiYTdhODM1ZDQ2Y2ZlZTM3OWM2MjAyOGNhMTE2Mjc2MDkzMjdlYmE4YjJl
|
15
|
+
OWRlYzkzYjc1Nzk4MGVkZjVlMGE2ZjFmODkxMDY5NjE1MTZiYjc=
|
@@ -0,0 +1,110 @@
|
|
1
|
+
module Derelict
|
2
|
+
class Box
|
3
|
+
# A class that handles managing boxes for a Vagrant instance
|
4
|
+
class Manager
|
5
|
+
# Include "memoize" class method to memoize methods
|
6
|
+
extend Memoist
|
7
|
+
|
8
|
+
# Include "logger" method to get a logger for this class
|
9
|
+
include Utils::Logger
|
10
|
+
|
11
|
+
attr_reader :instance
|
12
|
+
|
13
|
+
# Initializes a Manager for use with a particular instance
|
14
|
+
#
|
15
|
+
# * instance: The Derelict::Instance which will have its
|
16
|
+
# boxes managed by this Manager
|
17
|
+
def initialize(instance)
|
18
|
+
@instance = instance
|
19
|
+
logger.debug "Successfully initialized #{description}"
|
20
|
+
end
|
21
|
+
|
22
|
+
# Retrieves the Set of currently installed boxes
|
23
|
+
def list
|
24
|
+
logger.info "Retrieving Vagrant box list for #{description}"
|
25
|
+
output = instance.execute!(:box, "list").stdout
|
26
|
+
Derelict::Parser::BoxList.new(output).boxes
|
27
|
+
end
|
28
|
+
memoize :list
|
29
|
+
|
30
|
+
# Determines whether a particular box is installed
|
31
|
+
#
|
32
|
+
# * box_name: Name of the box to look for (as a string)
|
33
|
+
def present?(box_name, provider)
|
34
|
+
fetch(box_name, provider)
|
35
|
+
true
|
36
|
+
rescue Box::NotFound
|
37
|
+
false
|
38
|
+
end
|
39
|
+
|
40
|
+
# Adds a box from a file or URL
|
41
|
+
#
|
42
|
+
# The provider will be automatically determined from the box
|
43
|
+
# file's manifest.
|
44
|
+
#
|
45
|
+
# * box_name: The name of the box to add (e.g. "precise64")
|
46
|
+
# * source: The URL or path to the box file
|
47
|
+
# * options: Hash of options. Valid keys:
|
48
|
+
# * log: Whether to log the output (optional, defaults to
|
49
|
+
# false)
|
50
|
+
def add(box_name, source, options)
|
51
|
+
options = {:log => false}.merge(options)
|
52
|
+
logger.info <<-END.gsub(/ {10}|\n\Z/, '')
|
53
|
+
Adding box '#{box_name}' from '#{source}' using #{description}
|
54
|
+
END
|
55
|
+
|
56
|
+
command = [:box, "add", box_name, source]
|
57
|
+
|
58
|
+
log_block = options[:log] ? shell_log_block : nil
|
59
|
+
instance.execute!(*command, &log_block).tap do
|
60
|
+
flush_cache # flush memoized method return values
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# Removes an installed box for a particular provider
|
65
|
+
#
|
66
|
+
# * box_name: Name of the box to remove (e.g. "precise64")
|
67
|
+
# * options: Hash of options. Valid keys:
|
68
|
+
# * log: Whether to log the output (optional, defaults
|
69
|
+
# to false)
|
70
|
+
# * provider: If specified, only the box for a particular
|
71
|
+
# provider is removed; otherwise (by default),
|
72
|
+
# the box is removed for all providers
|
73
|
+
def remove(box_name, options)
|
74
|
+
options = {:log => false, :provider => nil}.merge(options)
|
75
|
+
|
76
|
+
provider = options[:provider]
|
77
|
+
command = [:box, "remove", box_name]
|
78
|
+
command << provider unless provider.nil?
|
79
|
+
|
80
|
+
logger.info <<-END.gsub(/ {10}|\n\Z/, '')
|
81
|
+
Removing box '#{box_name}' for '#{provider}' using #{description}
|
82
|
+
END
|
83
|
+
|
84
|
+
log_block = options[:log] ? shell_log_block : nil
|
85
|
+
instance.execute!(*command, &log_block).tap do
|
86
|
+
flush_cache # flush memoized method return values
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# Retrieves a box with a particular name
|
91
|
+
#
|
92
|
+
# * box_name: Name of the box to look for (as a string)
|
93
|
+
def fetch(box_name, provider)
|
94
|
+
box = list.find do |box|
|
95
|
+
box.name == box_name && box.provider == provider
|
96
|
+
end
|
97
|
+
|
98
|
+
raise Box::NotFound.new box_name, provider if box.nil?
|
99
|
+
box
|
100
|
+
end
|
101
|
+
|
102
|
+
# Provides a description of this Connection
|
103
|
+
#
|
104
|
+
# Mainly used for log messages.
|
105
|
+
def description
|
106
|
+
"Derelict::Box::Manager for #{instance.description}"
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Derelict
|
2
|
+
class Box
|
3
|
+
# A box that isn't currently installed has been retrieved
|
4
|
+
class NotFound < Derelict::Exception
|
5
|
+
# Initializes a new instance, for a particular box name/provider
|
6
|
+
#
|
7
|
+
# * box_name: The name of the box that this exception relates
|
8
|
+
# to
|
9
|
+
# * provider: The provider of the box that this exception
|
10
|
+
# relates to
|
11
|
+
def initialize(box_name, provider)
|
12
|
+
super "Box '#{box_name}' for provider '#{provider}' missing"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/derelict/box.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
module Derelict
|
2
|
+
# Represents an individual Vagrant box for a particular provider
|
3
|
+
class Box
|
4
|
+
autoload :Manager, "derelict/box/manager"
|
5
|
+
autoload :NotFound, "derelict/box/not_found"
|
6
|
+
|
7
|
+
attr_reader :name, :provider
|
8
|
+
|
9
|
+
# Initializes a box with a particular name and provider
|
10
|
+
#
|
11
|
+
# * name: The name of the box represented by this object
|
12
|
+
# * provider: The provider of the box represented by this object
|
13
|
+
def initialize(name, provider)
|
14
|
+
@name = name
|
15
|
+
@provider = provider
|
16
|
+
end
|
17
|
+
|
18
|
+
# Ensure equivalent Boxes are equal to this one
|
19
|
+
def ==(other)
|
20
|
+
other.name == name and other.provider == provider
|
21
|
+
end
|
22
|
+
alias_method :eql?, :==
|
23
|
+
|
24
|
+
# Make equivalent Boxes hash to the same value
|
25
|
+
def hash
|
26
|
+
name.hash ^ provider.hash
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/derelict/instance.rb
CHANGED
@@ -102,6 +102,12 @@ module Derelict
|
|
102
102
|
Derelict::Plugin::Manager.new(self)
|
103
103
|
end
|
104
104
|
|
105
|
+
# Initializes a box manager for use with this instance
|
106
|
+
def boxes
|
107
|
+
logger.info "Creating box manager for #{description}"
|
108
|
+
Derelict::Box::Manager.new(self)
|
109
|
+
end
|
110
|
+
|
105
111
|
# Provides a description of this Instance
|
106
112
|
#
|
107
113
|
# Mainly used for log messages.
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Derelict
|
2
|
+
class Parser
|
3
|
+
class BoxList
|
4
|
+
# The box list wasn't in the expected format, can't be parsed
|
5
|
+
class InvalidFormat < Derelict::Exception
|
6
|
+
include Derelict::Exception::OptionalReason
|
7
|
+
|
8
|
+
private
|
9
|
+
# Retrieves the default error message
|
10
|
+
def default_message
|
11
|
+
"Output from 'vagrant box list' was in an unexpected format"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Derelict
|
2
|
+
# Parses the output of "vagrant box list"
|
3
|
+
class Parser::BoxList < Parser
|
4
|
+
autoload :InvalidFormat, "derelict/parser/box_list/invalid_format"
|
5
|
+
|
6
|
+
# Include "memoize" class method to memoize methods
|
7
|
+
extend Memoist
|
8
|
+
|
9
|
+
# Output from "vagrant box list" if there are no boxes installed
|
10
|
+
NO_BOXES = <<-END.gsub(/^ {6}/, '')
|
11
|
+
There are no installed boxes! Use `vagrant box add` to add some.
|
12
|
+
END
|
13
|
+
|
14
|
+
# Regexp to parse a box line into a box name and provider
|
15
|
+
#
|
16
|
+
# Capture groups:
|
17
|
+
#
|
18
|
+
# 1. Box name, as listed in the output
|
19
|
+
# 2. Name of the provider for that box
|
20
|
+
PARSE_BOX = %r[
|
21
|
+
^(.*) # Box name starts at the start of the line
|
22
|
+
\ \( # Provider is separated by a space and open-parenthesis
|
23
|
+
(.*) # Provider name
|
24
|
+
\)$ # Ends with close-parenthesis and end-of-line
|
25
|
+
]x # Ignore whitespace to allow these comments
|
26
|
+
|
27
|
+
# Retrieves a Set containing all the boxes from the output
|
28
|
+
def boxes
|
29
|
+
box_lines.map {|l| parse_line l.match(PARSE_BOX) }.to_set
|
30
|
+
end
|
31
|
+
|
32
|
+
# Provides a description of this Parser
|
33
|
+
#
|
34
|
+
# Mainly used for log messages.
|
35
|
+
def description
|
36
|
+
"Derelict::Parser::BoxList instance"
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
# Retrieves an array of the box lines in the output
|
41
|
+
def box_lines
|
42
|
+
return [] if output.match NO_BOXES
|
43
|
+
output.lines
|
44
|
+
end
|
45
|
+
|
46
|
+
# Parses a single line of the output into a Box object
|
47
|
+
def parse_line(match)
|
48
|
+
raise InvalidFormat.new "Couldn't parse box list" if match.nil?
|
49
|
+
Derelict::Box.new *match.captures[0..1]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/derelict/parser.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module Derelict
|
2
2
|
# Base class for parsers, which extract data from command output
|
3
3
|
class Parser
|
4
|
+
autoload :BoxList, "derelict/parser/box_list"
|
4
5
|
autoload :PluginList, "derelict/parser/plugin_list"
|
5
6
|
autoload :Status, "derelict/parser/status"
|
6
7
|
autoload :Version, "derelict/parser/version"
|
@@ -102,15 +102,6 @@ module Derelict
|
|
102
102
|
def description
|
103
103
|
"Derelict::Plugin::Manager for #{instance.description}"
|
104
104
|
end
|
105
|
-
|
106
|
-
private
|
107
|
-
# A block that can be passed to #execute to log the output
|
108
|
-
def shell_log_block
|
109
|
-
Proc.new do |line|
|
110
|
-
logger(:type => :external).info line
|
111
|
-
end
|
112
|
-
end
|
113
|
-
memoize :shell_log_block
|
114
105
|
end
|
115
106
|
end
|
116
107
|
end
|
@@ -20,6 +20,13 @@ module Derelict
|
|
20
20
|
end
|
21
21
|
|
22
22
|
private
|
23
|
+
# A block that can be passed to #execute to log the output
|
24
|
+
def shell_log_block
|
25
|
+
Proc.new do |line|
|
26
|
+
logger(:type => :external).info line
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
23
30
|
# Finds or creates a Logger with a particular fullname
|
24
31
|
def find_or_create_logger(fullname)
|
25
32
|
Log4r::Logger[fullname.to_s] || Log4r::Logger.new(fullname.to_s)
|
data/lib/derelict.rb
CHANGED
@@ -9,6 +9,7 @@ Log4r::Logger["root"] # creates the level constants (INFO, etc).
|
|
9
9
|
|
10
10
|
# Main module/entry point for Derelict
|
11
11
|
module Derelict
|
12
|
+
autoload :Box, "derelict/box"
|
12
13
|
autoload :Connection, "derelict/connection"
|
13
14
|
autoload :Exception, "derelict/exception"
|
14
15
|
autoload :Instance, "derelict/instance"
|
@@ -0,0 +1,159 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Derelict::Box::Manager do
|
4
|
+
let(:instance) { double("instance", :description => "test instance") }
|
5
|
+
let(:manager) { Derelict::Box::Manager.new instance }
|
6
|
+
subject { manager }
|
7
|
+
|
8
|
+
it "is autoloaded" do
|
9
|
+
should be_a Derelict::Box::Manager
|
10
|
+
end
|
11
|
+
|
12
|
+
include_context "logged messages"
|
13
|
+
let(:expected_logs) {[
|
14
|
+
"DEBUG manager: Successfully initialized Derelict::Box::Manager for test instance\n"
|
15
|
+
]}
|
16
|
+
|
17
|
+
describe "#list" do
|
18
|
+
let(:stdout) { "stdout\n" }
|
19
|
+
let(:result) { double("result", :stdout => stdout) }
|
20
|
+
let(:parser) { double("parser", :boxes => boxes) }
|
21
|
+
let(:boxes) { [:foo, :bar] }
|
22
|
+
|
23
|
+
subject { manager.list }
|
24
|
+
|
25
|
+
before do
|
26
|
+
expect(instance).to receive(:execute!).with(:box, "list").and_return(result)
|
27
|
+
expect(Derelict::Parser::BoxList).to receive(:new).with(stdout).and_return(parser)
|
28
|
+
end
|
29
|
+
|
30
|
+
it { should be boxes }
|
31
|
+
|
32
|
+
include_context "logged messages"
|
33
|
+
let(:expected_logs) {[
|
34
|
+
"DEBUG manager: Successfully initialized Derelict::Box::Manager for test instance\n",
|
35
|
+
" INFO manager: Retrieving Vagrant box list for Derelict::Box::Manager for test instance\n",
|
36
|
+
]}
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#present?" do
|
40
|
+
let(:box_name) { double("box_name") }
|
41
|
+
let(:box) { double("box", :provider => box_provider) }
|
42
|
+
let(:box_provider) { nil }
|
43
|
+
let(:provider) { nil }
|
44
|
+
subject { manager.present? box_name, provider }
|
45
|
+
|
46
|
+
context "with known box" do
|
47
|
+
before { expect(manager).to receive(:fetch).with(box_name, provider).and_return(box) }
|
48
|
+
|
49
|
+
let(:provider) { "provider_one" }
|
50
|
+
let(:box_provider) { "provider_one" }
|
51
|
+
it { should be true }
|
52
|
+
end
|
53
|
+
|
54
|
+
context "with unknown box" do
|
55
|
+
before { expect(manager).to receive(:fetch).with(box_name, provider).and_raise(Derelict::Box::NotFound.new box_name, provider) }
|
56
|
+
it { should be false }
|
57
|
+
end
|
58
|
+
|
59
|
+
include_context "logged messages"
|
60
|
+
let(:expected_logs) {[
|
61
|
+
"DEBUG manager: Successfully initialized Derelict::Box::Manager for test instance\n",
|
62
|
+
" INFO manager: Retrieving Vagrant box list for Derelict::Box::Manager for test instance\n",
|
63
|
+
]}
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "#add" do
|
67
|
+
let(:log) { true }
|
68
|
+
let(:box_name) { double("box_name", :to_s => "test box") }
|
69
|
+
let(:source) { double("source", :to_s => "test source") }
|
70
|
+
let(:result) { double("result") }
|
71
|
+
subject { manager.add box_name, source, :log => log }
|
72
|
+
|
73
|
+
before do
|
74
|
+
expect(instance).to receive(:execute!).with(:box, "add", box_name, source).and_yield("test").and_return(result)
|
75
|
+
end
|
76
|
+
|
77
|
+
it { should be result }
|
78
|
+
|
79
|
+
context "with logging enabled" do
|
80
|
+
include_context "logged messages"
|
81
|
+
let(:expected_logs) {[
|
82
|
+
"DEBUG manager: Successfully initialized Derelict::Box::Manager for test instance\n",
|
83
|
+
" INFO manager: Adding box 'test box' from 'test source' using Derelict::Box::Manager for test instance\n",
|
84
|
+
" INFO external: test\n",
|
85
|
+
]}
|
86
|
+
end
|
87
|
+
|
88
|
+
context "with logging disabled" do
|
89
|
+
let(:log) { false }
|
90
|
+
include_context "logged messages"
|
91
|
+
let(:expected_logs) {[
|
92
|
+
"DEBUG manager: Successfully initialized Derelict::Box::Manager for test instance\n",
|
93
|
+
" INFO manager: Adding box 'test box' from 'test source' using Derelict::Box::Manager for test instance\n",
|
94
|
+
]}
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe "#remove" do
|
99
|
+
let(:log) { true }
|
100
|
+
let(:box_name) { "test_box" }
|
101
|
+
let(:provider) { "provider_one" }
|
102
|
+
let(:result) { double("result") }
|
103
|
+
subject { manager.remove box_name, :provider => provider, :log => log }
|
104
|
+
|
105
|
+
before do
|
106
|
+
expect(instance).to receive(:execute!).with(:box, "remove", box_name, provider).and_yield("test").and_return(result)
|
107
|
+
end
|
108
|
+
|
109
|
+
it { should be result }
|
110
|
+
|
111
|
+
context "with logging enabled" do
|
112
|
+
include_context "logged messages"
|
113
|
+
let(:expected_logs) {[
|
114
|
+
"DEBUG manager: Successfully initialized Derelict::Box::Manager for test instance\n",
|
115
|
+
" INFO manager: Removing box 'test_box' for 'provider_one' using Derelict::Box::Manager for test instance\n",
|
116
|
+
" INFO external: test\n",
|
117
|
+
]}
|
118
|
+
end
|
119
|
+
|
120
|
+
context "with logging disabled" do
|
121
|
+
let(:log) { false }
|
122
|
+
include_context "logged messages"
|
123
|
+
let(:expected_logs) {[
|
124
|
+
"DEBUG manager: Successfully initialized Derelict::Box::Manager for test instance\n",
|
125
|
+
" INFO manager: Removing box 'test_box' for 'provider_one' using Derelict::Box::Manager for test instance\n",
|
126
|
+
]}
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
describe "#fetch" do
|
131
|
+
let(:foo) { double("foo", :name => "foo", :provider => "provider_one") }
|
132
|
+
let(:bar) { double("bar", :name => "bar", :provider => "provider_two") }
|
133
|
+
let(:boxes) { [foo, bar] }
|
134
|
+
|
135
|
+
let(:box_name) { double("box_name") }
|
136
|
+
let(:box_provider) { double("box_provider") }
|
137
|
+
subject { manager.fetch box_name, box_provider }
|
138
|
+
before { expect(manager).to receive(:list).and_return(boxes) }
|
139
|
+
|
140
|
+
context "with known box" do
|
141
|
+
let(:box_name) { "foo" }
|
142
|
+
let(:box_provider) { "provider_one" }
|
143
|
+
it { should be foo }
|
144
|
+
end
|
145
|
+
|
146
|
+
context "with unknown box" do
|
147
|
+
let(:box_name) { "qux" }
|
148
|
+
it "should raise NotFound" do
|
149
|
+
expect { subject }.to raise_error Derelict::Box::NotFound
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
include_context "logged messages"
|
154
|
+
let(:expected_logs) {[
|
155
|
+
"DEBUG manager: Successfully initialized Derelict::Box::Manager for test instance\n",
|
156
|
+
]}
|
157
|
+
end
|
158
|
+
|
159
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Derelict::Box::NotFound do
|
4
|
+
subject { Derelict::Box::NotFound.new "test", "provider_one" }
|
5
|
+
|
6
|
+
it "is autoloaded" do
|
7
|
+
should be_a Derelict::Box::NotFound
|
8
|
+
end
|
9
|
+
|
10
|
+
its(:message) {
|
11
|
+
should eq "Box 'test' for provider 'provider_one' missing"
|
12
|
+
}
|
13
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Derelict::Box do
|
4
|
+
let(:name) { double("name") }
|
5
|
+
let(:provider) { double("provider") }
|
6
|
+
let(:box) { Derelict::Box.new name, provider }
|
7
|
+
subject { box }
|
8
|
+
|
9
|
+
it "is autoloaded" do
|
10
|
+
should be_a Derelict::Box
|
11
|
+
end
|
12
|
+
|
13
|
+
its(:name) { should be name }
|
14
|
+
its(:provider) { should be provider }
|
15
|
+
|
16
|
+
context "when comparing to an equivalent" do
|
17
|
+
let(:other) { box.dup }
|
18
|
+
|
19
|
+
it { should eq other }
|
20
|
+
its(:hash) { should eq other.hash }
|
21
|
+
|
22
|
+
specify "#eql?(other) should be true" do
|
23
|
+
expect(subject.eql? other).to be true
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "when comparing to a non-equivalent" do
|
28
|
+
let(:other) { box.class.new "not_foo", "other_provider" }
|
29
|
+
|
30
|
+
it { should_not eq other }
|
31
|
+
its(:hash) { should_not eq other.hash }
|
32
|
+
|
33
|
+
specify "#eql?(other) should be false" do
|
34
|
+
expect(subject.eql? other).to be false
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -31,6 +31,12 @@ describe Derelict::Instance do
|
|
31
31
|
its(:instance) { should be instance }
|
32
32
|
end
|
33
33
|
|
34
|
+
describe "#boxes" do
|
35
|
+
subject { instance.boxes }
|
36
|
+
it { should be_a Derelict::Box::Manager }
|
37
|
+
its(:instance) { should be instance }
|
38
|
+
end
|
39
|
+
|
34
40
|
context "with path parameter" do
|
35
41
|
let(:path) { "/foo/bar" }
|
36
42
|
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Derelict::Parser::BoxList::InvalidFormat do
|
4
|
+
it "is autoloaded" do
|
5
|
+
should be_a Derelict::Parser::BoxList::InvalidFormat
|
6
|
+
end
|
7
|
+
|
8
|
+
context "when using default reason" do
|
9
|
+
its(:message) { should eq "Output from 'vagrant box list' was in an unexpected format" }
|
10
|
+
end
|
11
|
+
|
12
|
+
context "when using custom reason" do
|
13
|
+
subject { Derelict::Parser::BoxList::InvalidFormat.new "reason" }
|
14
|
+
its(:message) { should eq "Output from 'vagrant box list' was in an unexpected format: reason" }
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Derelict::Parser::BoxList do
|
4
|
+
subject { Derelict::Parser::BoxList.new output }
|
5
|
+
let(:output) { nil }
|
6
|
+
|
7
|
+
it "is autoloaded" do
|
8
|
+
should be_a Derelict::Parser::BoxList
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#boxes" do
|
12
|
+
subject { Derelict::Parser::BoxList.new(output).boxes }
|
13
|
+
|
14
|
+
include_context "logged messages"
|
15
|
+
let(:expected_logs) {[
|
16
|
+
"DEBUG boxlist: Successfully initialized Derelict::Parser::BoxList instance\n",
|
17
|
+
]}
|
18
|
+
|
19
|
+
context "with valid output" do
|
20
|
+
let(:output) {
|
21
|
+
<<-END.gsub /^ +/, ""
|
22
|
+
foo (provider_one)
|
23
|
+
bar (provider_two)
|
24
|
+
END
|
25
|
+
}
|
26
|
+
|
27
|
+
let(:foo) { Derelict::Box.new "foo", "provider_one" }
|
28
|
+
let(:bar) { Derelict::Box.new "bar", "provider_two" }
|
29
|
+
it { should eq Set[foo, bar] }
|
30
|
+
end
|
31
|
+
|
32
|
+
context "with invalid output" do
|
33
|
+
let(:output) {
|
34
|
+
<<-END.gsub /^ +/, ""
|
35
|
+
foo (provider_one) lolwut
|
36
|
+
bar with no brackets
|
37
|
+
END
|
38
|
+
}
|
39
|
+
|
40
|
+
it "should raise InvalidFormat" do
|
41
|
+
expect { subject }.to raise_error Derelict::Parser::BoxList::InvalidFormat
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context "with no boxes in list" do
|
46
|
+
let(:output) {
|
47
|
+
<<-END.gsub /^ +/, ""
|
48
|
+
There are no installed boxes! Use `vagrant box add` to add some.
|
49
|
+
END
|
50
|
+
}
|
51
|
+
|
52
|
+
it { should eq Set.new }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: derelict
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.6.travis.
|
4
|
+
version: 0.2.6.travis.100
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brad Feehan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: log4r
|
@@ -190,6 +190,9 @@ files:
|
|
190
190
|
- Rakefile
|
191
191
|
- derelict.gemspec
|
192
192
|
- lib/derelict.rb
|
193
|
+
- lib/derelict/box.rb
|
194
|
+
- lib/derelict/box/manager.rb
|
195
|
+
- lib/derelict/box/not_found.rb
|
193
196
|
- lib/derelict/connection.rb
|
194
197
|
- lib/derelict/connection/invalid.rb
|
195
198
|
- lib/derelict/connection/not_found.rb
|
@@ -202,6 +205,8 @@ files:
|
|
202
205
|
- lib/derelict/instance/non_directory.rb
|
203
206
|
- lib/derelict/instance/not_found.rb
|
204
207
|
- lib/derelict/parser.rb
|
208
|
+
- lib/derelict/parser/box_list.rb
|
209
|
+
- lib/derelict/parser/box_list/invalid_format.rb
|
205
210
|
- lib/derelict/parser/plugin_list.rb
|
206
211
|
- lib/derelict/parser/plugin_list/invalid_format.rb
|
207
212
|
- lib/derelict/parser/status.rb
|
@@ -221,6 +226,9 @@ files:
|
|
221
226
|
- lib/derelict/virtual_machine/invalid.rb
|
222
227
|
- lib/derelict/virtual_machine/not_found.rb
|
223
228
|
- spec/coverage_helper.rb
|
229
|
+
- spec/derelict/box/manager_spec.rb
|
230
|
+
- spec/derelict/box/not_found_spec.rb
|
231
|
+
- spec/derelict/box_spec.rb
|
224
232
|
- spec/derelict/connection/invalid_spec.rb
|
225
233
|
- spec/derelict/connection/not_found_spec.rb
|
226
234
|
- spec/derelict/connection_spec.rb
|
@@ -232,6 +240,8 @@ files:
|
|
232
240
|
- spec/derelict/instance/non_directory_spec.rb
|
233
241
|
- spec/derelict/instance/not_found_spec.rb
|
234
242
|
- spec/derelict/instance_spec.rb
|
243
|
+
- spec/derelict/parser/box_list/invalid_format_spec.rb
|
244
|
+
- spec/derelict/parser/box_list_spec.rb
|
235
245
|
- spec/derelict/parser/plugin_list/invalid_format_spec.rb
|
236
246
|
- spec/derelict/parser/plugin_list_spec.rb
|
237
247
|
- spec/derelict/parser/status/invalid_format_spec.rb
|
@@ -278,6 +288,9 @@ specification_version: 4
|
|
278
288
|
summary: Ruby API for Vagrant installed via Installer package on Mac OS X.
|
279
289
|
test_files:
|
280
290
|
- spec/coverage_helper.rb
|
291
|
+
- spec/derelict/box/manager_spec.rb
|
292
|
+
- spec/derelict/box/not_found_spec.rb
|
293
|
+
- spec/derelict/box_spec.rb
|
281
294
|
- spec/derelict/connection/invalid_spec.rb
|
282
295
|
- spec/derelict/connection/not_found_spec.rb
|
283
296
|
- spec/derelict/connection_spec.rb
|
@@ -289,6 +302,8 @@ test_files:
|
|
289
302
|
- spec/derelict/instance/non_directory_spec.rb
|
290
303
|
- spec/derelict/instance/not_found_spec.rb
|
291
304
|
- spec/derelict/instance_spec.rb
|
305
|
+
- spec/derelict/parser/box_list/invalid_format_spec.rb
|
306
|
+
- spec/derelict/parser/box_list_spec.rb
|
292
307
|
- spec/derelict/parser/plugin_list/invalid_format_spec.rb
|
293
308
|
- spec/derelict/parser/plugin_list_spec.rb
|
294
309
|
- spec/derelict/parser/status/invalid_format_spec.rb
|