Skip to content

Commit

Permalink
Merge pull request #708 from chef/ap/string-examples
Browse files Browse the repository at this point in the history
Use only strings in resource examples, docs and tests
  • Loading branch information
arlimus committed May 3, 2016
2 parents c5afdf4 + f78afe0 commit d2518c9
Show file tree
Hide file tree
Showing 18 changed files with 75 additions and 75 deletions.
2 changes: 1 addition & 1 deletion docs/dsl_inspec.rst
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ The following test shows how to audit machines running |mysql| to ensure that pa
them to an attacker. Prevent this at all costs.
'
describe command('env') do
its(:stdout) { should_not match(/^MYSQL_PWD=/) }
its('stdout') { should_not match(/^MYSQL_PWD=/) }
end
end
Expand Down
18 changes: 9 additions & 9 deletions docs/resources.rst
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ The following examples show how to use this InSpec audit resource.

# syntax for auditd >= 2.3
describe auditd_rules do
its(:lines) { should contain_match(%r{-w /etc/ssh/sshd_config/}) }
its('lines') { should contain_match(%r{-w /etc/ssh/sshd_config/}) }
end

The syntax for recent auditd versions allows more precise tests, such as the following:
Expand All @@ -386,7 +386,7 @@ The syntax for recent auditd versions allows more precise tests, such as the fol
end

describe auditd_rules.key('sshd_config') do
its(:permissions) { should contain_match(/x/) }
its('permissions') { should contain_match(/x/) }
end

Note that filters can be chained, for example:
Expand Down Expand Up @@ -2045,23 +2045,23 @@ The following examples show how to use this InSpec audit resource.
.. code-block:: ruby

describe kernel_parameter('net.ipv4.conf.all.forwarding') do
its(:value) { should eq 1 }
its('value') { should eq 1 }
end

**Test if global forwarding is disabled for an IPv6 address**

.. code-block:: ruby

describe kernel_parameter('net.ipv6.conf.all.forwarding') do
its(:value) { should eq 0 }
its('value') { should eq 0 }
end

**Test if an IPv6 address accepts redirects**

.. code-block:: ruby

describe kernel_parameter('net.ipv6.conf.interface.accept_redirects') do
its(:value) { should eq 'true' }
its('value') { should eq 'true' }
end


Expand Down Expand Up @@ -2417,7 +2417,7 @@ The following examples show how to use this InSpec audit resource.

sql = mysql_session('my_user','password')
describe sql.query('show databases like \'test\';') do
its(:stdout) { should_not match(/test/) }
its('stdout') { should_not match(/test/) }
end


Expand Down Expand Up @@ -3148,12 +3148,12 @@ A ``passwd`` |inspec resource| block declares one (or more) users and associated
.. code-block:: ruby

describe passwd do
its(:users) { should_not include 'forbidden_user' }
its('users') { should_not include 'forbidden_user' }
end

describe passwd.uid(0) do
its(:users) { should cmp 'root' }
its(:count) { should eq 1 }
its('users') { should cmp 'root' }
its('count') { should eq 1 }
end

where
Expand Down
2 changes: 1 addition & 1 deletion lib/inspec/objects/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def describe_chain

if @qualifier.length > 1
last = @qualifier[-1]
# preventing its(:to_i) as the value returned is always 0
# preventing its('to_i') as the value returned is always 0
if last.length == 1 && last[0] != 'to_i'
xres = last[0]
else
Expand Down
6 changes: 3 additions & 3 deletions lib/matchers/matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
end

chain :with_version do |version|
warn "[DEPRECATION] `with_version` is deprecated. Please use `its(:version) { should eq '1.4.1' }` instead."
warn "[DEPRECATION] `with_version` is deprecated. Please use `its('version') { should eq '1.4.1' }` instead."
@version = version
end
end
Expand Down Expand Up @@ -146,7 +146,7 @@
# Deprecated: You should not use this matcher anymore
RSpec::Matchers.define :belong_to_group do |compare_group|
match do |user|
warn "[DEPRECATION] `belong_to_group` is deprecated. Please use `its(:groups) { should include('root') }` instead."
warn "[DEPRECATION] `belong_to_group` is deprecated. Please use `its('groups') { should include('root') }` instead."
user.groups.include?(compare_group)
end

Expand All @@ -159,7 +159,7 @@
# Deprecated: You should not use this matcher anymore
RSpec::Matchers.define :belong_to_primary_group do |compare_group|
match do |user|
warn "[DEPRECATION] `belong_to_primary_group` is deprecated. Please use `its(:group) { should eq 'root' }` instead."
warn "[DEPRECATION] `belong_to_primary_group` is deprecated. Please use `its('group') { should eq 'root' }` instead."
user.group == compare_group
end

Expand Down
4 changes: 2 additions & 2 deletions lib/resources/auditd_rules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ class AuditDaemonRules < Inspec.resource(1)
end
describe auditd_rules.key('sshd_config') do
its(:permissions) { should contain_match(/x/) }
its('permissions') { should contain_match(/x/) }
end
describe auditd_rules do
its(:lines) { should contain_match(%r{-w /etc/ssh/sshd_config/}) }
its('lines') { should contain_match(%r{-w /etc/ssh/sshd_config/}) }
end
"

Expand Down
2 changes: 1 addition & 1 deletion lib/resources/host.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# describe host('example.com') do
# it { should be_resolvable }
# it { should be_reachable }
# its(:ipaddress) { should include '93.184.216.34' }
# its('ipaddress') { should include '93.184.216.34' }
# end
#
# To verify a hostname with protocol and port
Expand Down
2 changes: 1 addition & 1 deletion lib/resources/interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class NetworkInterface < Inspec.resource(1)
describe interface('eth0') do
it { should exist }
it { should be_up }
its(:speed) { should eq 1000 }
its('speed') { should eq 1000 }
end
"
def initialize(iface)
Expand Down
2 changes: 1 addition & 1 deletion lib/resources/kernel_parameter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class KernelParameter < Inspec.resource(1)
desc 'Use the kernel_parameter InSpec audit resource to test kernel parameters on Linux platforms.'
example "
describe kernel_parameter('net.ipv4.conf.all.forwarding') do
its(:value) { should eq 0 }
its('value') { should eq 0 }
end
"

Expand Down
2 changes: 1 addition & 1 deletion lib/resources/mount.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Mount < Inspec.resource(1)
example "
describe mount('/') do
it { should be_mounted }
its(:count) { should eq 1 }
its('count') { should eq 1 }
its('device') { should eq '/dev/mapper/VolGroup-lv_root' }
its('type') { should eq 'ext4' }
its('options') { should eq ['rw', 'mode=620'] }
Expand Down
2 changes: 1 addition & 1 deletion lib/resources/mysql_session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class MysqlSession < Inspec.resource(1)
example "
sql = mysql_session('my_user','password')
describe sql.query('show databases like \'test\';') do
its(:stdout) { should_not match(/test/) }
its('stdout') { should_not match(/test/) }
end
"

Expand Down
4 changes: 2 additions & 2 deletions lib/resources/os_env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
# Usage:
#
# describe os_env('PATH') do
# its(:split) { should_not include('') }
# its(:split) { should_not include('.') }
# its('split') { should_not include('') }
# its('split') { should_not include('.') }
# end

require 'utils/simpleconfig'
Expand Down
30 changes: 15 additions & 15 deletions lib/resources/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
#
# describe user('root') do
# it { should exist }
# its(:uid) { should eq 0 }
# its(:gid) { should eq 0 }
# its(:group) { should eq 'root' }
# its(:groups) { should eq ['root', 'wheel']}
# its(:home) { should eq '/root' }
# its(:shell) { should eq '/bin/bash' }
# its(:mindays) { should eq 0 }
# its(:maxdays) { should eq 99 }
# its(:warndays) { should eq 5 }
# its('uid') { should eq 0 }
# its('gid') { should eq 0 }
# its('group') { should eq 'root' }
# its('groups') { should eq ['root', 'wheel']}
# its('home') { should eq '/root' }
# its('shell') { should eq '/bin/bash' }
# its('mindays') { should eq 0 }
# its('maxdays') { should eq 99 }
# its('warndays') { should eq 5 }
# end
#
# The following Serverspec matchers are deprecated in favor for direct value access
Expand All @@ -24,8 +24,8 @@
# it { should have_uid 0 }
# it { should have_home_directory '/root' }
# it { should have_login_shell '/bin/bash' }
# its(:minimum_days_between_password_change) { should eq 0 }
# its(:maximum_days_between_password_change) { should eq 99 }
# its('minimum_days_between_password_change') { should eq 0 }
# its('maximum_days_between_password_change') { should eq 99 }
# end

# ServerSpec tests that are not supported:
Expand Down Expand Up @@ -119,13 +119,13 @@ def warndays

# implement 'mindays' method to be compatible with serverspec
def minimum_days_between_password_change
deprecated('minimum_days_between_password_change', "Please use 'its(:mindays)'")
deprecated('minimum_days_between_password_change', "Please use: its('mindays')")
mindays
end

# implement 'maxdays' method to be compatible with serverspec
def maximum_days_between_password_change
deprecated('maximum_days_between_password_change', "Please use 'its(:maxdays)'")
deprecated('maximum_days_between_password_change', "Please use: its('maxdays')")
maxdays
end

Expand All @@ -137,12 +137,12 @@ def has_uid?(compare_uid)
end

def has_home_directory?(compare_home)
deprecated('has_home_directory?', "Please use 'its(:home)'")
deprecated('has_home_directory?', "Please use: its('home')")
home == compare_home
end

def has_login_shell?(compare_shell)
deprecated('has_login_shell?', "Please use 'its(:shell)'")
deprecated('has_login_shell?', "Please use: its('shell')")
shell == compare_shell
end

Expand Down
6 changes: 3 additions & 3 deletions test/integration/default/auditd_rules_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@
return unless os[:family] == 'centos'

describe auditd_rules.syscall('open') do
its(:action) { should eq(['always']) }
its('action') { should eq(['always']) }
end

describe auditd_rules.syscall('open').action do
it { should eq(['always']) }
end

describe auditd_rules.key('sshd_config') do
its(:permissions) { should contain_match(/x/) }
its('permissions') { should contain_match(/x/) }
end

describe auditd_rules.file('/etc/ssh/sshd_config').permissions do
it { should eq(['rwxa']) }
end

describe auditd_rules do
its(:lines) { should contain_match(%r{-w /etc/ssh/sshd_config/}) }
its('lines') { should contain_match(%r{-w /etc/ssh/sshd_config/}) }
end

describe auditd_rules.syscall('open').action('always').list do
Expand Down
12 changes: 6 additions & 6 deletions test/integration/default/kernel_parameter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,27 @@
# test on all linux systems
if os.linux?
describe kernel_parameter('kernel.panic') do
its(:value) { should eq test_values[:kernel_panic] }
its('value') { should eq test_values[:kernel_panic] }
end

describe kernel_parameter('net.netfilter.nf_log.0') do
its(:value) { should eq test_values[:nf_log] }
its('value') { should eq test_values[:nf_log] }
end

describe kernel_parameter('kernel.sched_autogroup_enabled') do
its(:value) { should eq test_values[:sched_autogroup_enabled] }
its('value') { should eq test_values[:sched_autogroup_enabled] }
end

describe kernel_parameter('net.ipv4.ip_local_port_range') do
its(:value) { should eq test_values[:ip_local_port_range] }
its('value') { should eq test_values[:ip_local_port_range] }
end

describe kernel_parameter('net.ipv4.conf.all.forwarding') do
its(:value) { should eq test_values[:forwarding] }
its('value') { should eq test_values[:forwarding] }
end

# serverspec compatability
describe linux_kernel_parameter('net.ipv4.conf.all.forwarding') do
its(:value) { should eq test_values[:forwarding] }
its('value') { should eq test_values[:forwarding] }
end
end
18 changes: 9 additions & 9 deletions test/resource/command_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
# author: Christoph Hartmann

describe command('echo hello') do
its(:stdout) { should eq "hello\n" }
its(:stderr) { should eq '' }
its(:exit_status) { should eq 0 }
its('stdout') { should eq "hello\n" }
its('stderr') { should eq '' }
its('exit_status') { should eq 0 }
end

describe command('>&2 echo error') do
its(:stdout) { should eq '' }
its(:stderr) { should eq "error\n" }
its(:exit_status) { should eq 0 }
its('stdout') { should eq '' }
its('stderr') { should eq "error\n" }
its('exit_status') { should eq 0 }
end

describe command('exit 123') do
its(:stdout) { should eq '' }
its(:stderr) { should eq '' }
its(:exit_status) { should eq 123 }
its('stdout') { should eq '' }
its('stderr') { should eq '' }
its('exit_status') { should eq 123 }
end

describe command('/bin/sh').exist? do
Expand Down
2 changes: 1 addition & 1 deletion test/resource/dsl_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# author: Christoph Hartmann

describe command('echo hello') do
its(:stdout) { should eq "hello\n" }
its('stdout') { should eq "hello\n" }
end

describe 'describe + it + expect' do
Expand Down
Loading

0 comments on commit d2518c9

Please sign in to comment.