Move acceptance spec "utility methods" out to an example group
This commit is contained in:
parent
8c8c11f07c
commit
6adebb695c
3 changed files with 51 additions and 46 deletions
|
@ -71,44 +71,4 @@ describe 'Sanity check' do
|
||||||
expect(containers).to_not include @container_name
|
expect(containers).to_not include @container_name
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
45
spec/acceptance/support/acceptance_example_group.rb
Normal file
45
spec/acceptance/support/acceptance_example_group.rb
Normal file
|
@ -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
|
|
@ -1,7 +1,7 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
unless ENV['USER'] == 'vagrant'
|
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
|
exit 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -14,8 +14,8 @@ require 'vagrant-lxc'
|
||||||
|
|
||||||
Dir[File.dirname(__FILE__) + "/acceptance/support/**/*.rb"].each { |f| require f }
|
Dir[File.dirname(__FILE__) + "/acceptance/support/**/*.rb"].each { |f| require f }
|
||||||
|
|
||||||
# RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
# config.include AcceptanceExampleGroup, :type => :unit, :example_group => {
|
config.include AcceptanceExampleGroup, :type => :acceptance, :example_group => {
|
||||||
# :file_path => /\bspec\/unit\//
|
:file_path => /\bspec\/acceptance\//
|
||||||
# }
|
}
|
||||||
# end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue