Skip to content

Commit a109ac1

Browse files
committed
add serverspecs
1 parent dcbbdf3 commit a109ac1

5 files changed

Lines changed: 95 additions & 0 deletions

File tree

Gemfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
source 'https://rubygems.org'
2+
3+
gem 'rspec'
4+
gem 'serverspec'
5+
gem 'rake'

Gemfile.lock

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
diff-lcs (1.2.5)
5+
highline (1.6.20)
6+
net-ssh (2.8.0)
7+
rake (10.1.1)
8+
rspec (2.14.1)
9+
rspec-core (~> 2.14.0)
10+
rspec-expectations (~> 2.14.0)
11+
rspec-mocks (~> 2.14.0)
12+
rspec-core (2.14.7)
13+
rspec-expectations (2.14.5)
14+
diff-lcs (>= 1.1.3, < 2.0)
15+
rspec-mocks (2.14.5)
16+
serverspec (0.15.1)
17+
highline
18+
net-ssh
19+
rspec (>= 2.13.0)
20+
specinfra (>= 0.5.4)
21+
specinfra (0.5.4)
22+
23+
PLATFORMS
24+
ruby
25+
26+
DEPENDENCIES
27+
rake
28+
rspec
29+
serverspec

Rakefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
require 'rake'
2+
require 'rspec/core/rake_task'
3+
4+
RSpec::Core::RakeTask.new(:spec) do |t|
5+
t.pattern = 'spec/*/*_spec.rb'
6+
end

spec/httpd_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require 'spec_helper'
2+
3+
describe port(80) do
4+
it { should be_listening }
5+
end
6+
7+
describe file('/opt/neo4j/neo4j-community-2.0.0') do
8+
it { should be_directory }
9+
end

spec/spec_helper.rb

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
require 'serverspec'
2+
require 'pathname'
3+
require 'net/ssh'
4+
5+
include SpecInfra::Helper::Ssh
6+
include SpecInfra::Helper::DetectOS
7+
8+
RSpec.configure do |c|
9+
if ENV['ASK_SUDO_PASSWORD']
10+
require 'highline/import'
11+
c.sudo_password = ask("Enter sudo password: ") { |q| q.echo = false }
12+
else
13+
c.sudo_password = ENV['SUDO_PASSWORD']
14+
end
15+
c.before :all do
16+
block = self.class.metadata[:example_group_block]
17+
if RUBY_VERSION.start_with?('1.8')
18+
file = block.to_s.match(/.*@(.*):[0-9]+>/)[1]
19+
else
20+
file = block.source_location.first
21+
end
22+
host = File.basename(Pathname.new(file).dirname)
23+
if c.host != host
24+
c.ssh.close if c.ssh
25+
c.host = host
26+
options = Net::SSH::Config.for(c.host)
27+
user = options[:user] || Etc.getlogin
28+
vagrant_up = `vagrant up `
29+
config = `vagrant ssh-config `
30+
if config != ''
31+
config.each_line do |line|
32+
if match = /HostName (.*)/.match(line)
33+
host = match[1]
34+
elsif match = /User (.*)/.match(line)
35+
user = match[1]
36+
elsif match = /IdentityFile (.*)/.match(line)
37+
options[:keys] = [match[1].gsub(/"/,'')]
38+
elsif match = /Port (.*)/.match(line)
39+
options[:port] = match[1]
40+
end
41+
end
42+
end
43+
c.ssh = Net::SSH.start(host, user, options)
44+
end
45+
end
46+
end

0 commit comments

Comments
 (0)