serverspec 0.5.8 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. data/lib/serverspec.rb +37 -33
  2. data/lib/serverspec/helper.rb +0 -3
  3. data/lib/serverspec/matchers.rb +18 -34
  4. data/lib/serverspec/matchers/be_executable.rb +1 -9
  5. data/lib/serverspec/matchers/be_installed.rb +1 -15
  6. data/lib/serverspec/matchers/be_mounted.rb +1 -5
  7. data/lib/serverspec/matchers/be_reachable.rb +1 -5
  8. data/lib/serverspec/matchers/be_readable.rb +1 -9
  9. data/lib/serverspec/matchers/be_resolvable.rb +1 -5
  10. data/lib/serverspec/matchers/be_running.rb +1 -15
  11. data/lib/serverspec/matchers/be_writable.rb +1 -9
  12. data/lib/serverspec/matchers/belong_to_group.rb +1 -5
  13. data/lib/serverspec/matchers/contain.rb +1 -11
  14. data/lib/serverspec/matchers/have_entry.rb +0 -2
  15. data/lib/serverspec/matchers/match_md5checksum.rb +1 -5
  16. data/lib/serverspec/matchers/return_exit_status.rb +1 -6
  17. data/lib/serverspec/matchers/return_stderr.rb +1 -10
  18. data/lib/serverspec/matchers/return_stdout.rb +1 -10
  19. data/lib/serverspec/version.rb +1 -1
  20. data/spec/darwin/commands_spec.rb +1 -1
  21. data/spec/debian/commands_spec.rb +1 -1
  22. data/spec/gentoo/commands_spec.rb +1 -1
  23. data/spec/redhat/commands_spec.rb +1 -1
  24. data/spec/solaris/commands_spec.rb +1 -1
  25. data/spec/solaris/service_spec.rb +1 -1
  26. data/spec/support/shared_commands_examples.rb +2 -2
  27. data/spec/support/shared_cron_examples.rb +4 -4
  28. data/spec/support/shared_group_examples.rb +2 -2
  29. data/spec/support/shared_iptables_examples.rb +2 -2
  30. data/spec/support/shared_package_examples.rb +4 -4
  31. data/spec/support/shared_user_examples.rb +2 -2
  32. metadata +3 -45
  33. data/lib/serverspec/backend/puppet.rb +0 -108
  34. data/lib/serverspec/filter.rb +0 -21
  35. data/lib/serverspec/helper/obsoleted.rb +0 -74
  36. data/lib/serverspec/matchers/be_default_gateway.rb +0 -14
  37. data/lib/serverspec/matchers/be_directory.rb +0 -9
  38. data/lib/serverspec/matchers/be_disabled.rb +0 -9
  39. data/lib/serverspec/matchers/be_enabled.rb +0 -9
  40. data/lib/serverspec/matchers/be_enforcing.rb +0 -10
  41. data/lib/serverspec/matchers/be_file.rb +0 -9
  42. data/lib/serverspec/matchers/be_group.rb +0 -5
  43. data/lib/serverspec/matchers/be_grouped_into.rb +0 -9
  44. data/lib/serverspec/matchers/be_linked_to.rb +0 -9
  45. data/lib/serverspec/matchers/be_listening.rb +0 -10
  46. data/lib/serverspec/matchers/be_mode.rb +0 -9
  47. data/lib/serverspec/matchers/be_owned_by.rb +0 -9
  48. data/lib/serverspec/matchers/be_permissive.rb +0 -9
  49. data/lib/serverspec/matchers/be_user.rb +0 -5
  50. data/lib/serverspec/matchers/be_zfs.rb +0 -9
  51. data/lib/serverspec/matchers/get_stdout.rb +0 -14
  52. data/lib/serverspec/matchers/have_authorized_key.rb +0 -9
  53. data/lib/serverspec/matchers/have_cron_entry.rb +0 -9
  54. data/lib/serverspec/matchers/have_gid.rb +0 -10
  55. data/lib/serverspec/matchers/have_home_directory.rb +0 -10
  56. data/lib/serverspec/matchers/have_ipfilter_rule.rb +0 -5
  57. data/lib/serverspec/matchers/have_ipnat_rule.rb +0 -5
  58. data/lib/serverspec/matchers/have_iptables_rule.rb +0 -11
  59. data/lib/serverspec/matchers/have_login_shell.rb +0 -10
  60. data/lib/serverspec/matchers/have_svcprop.rb +0 -9
  61. data/lib/serverspec/matchers/have_svcprops.rb +0 -5
  62. data/lib/serverspec/matchers/have_uid.rb +0 -10
  63. data/spec/darwin/matchers_spec.rb +0 -89
  64. data/spec/debian/matchers_spec.rb +0 -92
  65. data/spec/gentoo/matchers_spec.rb +0 -93
  66. data/spec/redhat/matchers_spec.rb +0 -98
  67. data/spec/solaris/matchers_spec.rb +0 -92
  68. data/spec/support/shared_matcher_examples.rb +0 -1310
@@ -5,7 +5,6 @@ require 'serverspec/matchers'
5
5
  require 'serverspec/backend'
6
6
  require 'serverspec/helper'
7
7
  require 'serverspec/setup'
8
- require 'serverspec/filter'
9
8
  require 'serverspec/subject'
10
9
  require 'serverspec/commands/base'
11
10
  require 'serverspec/commands/linux'
@@ -15,6 +14,7 @@ require 'serverspec/commands/gentoo'
15
14
  require 'serverspec/commands/solaris'
16
15
  require 'serverspec/commands/darwin'
17
16
  require 'serverspec/configuration'
17
+ require 'rspec/core/formatters/base_formatter'
18
18
 
19
19
  include Serverspec
20
20
 
@@ -40,20 +40,6 @@ RSpec.configure do |c|
40
40
  Serverspec.configuration.defaults.each { |k, v| c.add_setting k, :default => v }
41
41
  c.before :each do
42
42
  backend.set_example(example)
43
- if described_class.nil?
44
- puts
45
- puts "*****************************************"
46
- puts "Using a string as a subject is obsoleted."
47
- puts "Please use a subject type object instead."
48
- puts "See: http://serverspec.org/matchers.html"
49
- puts "*****************************************"
50
- puts
51
- end
52
- if described_class.nil? && subject == 'value'
53
- def subject
54
- Serverspec::Filter.filter_subject example
55
- end
56
- end
57
43
  end
58
44
  end
59
45
 
@@ -62,27 +48,45 @@ module RSpec
62
48
  module DSL
63
49
  class Matcher
64
50
  def failure_message_for_should(&block)
65
- if block.to_s =~ /serverspec\/matchers\/.+\.rb/
66
- @custom = true
67
- end
68
- if @custom
69
- cache_or_call_cached(:failure_message_for_should, &block)
70
- else
71
- message = "#{example.metadata[:command]}\n"
72
- message += "#{example.metadata[:stdout]}"
73
- message
74
- end
51
+ message = "#{example.metadata[:command]}\n"
52
+ message += "#{example.metadata[:stdout]}"
53
+ message
75
54
  end
76
55
  def failure_message_for_should_not(&block)
77
- if block.to_s =~ /serverspec\/matchers\/.+\.rb/
78
- @custom = true
56
+ message = "#{example.metadata[:command]}\n"
57
+ message += "#{example.metadata[:stdout]}"
58
+ message
59
+ end
60
+ end
61
+ end
62
+ end
63
+ module Core
64
+ module Formatters
65
+ class BaseTextFormatter < BaseFormatter
66
+ def dump_failure_info(example)
67
+ exception = example.execution_result[:exception]
68
+ exception_class_name = exception_class_name_for(exception)
69
+ output.puts "#{long_padding}#{failure_color("Failure/Error:")} #{failure_color(read_failed_line(exception, example).strip)}"
70
+ output.puts "#{long_padding}#{failure_color(exception_class_name)}:" unless exception_class_name =~ /RSpec/
71
+ output.puts "#{long_padding} #{failure_color(example.metadata[:command])}"
72
+ output.puts "#{long_padding} #{failure_color(example.metadata[:stdout])}" if example.metadata[:stdout] != ''
73
+
74
+ if shared_group = find_shared_group(example)
75
+ dump_shared_failure_info(shared_group)
79
76
  end
80
- if @custom
81
- cache_or_call_cached(:failure_message_for_should, &block)
82
- else
83
- message = "#{example.metadata[:command]}\n"
84
- message += "#{example.metadata[:stdout]}"
85
- message
77
+ end
78
+ end
79
+ class ProgressFormatter < BaseTextFormatter
80
+ def dump_failure_info(example)
81
+ exception = example.execution_result[:exception]
82
+ exception_class_name = exception_class_name_for(exception)
83
+ output.puts "#{long_padding}#{failure_color("Failure/Error:")} #{failure_color(read_failed_line(exception, example).strip)}"
84
+ output.puts "#{long_padding}#{failure_color(exception_class_name)}:" unless exception_class_name =~ /RSpec/
85
+ output.puts "#{long_padding} #{failure_color(example.metadata[:command])}"
86
+ output.puts "#{long_padding} #{failure_color(example.metadata[:stdout])}" if example.metadata[:stdout] != ''
87
+
88
+ if shared_group = find_shared_group(example)
89
+ dump_shared_failure_info(shared_group)
86
90
  end
87
91
  end
88
92
  end
@@ -13,9 +13,6 @@ require 'serverspec/helper/solaris'
13
13
  require 'serverspec/helper/darwin'
14
14
  require 'serverspec/helper/detect_os'
15
15
 
16
- # Obsoleted helpers
17
- require 'serverspec/helper/obsoleted'
18
-
19
16
  # Attributes helper
20
17
  require 'serverspec/helper/attributes'
21
18
 
@@ -1,46 +1,30 @@
1
+ # file
1
2
  require 'serverspec/matchers/be_mounted'
3
+ require 'serverspec/matchers/contain'
4
+ require 'serverspec/matchers/be_readable'
5
+ require 'serverspec/matchers/be_writable'
6
+ require 'serverspec/matchers/be_executable'
7
+ require 'serverspec/matchers/match_md5checksum'
8
+
9
+ # host
2
10
  require 'serverspec/matchers/be_resolvable'
3
- require 'serverspec/matchers/be_enabled'
4
- require 'serverspec/matchers/be_file'
5
11
  require 'serverspec/matchers/be_reachable'
6
- require 'serverspec/matchers/be_default_gateway'
7
- require 'serverspec/matchers/be_directory'
12
+
13
+ # package
8
14
  require 'serverspec/matchers/be_installed'
9
- require 'serverspec/matchers/be_listening'
15
+
16
+ # service
10
17
  require 'serverspec/matchers/be_running'
11
- require 'serverspec/matchers/contain'
12
- require 'serverspec/matchers/be_user'
13
- require 'serverspec/matchers/be_group'
14
- require 'serverspec/matchers/be_mode'
15
- require 'serverspec/matchers/be_owned_by'
16
- require 'serverspec/matchers/be_grouped_into'
17
- require 'serverspec/matchers/have_entry'
18
- require 'serverspec/matchers/have_cron_entry'
19
- require 'serverspec/matchers/be_linked_to'
18
+
19
+ # user
20
20
  require 'serverspec/matchers/belong_to_group'
21
- require 'serverspec/matchers/have_gid'
22
- require 'serverspec/matchers/have_uid'
23
- require 'serverspec/matchers/have_login_shell'
24
- require 'serverspec/matchers/have_home_directory'
25
- require 'serverspec/matchers/have_authorized_key'
26
- require 'serverspec/matchers/have_iptables_rule'
27
- require 'serverspec/matchers/get_stdout'
28
- require 'serverspec/matchers/be_zfs'
29
- require 'serverspec/matchers/be_readable'
30
- require 'serverspec/matchers/be_writable'
31
- require 'serverspec/matchers/be_executable'
32
- require 'serverspec/matchers/be_enforcing'
33
- require 'serverspec/matchers/be_permissive'
34
- require 'serverspec/matchers/be_disabled'
35
- require 'serverspec/matchers/have_ipfilter_rule'
36
- require 'serverspec/matchers/have_ipnat_rule'
37
- require 'serverspec/matchers/have_svcprop'
38
- require 'serverspec/matchers/have_svcprops'
21
+
39
22
  require 'serverspec/matchers/return_exit_status'
40
23
  require 'serverspec/matchers/return_stdout'
41
24
  require 'serverspec/matchers/return_stderr'
42
- require 'serverspec/matchers/match_md5checksum'
43
25
 
44
- # For explicit types
26
+ # ipfiter, ipnat, iptables
45
27
  require 'serverspec/matchers/have_rule'
46
28
 
29
+ # cron, routing_table
30
+ require 'serverspec/matchers/have_entry'
@@ -1,14 +1,6 @@
1
1
  RSpec::Matchers.define :be_executable do
2
2
  match do |file|
3
- if file.respond_to?(:executable?)
4
- file.executable?(@by_whom, @by_user)
5
- else
6
- if @by_user != nil
7
- backend.check_access_by_user(file, @by_user, 'x')
8
- else
9
- backend.check_executable(file, @by_whom)
10
- end
11
- end
3
+ file.executable?(@by_whom, @by_user)
12
4
  end
13
5
  chain :by do |by_whom|
14
6
  @by_whom = by_whom
@@ -1,20 +1,6 @@
1
1
  RSpec::Matchers.define :be_installed do
2
2
  match do |name|
3
- if name.respond_to?(:installed?)
4
- name.installed?(@provider, @version)
5
- else
6
- if @provider.nil?
7
- backend.check_installed(name)
8
- else
9
- check_method = "check_installed_by_#{@provider}".to_sym
10
-
11
- unless backend.respond_to?(check_method) || commands.respond_to?(check_method)
12
- raise ArgumentError.new("`be_installed` matcher doesn't support #{@under}")
13
- end
14
-
15
- backend.send(check_method, name, @version)
16
- end
17
- end
3
+ name.installed?(@provider, @version)
18
4
  end
19
5
 
20
6
  chain :by do |provider|
@@ -1,10 +1,6 @@
1
1
  RSpec::Matchers.define :be_mounted do
2
2
  match do |path|
3
- if path.respond_to?(:mounted?)
4
- path.mounted?(@attr, @only_with)
5
- else
6
- backend.check_mounted(path, @attr, @only_with)
7
- end
3
+ path.mounted?(@attr, @only_with)
8
4
  end
9
5
  chain :with do |attr|
10
6
  @attr = attr
@@ -8,11 +8,7 @@ RSpec::Matchers.define :be_reachable do
8
8
  timeout = @attr[:timeout] if @attr[:timeout]
9
9
  end
10
10
 
11
- if host.respond_to?(:reachable?)
12
- host.reachable?(port, proto, timeout)
13
- else
14
- backend.check_reachable(host, port, proto, timeout)
15
- end
11
+ host.reachable?(port, proto, timeout)
16
12
  end
17
13
 
18
14
  chain :with do |attr|
@@ -1,14 +1,6 @@
1
1
  RSpec::Matchers.define :be_readable do
2
2
  match do |file|
3
- if file.respond_to?(:readable?)
4
- file.readable?(@by_whom, @by_user)
5
- else
6
- if @by_user != nil
7
- backend.check_access_by_user(file, @by_user, 'r')
8
- else
9
- backend.check_readable(file, @by_whom)
10
- end
11
- end
3
+ file.readable?(@by_whom, @by_user)
12
4
  end
13
5
  chain :by do |by_whom|
14
6
  @by_whom = by_whom
@@ -1,10 +1,6 @@
1
1
  RSpec::Matchers.define :be_resolvable do
2
2
  match do |name|
3
- if name.respond_to?(:resolvable?)
4
- name.resolvable?(@type)
5
- else
6
- backend.check_resolvable(name, @type)
7
- end
3
+ name.resolvable?(@type)
8
4
  end
9
5
  chain :by do |type|
10
6
  @type = type
@@ -1,20 +1,6 @@
1
1
  RSpec::Matchers.define :be_running do
2
2
  match do |process|
3
- if process.respond_to?(:running?)
4
- process.running? @under
5
- else
6
- if (@under)
7
- check_method = "check_running_under_#{@under}".to_sym
8
-
9
- unless backend.respond_to?(check_method)
10
- raise ArgumentError.new("`be_running` matcher doesn't support #{@under}")
11
- end
12
-
13
- backend.send(check_method, process)
14
- else
15
- backend.check_running(process)
16
- end
17
- end
3
+ process.running?(@under)
18
4
  end
19
5
 
20
6
  chain :under do |under|
@@ -1,14 +1,6 @@
1
1
  RSpec::Matchers.define :be_writable do
2
2
  match do |file|
3
- if file.respond_to?(:writable?)
4
- file.writable?(@by_whom, @by_user)
5
- else
6
- if @by_user != nil
7
- backend.check_access_by_user(file, @by_user, 'w')
8
- else
9
- backend.check_writable(file, @by_whom)
10
- end
11
- end
3
+ file.writable?(@by_whom, @by_user)
12
4
  end
13
5
  chain :by do |by_whom|
14
6
  @by_whom = by_whom
@@ -1,10 +1,6 @@
1
1
  RSpec::Matchers.define :belong_to_group do |group|
2
2
  match do |user|
3
- if user.respond_to?(:belongs_to_group?)
4
- user.belongs_to_group?(group)
5
- else
6
- backend.check_belonging_group(user, group)
7
- end
3
+ user.belongs_to_group?(group)
8
4
  end
9
5
  end
10
6
 
@@ -1,16 +1,6 @@
1
1
  RSpec::Matchers.define :contain do |pattern|
2
2
  match do |file|
3
- if file.respond_to?(:contain)
4
- file.contain(pattern, @from, @to)
5
- else
6
- if (@from || @to).nil?
7
- cmd = backend.commands.check_file_contain(file, pattern)
8
- else
9
- cmd = backend.commands.check_file_contain_within(file, pattern, @from, @to)
10
- end
11
- ret = backend.run_command(cmd)
12
- ret[:exit_status] == 0
13
- end
3
+ file.contain(pattern, @from, @to)
14
4
  end
15
5
  # for contain(pattern).from(/A/).to(/B/)
16
6
  chain :from do |from|
@@ -4,8 +4,6 @@ RSpec::Matchers.define :have_entry do |entry|
4
4
  subject.has_entry?(@user, entry)
5
5
  elsif subject.respond_to?(:has_entry?)
6
6
  subject.has_entry?(entry)
7
- else
8
- backend.check_routing_table(entry)
9
7
  end
10
8
  end
11
9
  # For cron type
@@ -1,9 +1,5 @@
1
1
  RSpec::Matchers.define :match_md5checksum do |pattern|
2
2
  match do |file|
3
- if file.respond_to?(:match_md5checksum)
4
- file.match_md5checksum(pattern)
5
- else
6
- backend.check_file_md5checksum(file, pattern)
7
- end
3
+ file.match_md5checksum(pattern)
8
4
  end
9
5
  end
@@ -1,10 +1,5 @@
1
1
  RSpec::Matchers.define :return_exit_status do |status|
2
2
  match do |command|
3
- if command.respond_to?(:return_exit_status?)
4
- command.return_exit_status?(status)
5
- else
6
- ret = backend.run_command(command)
7
- ret[:exit_status].to_i == status
8
- end
3
+ command.return_exit_status?(status)
9
4
  end
10
5
  end
@@ -1,14 +1,5 @@
1
1
  RSpec::Matchers.define :return_stderr do |content|
2
2
  match do |command|
3
- if command.respond_to?(:return_stderr?)
4
- command.return_stderr?(content)
5
- else
6
- ret = backend.run_command(command)
7
- if content.instance_of?(Regexp)
8
- ret[:stderr] =~ content
9
- else
10
- ret[:stderr].strip == content
11
- end
12
- end
3
+ command.return_stderr?(content)
13
4
  end
14
5
  end
@@ -1,14 +1,5 @@
1
1
  RSpec::Matchers.define :return_stdout do |content|
2
2
  match do |command|
3
- if command.respond_to?(:return_stdout?)
4
- command.return_stdout?(content)
5
- else
6
- ret = backend.run_command(command)
7
- if content.instance_of?(Regexp)
8
- ret[:stdout] =~ content
9
- else
10
- ret[:stdout].strip == content
11
- end
12
- end
3
+ command.return_stdout?(content)
13
4
  end
14
5
  end
@@ -1,3 +1,3 @@
1
1
  module Serverspec
2
- VERSION = "0.5.8"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -7,7 +7,7 @@ describe 'Serverspec commands of Darwin family' do
7
7
  it_behaves_like 'support command check_directory', '/var/log'
8
8
 
9
9
  it_behaves_like 'support command check_installed_by_gem', 'jekyll'
10
- it_behaves_like 'support command check_installed_by_gem', 'jekyll', '1.0.2'
10
+ it_behaves_like 'support command check_installed_by_gem with_version', 'jekyll', '1.0.2'
11
11
 
12
12
  it_behaves_like 'support command check_mounted', '/'
13
13
 
@@ -7,7 +7,7 @@ describe 'Serverspec commands of Debian family' do
7
7
  it_behaves_like 'support command check_directory', '/var/log'
8
8
 
9
9
  it_behaves_like 'support command check_installed_by_gem', 'jekyll'
10
- it_behaves_like 'support command check_installed_by_gem', 'jekyll', '1.0.2'
10
+ it_behaves_like 'support command check_installed_by_gem with_version', 'jekyll', '1.0.2'
11
11
 
12
12
  it_behaves_like 'support command check_mounted', '/'
13
13
 
@@ -7,7 +7,7 @@ describe 'Serverspec commands of Gentoo family' do
7
7
  it_behaves_like 'support command check_directory', '/var/log'
8
8
 
9
9
  it_behaves_like 'support command check_installed_by_gem', 'jekyll'
10
- it_behaves_like 'support command check_installed_by_gem', 'jekyll', '1.0.2'
10
+ it_behaves_like 'support command check_installed_by_gem with_version', 'jekyll', '1.0.2'
11
11
 
12
12
  it_behaves_like 'support command check_mounted', '/'
13
13
 
@@ -7,7 +7,7 @@ describe 'Serverspec commands of Red Hat' do
7
7
  it_behaves_like 'support command check_directory', '/var/log'
8
8
 
9
9
  it_behaves_like 'support command check_installed_by_gem', 'jekyll'
10
- it_behaves_like 'support command check_installed_by_gem', 'jekyll', '1.0.2'
10
+ it_behaves_like 'support command check_installed_by_gem with_version', 'jekyll', '1.0.2'
11
11
 
12
12
  it_behaves_like 'support command check_mounted', '/'
13
13