rspec-system 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ Gemfile.lock
2
+ .*.swp
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-1.9.3-p362@rspec-system-vagrant
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
@@ -0,0 +1 @@
1
+ tmp
@@ -0,0 +1,14 @@
1
+ require 'system_spec_helper.rb'
2
+
3
+ describe "Centos 5.8 x86_64", :scope => :all do
4
+ let(:rspec_system_config) do
5
+ {
6
+ :id => 'centos-58-x64',
7
+ :nodes => {
8
+ 'main' => {
9
+ :prefab => 'centos-58-x64',
10
+ }
11
+ }
12
+ }
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ require 'system_spec_helper'
2
+
3
+ describe 'Debian 6.0.6 x86_64', :scope => :all do
4
+ let(:rspec_system_config) do
5
+ {
6
+ :id => 'debian-606-x64',
7
+ :nodes => {
8
+ 'main' => {
9
+ :prefab => 'debian-606-x64',
10
+ }
11
+ }
12
+ }
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ require 'system_spec_helper'
2
+
3
+ shared_examples "test1", :scope => :all do
4
+ it 'run test1 - part1' do
5
+ puts 'test1 - part1'
6
+ run_on('main', "cat /etc/resolv.conf")
7
+ end
8
+
9
+ it 'run test1 - part2' do
10
+ puts 'test1 - part2'
11
+ run_on('main', "cat /etc/issue")
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ require 'system_spec_helper'
2
+
3
+ shared_examples "test2", :scope => :all do
4
+ it 'run test2 - part1' do
5
+ puts 'test2 - part1'
6
+ end
7
+
8
+ it 'run test2 - part2' do
9
+ puts 'test2 - part2'
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ require 'rspec-system'
2
+ require 'system/tests/test1'
3
+ require 'system/tests/test2'
4
+
5
+ RSpec.configure do |c|
6
+ c.rspec_system_vagrant_projects = File.join(File.dirname(__FILE__), 'system', 'tmp', 'rspec_system_vagrant')
7
+ end
@@ -0,0 +1 @@
1
+ {"active":{"main":"890d1d49-5bac-4373-99ff-7b8b8d144c38"}}
@@ -0,0 +1,6 @@
1
+ Vagrant::Config.run do |c| c.vm.define 'main' do |vmconf|
2
+ vmconf.vm.box = 'centos-58-x64'
3
+ vmconf.vm.box_url = 'http://puppet-vagrant-boxes.puppetlabs.com/centos-58-x64.box'
4
+
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module RSpecSystem::Helpers
2
+ def run_on(dest, command)
3
+ rspec_system_node_set.run(dest,command)
4
+ end
5
+ end
@@ -0,0 +1,88 @@
1
+ require 'vagrant'
2
+ require 'fileutils'
3
+
4
+ module RSpecSystem
5
+ class NodeSet::Vagrant
6
+ def initialize(config)
7
+ @config = config
8
+ @vagrant_path = File.expand_path(File.join(RSpec.configuration.rspec_system_vagrant_projects, @config[:id].to_s))
9
+ end
10
+
11
+ def setup
12
+ puts "Setting up vagrant!"
13
+ create_virtualboxfile
14
+
15
+ puts "prepping vagrant environment"
16
+ @vagrant_env = Vagrant::Environment.new(:cwd => @vagrant_path)
17
+ puts "running vagrant up"
18
+ @vagrant_env.cli("up")
19
+
20
+ snapshot
21
+ end
22
+
23
+ def teardown
24
+ puts "running vagrant down"
25
+ @vagrant_env.cli("suspend")
26
+ end
27
+
28
+ def snapshot
29
+ puts "turning on sandbox"
30
+ Dir.chdir(@vagrant_path) do
31
+ @vagrant_env.cli("sandbox", "on")
32
+ end
33
+ end
34
+
35
+ def rollback
36
+ puts "rolling back vagrant box"
37
+ Dir.chdir(@vagrant_path) do
38
+ @vagrant_env.cli("sandbox", "rollback")
39
+ end
40
+ end
41
+
42
+ def run(dest, command)
43
+ puts "Running #{command} on #{dest}"
44
+ result = ""
45
+ @vagrant_env.vms[dest.to_sym].channel.sudo("cd /tmp && #{command}") do |ch, data|
46
+ result << data
47
+ puts "Got data: #{data}"
48
+ end
49
+ result
50
+ end
51
+
52
+ # @api private
53
+ def create_virtualboxfile
54
+ puts "Creating vagrant file here: #{@vagrant_path}"
55
+ FileUtils.mkdir_p(@vagrant_path)
56
+ File.open(File.expand_path(File.join(@vagrant_path, "Vagrantfile")), 'w') do |f|
57
+ f.write('Vagrant::Config.run do |c|')
58
+ @config[:nodes].each do |k,v|
59
+ puts "prepping #{k}"
60
+ f.write(<<-EOS)
61
+ c.vm.define '#{k}' do |vmconf|
62
+ #{setup_prefabs(v[:prefab])}
63
+ end
64
+ EOS
65
+ end
66
+ f.write('end')
67
+ end
68
+ end
69
+
70
+ # @api private
71
+ def setup_prefabs(prefab)
72
+ case prefab
73
+ when 'centos-58-x64'
74
+ <<-EOS
75
+ vmconf.vm.box = 'centos-58-x64'
76
+ vmconf.vm.box_url = 'http://puppet-vagrant-boxes.puppetlabs.com/centos-58-x64.box'
77
+ EOS
78
+ when 'debian-606-x64'
79
+ <<-EOS
80
+ vmconf.vm.box = 'debian-606-x64'
81
+ vmconf.vm.box_url = 'http://puppet-vagrant-boxes.puppetlabs.com/debian-606-x64.box'
82
+ EOS
83
+ else
84
+ raise 'Unknown prefab'
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,35 @@
1
+ module RSpecSystem
2
+ class NodeSet
3
+ attr_reader :config, :virtual_env
4
+
5
+ def initialize(config, virtual_env)
6
+ @config = config
7
+ @virtual_env = virtual_env
8
+
9
+ @virtual_driver = case(@virtual_env)
10
+ when 'vagrant'
11
+ RSpecSystem::NodeSet::Vagrant.new(@config)
12
+ else
13
+ raise "Unsupported virtual environment #{@virtual_env}"
14
+ end
15
+ end
16
+
17
+ def setup
18
+ @virtual_driver.setup
19
+ end
20
+
21
+ def teardown
22
+ @virtual_driver.teardown
23
+ end
24
+
25
+ def rollback
26
+ @virtual_driver.rollback
27
+ end
28
+
29
+ def run(dest, command)
30
+ @virtual_driver.run(dest,command)
31
+ end
32
+ end
33
+ end
34
+
35
+ require 'rspec-system/node_set/vagrant'
@@ -0,0 +1,44 @@
1
+ require 'logger'
2
+
3
+ shared_context "shared stuff", :scope => :all do
4
+ # Grab the type of virtual environment we wish to run these tests in
5
+ let(:rspec_virtual_env) do
6
+ ENV["RSPEC_VIRTUAL_ENV"] || 'vagrant'
7
+ end
8
+
9
+ let(:rspec_system_node_set) do
10
+ RSpecSystem::NodeSet.new(rspec_system_config, rspec_virtual_env)
11
+ end
12
+
13
+ let(:rspec_system_logger) do
14
+ Logger::DEBUG
15
+ end
16
+
17
+ before :all do
18
+ require 'pp'
19
+
20
+ puts "Configuration for now is:"
21
+ puts rspec_system_node_set.config.pretty_inspect
22
+ puts "Virtual Environment is: #{rspec_system_node_set.virtual_env}"
23
+
24
+ rspec_system_node_set.setup
25
+
26
+ puts 'before all: setup vms'
27
+ puts 'before all: snapshot vms'
28
+ end
29
+
30
+ before :each do
31
+ puts 'before each: roll back vms'
32
+ rspec_system_node_set.rollback
33
+ end
34
+
35
+ after :each do
36
+ puts 'after each: roll back vms'
37
+ rspec_system_node_set.rollback
38
+ end
39
+
40
+ after :all do
41
+ puts 'after all: shut down all vms'
42
+ rspec_system_node_set.teardown
43
+ end
44
+ end
@@ -0,0 +1,14 @@
1
+ require 'rspec'
2
+
3
+ module RSpecSystem; end
4
+
5
+ require 'rspec-system/helpers'
6
+ require 'rspec-system/node_set'
7
+ require 'rspec-system/shared_contexts'
8
+
9
+ RSpec::configure do |c|
10
+ c.include RSpecSystem::Helpers
11
+
12
+ # This provides a path to save vagrant files
13
+ c.add_setting :rspec_system_vagrant_projects
14
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ Gem::Specification.new do |s|
3
+ # Metadata
4
+ s.name = "rspec-system"
5
+ s.version = "0.0.1"
6
+ s.authors = ["Ken Barber"]
7
+ s.email = ["ken@bob.sh"]
8
+ s.homepage = "https://github.com/kbarber/rspec-system"
9
+ s.summary = "System testing with vagrant"
10
+
11
+ # Manifest
12
+ s.files = `git ls-files`.split("\n")
13
+ s.test_files = `git ls-files -- {test,spec,features}/*_spec.rb`.split("\n")
14
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
15
+ s.require_paths = ["lib"]
16
+
17
+ # Dependencies
18
+ s.required_ruby_version = '>= 1.9.3'
19
+ s.add_runtime_dependency "vagrant"
20
+ s.add_runtime_dependency "sahara"
21
+ s.add_runtime_dependency "rspec"
22
+ s.add_development_dependency "simplecov"
23
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec-system
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ken Barber
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: vagrant
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: sahara
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: simplecov
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description:
79
+ email:
80
+ - ken@bob.sh
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .gitignore
86
+ - .ruby-version
87
+ - Gemfile
88
+ - examples/spec/.gitignore
89
+ - examples/spec/system/distros/centos-58-x64_spec.rb
90
+ - examples/spec/system/distros/debian-606-x64_spec.rb
91
+ - examples/spec/system/tests/test1.rb
92
+ - examples/spec/system/tests/test2.rb
93
+ - examples/spec/system_spec_helper.rb
94
+ - examples/spec/systemtmp/rspec_system_vagrant/centos-58-x64/.vagrant
95
+ - examples/spec/systemtmp/rspec_system_vagrant/centos-58-x64/Vagrantfile
96
+ - lib/rspec-system.rb
97
+ - lib/rspec-system/helpers.rb
98
+ - lib/rspec-system/node_set.rb
99
+ - lib/rspec-system/node_set/vagrant.rb
100
+ - lib/rspec-system/shared_contexts.rb
101
+ - rspec-system.gemspec
102
+ homepage: https://github.com/kbarber/rspec-system
103
+ licenses: []
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ! '>='
112
+ - !ruby/object:Gem::Version
113
+ version: 1.9.3
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ! '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 1.8.24
123
+ signing_key:
124
+ specification_version: 3
125
+ summary: System testing with vagrant
126
+ test_files: []