Skip to content

Commit

Permalink
Merge pull request #452 from serverspec/dont-call-backend-directly
Browse files Browse the repository at this point in the history
Fix according to mizzy/specinfra#163
  • Loading branch information
mizzy committed Aug 2, 2014
2 parents 300dfb1 + 7707e53 commit f934d11
Show file tree
Hide file tree
Showing 18 changed files with 25 additions and 114 deletions.
6 changes: 1 addition & 5 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if defined?(RSpec)
task :spec => 'spec:all'

namespace :spec do
task :all => [ 'spec:type:all', 'spec:helper', 'spec:unit' ]
task :all => [ 'spec:type:all', 'spec:helper' ]

namespace :type do
oses = Dir.glob('spec/type/*').map {|d| File.basename(d)}
Expand All @@ -26,9 +26,5 @@ if defined?(RSpec)
RSpec::Core::RakeTask.new(:helper) do |t|
t.pattern = "spec/helper/*_spec.rb"
end

RSpec::Core::RakeTask.new(:unit) do |t|
t.pattern = "spec/unit/*_spec.rb"
end
end
end
21 changes: 9 additions & 12 deletions lib/serverspec/setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def self.run
ask_windows_backend
end

if @backend_type == 'Ssh'
if @backend_type == 'ssh'
print 'Vagrant instance y/n: '
@vagrant = $stdin.gets.chomp
if @vagrant =~ (/(true|t|yes|y|1)$/i)
Expand Down Expand Up @@ -72,7 +72,7 @@ def self.ask_unix_backend
num = $stdin.gets.to_i - 1
puts

@backend_type = ['Ssh', 'Exec'][num] || 'Exec'
@backend_type = ['ssh', 'exec'][num] || 'exec'
end

def self.ask_windows_backend
Expand All @@ -88,7 +88,7 @@ def self.ask_windows_backend
num = $stdin.gets.to_i - 1
puts

@backend_type = ['WinRM', 'Cmd'][num] || 'Exec'
@backend_type = ['winrm', 'cmd'][num] || 'exec'
end

def self.safe_create_spec
Expand Down Expand Up @@ -241,22 +241,19 @@ def self.auto_vagrant_configuration
def self.spec_helper_template
template = <<-'EOF'
require 'serverspec'
<% if @backend_type == 'Ssh' -%>
<% if @backend_type == 'ssh' -%>
require 'net/ssh'
<% end -%>
<%- if @vagrant -%>
require 'tempfile'
<% end -%>
<% if @backend_type == 'WinRM' -%>
<% if @backend_type == 'winrm' -%>
require 'winrm'
<% end -%>
include Specinfra::Helper::<%= @backend_type %>
<% if @os_type != 'UN*X' -%>
include Specinfra::Helper::Windows
<% end -%>
set :backend, :<%= @backend_type %>
<% if @os_type == 'UN*X' && @backend_type == 'Ssh' -%>
<% if @os_type == 'UN*X' && @backend_type == 'ssh' -%>
if ENV['ASK_SUDO_PASSWORD']
begin
require 'highline/import'
Expand All @@ -268,7 +265,7 @@ def self.spec_helper_template
set :sudo_password, ENV['SUDO_PASSWORD']
end
<%- if @backend_type == 'Ssh' -%>
<%- if @backend_type == 'ssh' -%>
host = ENV['TARGET_HOST']
<%- if @vagrant -%>
Expand Down Expand Up @@ -298,7 +295,7 @@ def self.spec_helper_template
# Set PATH
# set :path, '/sbin:/usr/local/sbin:$PATH'
<% if @backend_type == 'WinRM'-%>
<% if @backend_type == 'winrm'-%>
user = <username>
pass = <password>
endpoint = "http://<hostname>:5985/wsman"
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require 'pathname'
require 'rspec/mocks/standalone'

include Specinfra::Helper::Exec
set :backend, :exec

PROJECT_ROOT = (Pathname.new(File.dirname(__FILE__)) + '..').expand_path

Expand Down
3 changes: 1 addition & 2 deletions spec/type/windows/command_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require 'spec_helper'

include Specinfra::Helper::Cmd

set :backend, :cmd
set :os, :family => 'windows'

describe command('test_cmd /test/path/file') do
Expand Down
2 changes: 1 addition & 1 deletion spec/type/windows/feature_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

include Specinfra::Helper::Cmd
set :backend, :cmd

set :os, :family => 'windows'

Expand Down
2 changes: 1 addition & 1 deletion spec/type/windows/file_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

include Specinfra::Helper::Cmd
set :backend, :cmd

set :os, :family => 'windows'

Expand Down
2 changes: 1 addition & 1 deletion spec/type/windows/group_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

include Specinfra::Helper::Cmd
set :backend, :cmd

set :os, :family => 'windows'

Expand Down
2 changes: 1 addition & 1 deletion spec/type/windows/host_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

include Specinfra::Helper::Cmd
set :backend, :cmd
set :os, :family => 'windows'

describe host('127.0.0.1') do
Expand Down
2 changes: 1 addition & 1 deletion spec/type/windows/hot_fix_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

include Specinfra::Helper::Cmd
set :backend, :cmd

set :os, :family => 'windows'

Expand Down
2 changes: 1 addition & 1 deletion spec/type/windows/iis_app_pool_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

include Specinfra::Helper::Cmd
set :backend, :cmd

set :os, :family => 'windows'

Expand Down
2 changes: 1 addition & 1 deletion spec/type/windows/iis_webisite_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

include Specinfra::Helper::Cmd
set :backend, :cmd

set :os, :family => 'windows'

Expand Down
2 changes: 1 addition & 1 deletion spec/type/windows/package_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

include Specinfra::Helper::Cmd
set :backend, :cmd

set :os, :family => 'windows'

Expand Down
2 changes: 1 addition & 1 deletion spec/type/windows/port_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

include Specinfra::Helper::Cmd
set :backend, :cmd

set :os, :family => 'windows'

Expand Down
2 changes: 1 addition & 1 deletion spec/type/windows/registry_key_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

include Specinfra::Helper::Cmd
set :backend, :cmd
set :os, :family => 'windows'

describe windows_registry_key('PATH/TO/THE_KEY') do
Expand Down
2 changes: 1 addition & 1 deletion spec/type/windows/scheduled_task_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

include Specinfra::Helper::Cmd
set :backend, :cmd

set :os, :family => 'windows'

Expand Down
2 changes: 1 addition & 1 deletion spec/type/windows/service_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

include Specinfra::Helper::Cmd
set :backend, :cmd

set :os, :family => 'windows'

Expand Down
2 changes: 1 addition & 1 deletion spec/type/windows/user_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

include Specinfra::Helper::Cmd
set :backend, :cmd

set :os, :family => 'windows'

Expand Down
81 changes: 0 additions & 81 deletions spec/unit/command_spec.rb

This file was deleted.

0 comments on commit f934d11

Please sign in to comment.