vagrant_spec 0.0.1

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.
Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +6 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +2 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +10 -0
  7. data/Gemfile +10 -0
  8. data/LICENSE +13 -0
  9. data/README.md +146 -0
  10. data/Rakefile +26 -0
  11. data/Vagrantfile +27 -0
  12. data/lib/vagrant_spec/ansible_inventory.rb +80 -0
  13. data/lib/vagrant_spec/command/base.rb +74 -0
  14. data/lib/vagrant_spec/command/init.rb +45 -0
  15. data/lib/vagrant_spec/command/test.rb +32 -0
  16. data/lib/vagrant_spec/command.rb +9 -0
  17. data/lib/vagrant_spec/config/base.rb +42 -0
  18. data/lib/vagrant_spec/config.rb +20 -0
  19. data/lib/vagrant_spec/machine_finder.rb +31 -0
  20. data/lib/vagrant_spec/spec_helper.rb +42 -0
  21. data/lib/vagrant_spec/templates/spec_helper.erb +19 -0
  22. data/lib/vagrant_spec/templates/vagrantspec_inventory.erb +12 -0
  23. data/lib/vagrant_spec/test_plan.rb +68 -0
  24. data/lib/vagrant_spec/utils.rb +23 -0
  25. data/lib/vagrant_spec/version.rb +6 -0
  26. data/lib/vagrant_spec.rb +27 -0
  27. data/scripts/poor_mans_smoke_test.sh +17 -0
  28. data/serverspec/fail_spec.rb +7 -0
  29. data/serverspec/ssh_spec.rb +10 -0
  30. data/spec/unit/spec_helper.rb +101 -0
  31. data/spec/unit/vagrant_spec_spec.rb +13 -0
  32. data/spec/unit/vagrant_spec_test/ansible_inventory_spec.rb +143 -0
  33. data/spec/unit/vagrant_spec_test/command_spec/base_spec.rb +105 -0
  34. data/spec/unit/vagrant_spec_test/command_spec/init_spec.rb +87 -0
  35. data/spec/unit/vagrant_spec_test/command_spec/test_spec.rb +45 -0
  36. data/spec/unit/vagrant_spec_test/config_spec/base_spec.rb +34 -0
  37. data/spec/unit/vagrant_spec_test/config_spec.rb +15 -0
  38. data/spec/unit/vagrant_spec_test/machine_finder_spec.rb +27 -0
  39. data/spec/unit/vagrant_spec_test/spec_helper_spec.rb +41 -0
  40. data/spec/unit/vagrant_spec_test/test_plan_spec.rb +104 -0
  41. data/spec/unit/vagrant_spec_test/utils_spec.rb +24 -0
  42. data/vagrant_spec.gemspec +30 -0
  43. metadata +184 -0
@@ -0,0 +1,68 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'rspec'
4
+
5
+ require 'vagrant_spec/config'
6
+ require 'vagrant_spec/machine_finder'
7
+
8
+ module VagrantSpec
9
+ # Run serverspec tests
10
+ #
11
+ # env [Vagrant::Environment]
12
+ class TestPlan
13
+ attr_reader :env, :config, :test_plan, :m_finder
14
+ def initialize(env)
15
+ @env = env
16
+ @config = VagrantSpec::Config.load(env)
17
+ @test_plan = @config.spec.test_plan
18
+ @m_finder = VagrantSpec::MachineFinder.new(env)
19
+ @ret_code = 0
20
+ end
21
+
22
+ # Run the test suite and exit based on the return codes of the tests
23
+ #
24
+ # This will fail if any of the tests fail, but it will allow all tests to
25
+ # run
26
+ def run
27
+ @env.ui.info('*******************************************************')
28
+ @env.ui.info('***************** ServerSpec Test Run *****************')
29
+ @env.ui.info('*******************************************************')
30
+ @env.ui.info('')
31
+ @test_plan.each do |plan|
32
+ nodes(plan).each { |node| execute_plan_tests(node, plan) }
33
+ end
34
+ exit @ret_code
35
+ end
36
+
37
+ # Return array of active Vagrant machines
38
+ #
39
+ # plan [Hash] item in the @config.spec.test_plan
40
+ #
41
+ # return [Array<Vagrant::Machine>]
42
+ def nodes(plan)
43
+ if plan['nodes'].is_a?(Regexp)
44
+ @m_finder.match_nodes(plan['nodes'])
45
+ elsif plan['nodes'].is_a?(Array)
46
+ plan['nodes'].collect { |n| @m_finder.machine(n.to_sym) }
47
+ end
48
+ end
49
+
50
+ # Execute a test_suite and return the code
51
+ #
52
+ # node [Vagrant::Machine]
53
+ # plan [Hash] item in the @config.spec.test_plan
54
+ #
55
+ # return [@ret_code]
56
+ def execute_plan_tests(node, plan)
57
+ @env.ui.info("[#{node.name}]")
58
+ ENV['VAGRANT_HOST'] = node.ssh_info[:host].to_s
59
+ ENV['VAGRANT_PORT'] = node.ssh_info[:port].to_s
60
+ ENV['VAGRANT_KEY'] = node.ssh_info[:private_key_path][0].to_s
61
+ ENV['VAGRANT_USER'] = node.ssh_info[:username].to_s
62
+ plan['flags'].prepend "-I #{@config.spec.directory} "
63
+ ret_code = RSpec::Core::Runner.run(plan['flags'].split, $stderr, $stdout)
64
+ RSpec.clear_examples
65
+ @ret_code = ret_code unless ret_code.zero?
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,23 @@
1
+ # encoding: UTF-8
2
+
3
+ module VagrantSpec
4
+ # Utilities
5
+ module Utils
6
+ # return [String]
7
+ def project_root
8
+ File.expand_path(File.join(File.dirname(__FILE__), '..', '..'), __FILE__)
9
+ end
10
+
11
+ # return [String]
12
+ def lib_root
13
+ File.expand_path(File.join(File.dirname(__FILE__), '..'), __FILE__)
14
+ end
15
+
16
+ # return [String]
17
+ def template_dir
18
+ File.expand_path(
19
+ File.join(lib_root, 'vagrant_spec', 'templates'), __FILE__
20
+ )
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,6 @@
1
+ # encoding: UTF-8
2
+
3
+ # Requisite version info
4
+ module VagrantSpec
5
+ VERSION = '0.0.1'.freeze
6
+ end
@@ -0,0 +1,27 @@
1
+ # encoding: UTF-8
2
+
3
+ begin
4
+ require 'vagrant'
5
+ rescue LoadError
6
+ raise 'The Vagrant plugin vagrant_spec must be run within Vagrant'
7
+ end
8
+
9
+ module VagrantSpec
10
+ # Plugin definitions
11
+ class Plugin < Vagrant.plugin(2)
12
+ name 'spec'
13
+ description <<-DESC
14
+ This plugin eases rspec and serverspec testing
15
+ DESC
16
+
17
+ command :spec do
18
+ require 'vagrant_spec/command/base'
19
+ VagrantSpec::Command::Base
20
+ end
21
+
22
+ config :spec do
23
+ require 'vagrant_spec/config/base'
24
+ VagrantSpec::Config::Base
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is purely for convenience. This has to be watched to verify that the
4
+ # plugin works in a live environment. Better testing to come...
5
+
6
+ set -e
7
+
8
+ bundle exec vagrant spec
9
+ bundle exec vagrant spec -h
10
+ bundle exec vagrant spec init -h
11
+ bundle exec vagrant spec test -h
12
+ bundle exec vagrant spec no_command -h
13
+ rm -f serverspec/spec_helper.rb
14
+ bundle exec vagrant up
15
+ bundle exec vagrant spec init
16
+ bundle exec vagrant spec test || true
17
+ bundle exec vagrant destroy -f
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Thing that fails' do
4
+ it 'dumb_service totally fails' do
5
+ expect(service('dumb_service')).to be_running
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+
2
+ # encoding: UTF-8
3
+
4
+ require 'spec_helper'
5
+
6
+ describe 'ssh' do
7
+ it 'ssh should be running' do
8
+ expect(service('ssh')).to be_running
9
+ end
10
+ end
@@ -0,0 +1,101 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'coveralls'
4
+ Coveralls.wear!
5
+
6
+ require 'rspec'
7
+
8
+ # Get path to vagrant's test directory so we can load that code. We'll want it
9
+ # for getting access to its convenient shared methods and contexts and such
10
+ VAGRANT_LIB_DIR = Gem::Specification.find_by_name('vagrant').gem_dir.freeze
11
+ VAGRANT_TEST_DIR = File.join(VAGRANT_LIB_DIR, 'test').freeze
12
+
13
+ # Load code paths
14
+ $LOAD_PATH.unshift File.expand_path(File.join('..', '..', 'lib'), __FILE__)
15
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__))
16
+ $LOAD_PATH.unshift File.expand_path(VAGRANT_TEST_DIR, __FILE__)
17
+
18
+ require 'vagrant'
19
+ require 'vagrant_spec'
20
+
21
+ require 'unit/support/shared/base_context'
22
+ require 'unit/support/shared/virtualbox_context'
23
+
24
+ # Build methods to retrieve plugins against VagrantSpec::Plugin.
25
+ #
26
+ # Example: get_commands(VagrantSpec::Plugin)
27
+ #
28
+ # The method call above will return an array of Command plugin names as symbols.
29
+ # Add support by extending the symbol arrays as needed
30
+ %i(command).each do |plugin|
31
+ plural = "#{plugin}s"
32
+ plural_symbol = plural.to_sym
33
+ method_name = "get_#{plural}"
34
+ define_method(method_name) do |plugin_obj|
35
+ plugin_obj.components.send(plural_symbol).keys
36
+ end
37
+ end
38
+
39
+ %i(config).each do |plugin|
40
+ plural = "#{plugin}s"
41
+ plural_symbol = plural.to_sym
42
+ method_name = "get_#{plural}"
43
+ define_method(method_name) do |plugin_obj|
44
+ plugin_obj.components.send(plural_symbol)[:top].keys
45
+ end
46
+ end
47
+
48
+ RSpec.shared_examples 'shared_mocks' do
49
+ let(:vagrant_file) do
50
+ <<-EOF.gsub(/^ {4}/, '')
51
+ Vagrant.configure(2) do |config|
52
+ config.vm.box = 'test'
53
+ end
54
+ EOF
55
+ end
56
+
57
+ let(:mock_vf_obj) { double(Vagrant::Vagrantfile) }
58
+ let(:mock_ui) { double(Vagrant::UI) }
59
+ let(:mock_config) { double(Vagrant::Config) }
60
+ let(:mock_spec) { double(VagrantSpec::Config::Base) }
61
+ let(:mock_node) { double(Vagrant::Machine) }
62
+
63
+ let(:spec_dir) { 'serverspec' }
64
+
65
+ let(:iso_env) do
66
+ env = isolated_environment
67
+ env.vagrantfile vagrant_file
68
+ env.create_vagrant_env
69
+ env
70
+ end
71
+
72
+ before do
73
+ allow(iso_env).to receive(:ui)
74
+ allow(mock_node).to receive(:name)
75
+ allow(mock_ui).to receive(:info)
76
+
77
+ allow(iso_env).to receive(:vagrantfile) { mock_vf_obj }
78
+ allow(iso_env).to receive(:ui) { mock_ui }
79
+ allow(mock_vf_obj).to receive(:config) { mock_config }
80
+ allow(mock_config).to receive(:spec) { mock_spec }
81
+ allow(mock_spec).to receive(:directory) { spec_dir }
82
+ end
83
+ end
84
+
85
+ RSpec::Matchers.define :have_attr_accessor do |field|
86
+ match do |obj_i|
87
+ obj_i.respond_to?(field) && obj_i.respond_to?("#{field}=")
88
+ end
89
+
90
+ failure_message do |obj_i|
91
+ "expected attr_accessor for #{field} on #{obj_i}"
92
+ end
93
+
94
+ failure_message_when_negated do |obj_i|
95
+ "expected attr_accessor for #{field} not to be defined on #{obj_i}"
96
+ end
97
+
98
+ description do
99
+ 'checks to see if there is an attr accessor on the supplied object'
100
+ end
101
+ end
@@ -0,0 +1,13 @@
1
+ # encoding: UTF-8
2
+
3
+ require_relative 'spec_helper'
4
+
5
+ describe VagrantSpec::Plugin do
6
+ it 'has a command plugin: spec' do
7
+ expect(get_commands(VagrantSpec::Plugin)).to include(:spec)
8
+ end
9
+
10
+ it 'has a config plugin: spec' do
11
+ expect(get_configs(VagrantSpec::Plugin)).to include(:spec)
12
+ end
13
+ end
@@ -0,0 +1,143 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+ require 'vagrant_spec/ansible_inventory'
5
+
6
+ describe VagrantSpec::AnsibleInventory do
7
+ include_context 'unit'
8
+ include_examples 'shared_mocks'
9
+
10
+ let(:mock_ansible_inventory_regexp) { { 'all' => /node/ } }
11
+ let(:mock_ansible_inventory_array) { { 'all' => %w(node1) } }
12
+
13
+ let(:mock_machine_ssh_config) do
14
+ {
15
+ 'ansible_host' => 'node1',
16
+ 'ansible_port' => '2222',
17
+ 'ansible_user' => 'vagrant',
18
+ 'ansible_ssh_private_key_file' => 'mock_key'
19
+ }
20
+ end
21
+
22
+ subject { VagrantSpec::AnsibleInventory.new(iso_env) }
23
+
24
+ def load_ansible_inventory_proc
25
+ proc do
26
+ allow(subject).to receive(:handle_array)
27
+ allow(subject).to receive(:handle_regexp)
28
+ end
29
+ end
30
+
31
+ context 'when ansible_inventory is a Regexp' do
32
+ it '#load_ansible_inventory calls handle_regexp' do
33
+ allow(mock_spec).to receive(:ansible_inventory) do
34
+ mock_ansible_inventory_regexp
35
+ end
36
+ load_ansible_inventory_proc.call
37
+ expect(subject).to receive(:handle_regexp)
38
+ subject.load_ansible_inventory
39
+ end
40
+ end
41
+
42
+ context 'when ansibe_inventory is an Array' do
43
+ it '#load_ansible_inventory calls handle_array' do
44
+ allow(mock_spec).to receive(:ansible_inventory) do
45
+ mock_ansible_inventory_array
46
+ end
47
+
48
+ load_ansible_inventory_proc.call
49
+ expect(subject).to receive(:handle_array)
50
+ subject.load_ansible_inventory
51
+ end
52
+ end
53
+
54
+ it '#handle_array calls generate_machine_config on each node name' do
55
+ group = mock_ansible_inventory_array.keys[0]
56
+ nodes = mock_ansible_inventory_array.values[0]
57
+
58
+ allow(mock_spec).to receive(:ansible_inventory) do
59
+ mock_ansible_inventory_array
60
+ end
61
+
62
+ allow(subject).to receive(:generate_machine_config)
63
+ expect(subject).to receive(:generate_machine_config).with(nodes[0])
64
+
65
+ subject.handle_array(group, nodes)
66
+ end
67
+
68
+ # Inject code into handle_regexp tests
69
+ def handle_regexp_proc
70
+ proc do
71
+ allow(mock_spec).to receive(:ansible_inventory) do
72
+ mock_ansible_inventory_regexp
73
+ end
74
+
75
+ allow(mock_node).to receive(:name) { 'node1' }
76
+ allow(subject).to receive(:generate_machine_config)
77
+ end
78
+ end
79
+
80
+ context 'when nodes are matched' do
81
+ it '#handle_regexp calls generate_machine_config' do
82
+ handle_regexp_proc.call
83
+
84
+ allow(subject.m_finder).to receive(:match_nodes) { [mock_node] }
85
+ expect(subject).to receive(:generate_machine_config).with('node1')
86
+
87
+ subject.handle_regexp('all', /node/)
88
+ end
89
+ end
90
+
91
+ context 'when nodes are not matched' do
92
+ it '#handle_regexp does nothing' do
93
+ handle_regexp_proc.call
94
+
95
+ allow(subject.m_finder).to receive(:match_nodes) {}
96
+ expect(subject).to_not receive(:generate_machine_config)
97
+
98
+ subject.handle_regexp('all', /node/)
99
+ end
100
+ end
101
+
102
+ def generate_machine_config_proc(_name)
103
+ proc do
104
+ allow(mock_spec).to receive(:ansible_inventory) do
105
+ mock_ansible_inventory_regexp
106
+ end
107
+
108
+ allow(subject).to receive(:machine_ssh_config) { mock_machine_ssh_config }
109
+ end
110
+ end
111
+
112
+ context 'when a node is found' do
113
+ it '#generate_machine_config calls machine_ssh_config' do
114
+ name = 'node1'
115
+ generate_machine_config_proc(name).call
116
+
117
+ allow(subject.m_finder).to receive(:machine).with(name.to_sym) do
118
+ mock_node
119
+ end
120
+
121
+ expect(subject).to receive(:machine_ssh_config) do
122
+ { 'name' => mock_machine_ssh_config }
123
+ end
124
+
125
+ subject.generate_machine_config(name)
126
+ end
127
+ end
128
+
129
+ context 'when a node is not found' do
130
+ it '#generate_machine_config does nothing' do
131
+ name = 'node1'
132
+ generate_machine_config_proc(name).call
133
+
134
+ allow(subject.m_finder).to receive(:machine).with(name.to_sym) {}
135
+
136
+ expect(subject).not_to receive(:machine_ssh_config) do
137
+ { 'name' => mock_machine_ssh_config }
138
+ end
139
+
140
+ subject.generate_machine_config(name)
141
+ end
142
+ end
143
+ end
@@ -0,0 +1,105 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+ require 'vagrant_spec/command/base'
5
+
6
+ describe VagrantSpec::Command::Base do
7
+ include_context 'unit'
8
+ include_examples 'shared_mocks'
9
+
10
+ let(:mock_opts) { double(OptionParser) }
11
+ let(:mock_registry) { double(Vagrant::Registry) }
12
+
13
+ before do
14
+ allow(Dir).to receive(:glob) { %w(base.rb foo.rb bar.rb bing.rb) }
15
+ allow_any_instance_of(VagrantSpec::Command::Base)
16
+ .to receive(:instance_variable_get).with('subcommands') { mock_registry }
17
+ end
18
+
19
+ subject { VagrantSpec::Command::Base.new([], iso_env) }
20
+
21
+ it 'VagrantSpec::Command::Base is subclass of Vagrant::Plugin::V2:Command' do
22
+ expect(VagrantSpec::Command::Base).to be < Vagrant::Plugin::V2::Command
23
+ end
24
+
25
+ it 'instance contains the correct valid commands' do
26
+ expect(subject.valid_commands).to eq(%w(foo bar bing))
27
+ end
28
+
29
+ it '#register_subcommands results in the correct length' do
30
+ subject.valid_commands.each do |cmd|
31
+ allow(subject.subcommands).to receive(:register).with(cmd.to_sym)
32
+ expect(subject.subcommands).to receive(:register).with(cmd.to_sym)
33
+ end
34
+ subject.register_subcommands
35
+ end
36
+
37
+ context 'when -h is passed' do
38
+ it '#parse_main_args returns help' do
39
+ i = VagrantSpec::Command::Base.new(%w(-h), iso_env)
40
+ allow(i).to receive(:help)
41
+ expect(i).to receive(:help)
42
+ i.parse_main_args
43
+ end
44
+ end
45
+
46
+ context 'when --help is passed' do
47
+ it '#parse_main_args returns help' do
48
+ i = VagrantSpec::Command::Base.new(%w(--help), iso_env)
49
+ allow(i).to receive(:help)
50
+ expect(i).to receive(:help)
51
+ i.parse_main_args
52
+ end
53
+ end
54
+
55
+ it '#print_help prints help output' do
56
+ i = VagrantSpec::Command::Base.new([], iso_env)
57
+ allow(i).to receive(:instance_variable_get).with('opts') do
58
+ mock_opts
59
+ end
60
+
61
+ allow(i).to receive(:help)
62
+ allow(i.env).to receive(:ui) { mock_ui }
63
+ allow(mock_ui).to receive(:info)
64
+ allow(mock_opts).to receive(:help)
65
+
66
+ expect(i).to receive(:help)
67
+ expect(mock_ui).to receive(:info).with(subject.opts)
68
+
69
+ i.print_help
70
+ end
71
+
72
+ context 'when no @sub_commands are nil' do
73
+ it '#parse_subcommands prints help' do
74
+ allow(subject).to receive(:instance_variable_get).with('sub_command') do
75
+ nil
76
+ end
77
+ allow(subject.subcommands).to receive(:get) { nil }
78
+ allow(subject).to receive(:print_help)
79
+ expect(subject).to receive(:print_help)
80
+ subject.parse_subcommand
81
+ end
82
+ end
83
+
84
+ context 'when @subcommands.get returns nil' do
85
+ it '#parse_subcommands prints help' do
86
+ allow(subject).to receive(:instance_variable_get).with('sub_command') do
87
+ 'mock_command'
88
+ end
89
+ allow(subject.subcommands).to receive(:get) { nil }
90
+ allow(subject).to receive(:print_help)
91
+ expect(subject).to receive(:print_help)
92
+ subject.parse_subcommand
93
+ end
94
+ end
95
+
96
+ it '#execute registers subcommands and parses' do
97
+ allow(subject).to receive(:register_subcommands)
98
+ allow(subject).to receive(:parse_main_args) { 'not_nil' }
99
+ allow(subject).to receive(:parse_subcommand) { 'not_nil' }
100
+ expect(subject).to receive(:register_subcommands)
101
+ expect(subject).to receive(:parse_main_args)
102
+ expect(subject).to receive(:parse_subcommand)
103
+ subject.execute
104
+ end
105
+ end
@@ -0,0 +1,87 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+ require 'vagrant_spec/command/init'
5
+
6
+ describe VagrantSpec::Command::Init do
7
+ include_context 'unit'
8
+ include_examples 'shared_mocks'
9
+
10
+ let(:mock_spec_helper) do
11
+ double(VagrantSpec::SpecHelper)
12
+ end
13
+
14
+ let(:mock_ansible_inventory) do
15
+ double(VagrantSpec::AnsibleInventory)
16
+ end
17
+
18
+ before do
19
+ allow(mock_spec).to receive(:ansible_inventory) { { 'all' => /node/ } }
20
+ end
21
+
22
+ subject { VagrantSpec::Command::Init.new([], iso_env) }
23
+
24
+ it 'VagrantSpec::Command::Init is subclass of Vagrant::Plugin::V2:Command' do
25
+ expect(VagrantSpec::Command::Init).to be < Vagrant::Plugin::V2::Command
26
+ end
27
+
28
+ def execute_proc
29
+ proc do
30
+ allow_any_instance_of(VagrantSpec::SpecHelper).to receive(:generate)
31
+ allow_any_instance_of(VagrantSpec::AnsibleInventory).to receive(:generate)
32
+ allow(mock_spec_helper).to receive(:generate)
33
+ allow(mock_ansible_inventory).to receive(:generate)
34
+ end
35
+ end
36
+
37
+ context 'when parse_opts returns nil' do
38
+ it '#execute does nothing' do
39
+ allow(subject).to receive(:parse_opts) { nil }
40
+ execute_proc.call
41
+ expect(subject.execute).to be_nil
42
+ end
43
+ end
44
+
45
+ context 'when parse_opts does not return nil' do
46
+ def execute_protection_proc
47
+ proc do
48
+ allow(subject).to receive(:parse_opts) { 'not_nil' }
49
+ allow(VagrantSpec::SpecHelper).to receive(:new) do
50
+ mock_spec_helper
51
+ end
52
+ allow(VagrantSpec::AnsibleInventory).to receive(:new) do
53
+ mock_ansible_inventory
54
+ end
55
+ execute_proc.call
56
+ end
57
+ end
58
+
59
+ context 'and when @ansible_inventory eq empty hash,' do
60
+ it '#execute creates an instance of VagrantSpec::SpecHelper' do
61
+ execute_protection_proc.call
62
+ subject.ansible_inventory = {}
63
+
64
+ expect(mock_spec_helper).to receive(:generate)
65
+ expect(mock_ansible_inventory).to_not receive(:generate)
66
+ subject.execute
67
+ end
68
+ end
69
+
70
+ context 'and when @ansible_inventory has data' do
71
+ it '#execute creates instances of SpecHelper and AnsibleInventory' do
72
+ execute_protection_proc.call
73
+ subject.ansible_inventory = { 'all' => /node/ }
74
+
75
+ expect(mock_spec_helper).to receive(:generate)
76
+ expect(mock_ansible_inventory).to receive(:generate)
77
+ subject.execute
78
+ end
79
+ end
80
+ end
81
+
82
+ it '#parse_opts calls parse_options' do
83
+ allow(subject).to receive(:parse_options)
84
+ expect(subject).to receive(:parse_options)
85
+ subject.parse_opts
86
+ end
87
+ end
@@ -0,0 +1,45 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+ require 'vagrant_spec/command/test'
5
+
6
+ describe VagrantSpec::Command::Test do
7
+ include_context 'unit'
8
+ include_examples 'shared_mocks'
9
+
10
+ let(:mock_test) { double(VagrantSpec::TestPlan) }
11
+
12
+ subject { VagrantSpec::Command::Test.new([], iso_env) }
13
+
14
+ context 'when parse_opts returns nil' do
15
+ it '#execute should do nothing' do
16
+ allow(VagrantSpec::TestPlan).to receive(:new) { mock_test }
17
+
18
+ allow(subject).to receive(:parse_opts) { nil }
19
+ allow(mock_test).to receive(:new)
20
+ allow(mock_test).to receive(:run)
21
+
22
+ expect(mock_test).not_to receive(:new)
23
+ subject.execute
24
+ end
25
+ end
26
+
27
+ context 'when parse_opts returns data' do
28
+ it '#execute should test' do
29
+ allow(subject).to receive(:parse_opts) { 'not_nil' }
30
+
31
+ allow(VagrantSpec::TestPlan).to receive(:new) { mock_test }
32
+ allow(mock_test).to receive(:new)
33
+ allow(mock_test).to receive(:run)
34
+
35
+ expect(mock_test).to receive(:run)
36
+ subject.execute
37
+ end
38
+ end
39
+
40
+ it '#parse_opts calls parse_options' do
41
+ allow(subject).to receive(:parse_options)
42
+ expect(subject).to receive(:parse_options)
43
+ subject.parse_opts
44
+ end
45
+ end
@@ -0,0 +1,34 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+ require 'vagrant_spec/config/base'
5
+ require 'vagrant/plugin'
6
+
7
+ describe VagrantSpec::Config::Base do
8
+ include_context 'unit'
9
+ include_examples 'shared_mocks'
10
+
11
+ subject { VagrantSpec::Config::Base.new }
12
+
13
+ it 'VagrantSpec::Config::Base is a subclass of Vagrant::Plugin::V2::Config' do
14
+ expect(VagrantSpec::Config::Base).to be < Vagrant::Plugin::V2::Config
15
+ end
16
+
17
+ %i(directory ansible_inventory test_plan).each do |a|
18
+ it "VagrantSpec::Config::Base has the attr_accessor: #{a}" do
19
+ expect(subject).to have_attr_accessor(a)
20
+ end
21
+ end
22
+
23
+ let(:methods) do
24
+ %w(final_directory final_ansible_inventory final_test_plan)
25
+ end
26
+
27
+ %w(final_directory final_ansible_inventory final_test_plan).each do |method|
28
+ it "#finalize! calls #{method}" do
29
+ methods.each { |m| allow(subject).to receive(m.to_sym) }
30
+ expect(subject).to receive(method.to_sym)
31
+ subject.finalize!
32
+ end
33
+ end
34
+ end