From 4c2e53a27b73b88a81dee745f582392dec5cbcb0 Mon Sep 17 00:00:00 2001 From: Demitri Swan Date: Tue, 9 Aug 2016 17:19:32 -0700 Subject: [PATCH] Adding version sub-command --- lib/vagrant_spec/command/version.rb | 30 +++++++++++++++++++ scripts/poor_mans_smoke_test.sh | 6 ++-- .../command_spec/version_spec.rb | 25 ++++++++++++++++ 3 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 lib/vagrant_spec/command/version.rb create mode 100644 spec/unit/vagrant_spec_test/command_spec/version_spec.rb diff --git a/lib/vagrant_spec/command/version.rb b/lib/vagrant_spec/command/version.rb new file mode 100644 index 0000000..fa9b2ed --- /dev/null +++ b/lib/vagrant_spec/command/version.rb @@ -0,0 +1,30 @@ +# encoding: UTF-8 + +require 'vagrant_spec/version' + +module VagrantSpec + module Command + # Provide CLI interface to retrieving version information + class Version < Vagrant.plugin(2, :command) + def intiialize(argv, env) + @env = env + @argv = argv + end + + def execute + return unless parse_opts + @env.ui.info("vagrant_spec: #{VagrantSpec::VERSION}") + end + + def parse_opts + opts = OptionParser.new do |o| + o.banner = "\nVersion: Output the version of the plugin" + o.separator '' + o.separator 'Usage: vagrant spec version' + o.separator '' + end + parse_options(opts) + end + end + end +end diff --git a/scripts/poor_mans_smoke_test.sh b/scripts/poor_mans_smoke_test.sh index 2cc911a..7b9ed16 100755 --- a/scripts/poor_mans_smoke_test.sh +++ b/scripts/poor_mans_smoke_test.sh @@ -7,13 +7,15 @@ set -e export ANSIBLE_REMOTE_USER=vagrant +bundle exec vagrant spec version +bundle exec vagrant spec version -h bundle exec vagrant spec bundle exec vagrant spec -h bundle exec vagrant spec init -h bundle exec vagrant spec test -h bundle exec vagrant spec no_command -h -rm -f serverspec/spec_helper.rb -rm -f .vagrantspec_machine_data +rm -f "serverspec/spec_helper.rb" +rm -f ".vagrantspec_machine_data" bundle exec vagrant up bundle exec vagrant spec init ansible-playbook site.yml -i vagrantspec_inventory diff --git a/spec/unit/vagrant_spec_test/command_spec/version_spec.rb b/spec/unit/vagrant_spec_test/command_spec/version_spec.rb new file mode 100644 index 0000000..5416bbb --- /dev/null +++ b/spec/unit/vagrant_spec_test/command_spec/version_spec.rb @@ -0,0 +1,25 @@ +# encoding: UTF-8 + +require 'spec_helper' +require 'vagrant_spec/command/version' + +describe VagrantSpec::Command::Version do + include_context 'unit' + include_examples 'shared_mocks' + + subject { VagrantSpec::Command::Version.new([], iso_env) } + + context 'when parse_opts returns data' do + it '#execute calls env.ui.info' do + allow(subject).to receive(:parse_opts) { 'not_nil' } + expect(mock_ui).to receive(:info) + subject.execute + end + end + + it '#parse_opts calls parse_options' do + allow(subject).to receive(:parse_options) + expect(subject).to receive(:parse_options) + subject.parse_opts + end +end