From 6adebb695c1b74f2ac62d042c12febf55ff16419 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Sun, 21 Apr 2013 18:38:02 -0300 Subject: [PATCH] Move acceptance spec "utility methods" out to an example group --- spec/acceptance/sanity_check_spec.rb | 40 ----------------- .../support/acceptance_example_group.rb | 45 +++++++++++++++++++ spec/acceptance_helper.rb | 12 ++--- 3 files changed, 51 insertions(+), 46 deletions(-) create mode 100644 spec/acceptance/support/acceptance_example_group.rb diff --git a/spec/acceptance/sanity_check_spec.rb b/spec/acceptance/sanity_check_spec.rb index 782e6aa..2206bf2 100644 --- a/spec/acceptance/sanity_check_spec.rb +++ b/spec/acceptance/sanity_check_spec.rb @@ -71,44 +71,4 @@ describe 'Sanity check' do expect(containers).to_not include @container_name end end - - def destroy_container - `sudo lxc-shutdown -n \`cat /vagrant/spec/.vagrant/machines/default/lxc/id\` 2>/dev/null` - `sudo lxc-wait -n \`cat /vagrant/spec/.vagrant/machines/default/lxc/id\` --state STOPPED 2>/dev/null` - `sudo lxc-destroy -n \`cat /vagrant/spec/.vagrant/machines/default/lxc/id\` 2>/dev/null` - `sudo killall -9 redir 2>/dev/null` - end - - def vagrant_up - opts = { cwd: 'spec' } - env = Vagrant::Environment.new(opts) - env.cli('up', '--provider', 'lxc') - env.unload - end - - def vagrant_halt - opts = { cwd: 'spec' } - env = Vagrant::Environment.new(opts) - env.cli('halt') - env.unload - end - - def vagrant_destroy - opts = { cwd: 'spec' } - env = Vagrant::Environment.new(opts) - env.cli('destroy', '-f') - env.unload - end - - def vagrant_ssh(cmd) - opts = { cwd: 'spec', ui_class: TestUI } - env = Vagrant::Environment.new(opts) - result = env.cli('ssh', '-c', cmd) - if result.to_i != 0 - raise "SSH command failed: '#{cmd}'\n#{env.ui.messages.inspect}" - end - output = env.ui.messages[:info].join("\n").chomp - env.unload - output - end end diff --git a/spec/acceptance/support/acceptance_example_group.rb b/spec/acceptance/support/acceptance_example_group.rb new file mode 100644 index 0000000..2c28c12 --- /dev/null +++ b/spec/acceptance/support/acceptance_example_group.rb @@ -0,0 +1,45 @@ +module AcceptanceExampleGroup + def self.included(base) + base.metadata[:type] = :acceptance + end + + def destroy_container + `sudo lxc-shutdown -n \`cat /vagrant/spec/.vagrant/machines/default/lxc/id\` 2>/dev/null` + `sudo lxc-wait -n \`cat /vagrant/spec/.vagrant/machines/default/lxc/id\` --state STOPPED 2>/dev/null` + `sudo lxc-destroy -n \`cat /vagrant/spec/.vagrant/machines/default/lxc/id\` 2>/dev/null` + `sudo killall -9 redir 2>/dev/null` + end + + def vagrant_up + opts = { cwd: 'spec' } + env = Vagrant::Environment.new(opts) + env.cli('up', '--provider', 'lxc') + env.unload + end + + def vagrant_halt + opts = { cwd: 'spec' } + env = Vagrant::Environment.new(opts) + env.cli('halt') + env.unload + end + + def vagrant_destroy + opts = { cwd: 'spec' } + env = Vagrant::Environment.new(opts) + env.cli('destroy', '-f') + env.unload + end + + def vagrant_ssh(cmd) + opts = { cwd: 'spec', ui_class: TestUI } + env = Vagrant::Environment.new(opts) + result = env.cli('ssh', '-c', cmd) + if result.to_i != 0 + raise "SSH command failed: '#{cmd}'\n#{env.ui.messages.inspect}" + end + output = env.ui.messages[:info].join("\n").chomp + env.unload + output + end +end diff --git a/spec/acceptance_helper.rb b/spec/acceptance_helper.rb index 03105f9..ff45967 100644 --- a/spec/acceptance_helper.rb +++ b/spec/acceptance_helper.rb @@ -1,7 +1,7 @@ require 'spec_helper' unless ENV['USER'] == 'vagrant' - puts 'Acceptance specs are supposed to run from one of the vagrant dev machines' + puts 'Acceptance specs are supposed to run from one of the vagrant-lxc dev machines' exit 1 end @@ -14,8 +14,8 @@ require 'vagrant-lxc' Dir[File.dirname(__FILE__) + "/acceptance/support/**/*.rb"].each { |f| require f } -# RSpec.configure do |config| -# config.include AcceptanceExampleGroup, :type => :unit, :example_group => { -# :file_path => /\bspec\/unit\// -# } -# end +RSpec.configure do |config| + config.include AcceptanceExampleGroup, :type => :acceptance, :example_group => { + :file_path => /\bspec\/acceptance\// + } +end