Commit graph

63 commits

Author SHA1 Message Date
Miah Johnson
6c19e81a06 Remove authors tags from source files.
Signed-off-by: Miah Johnson <miah@chia-pet.org>
2019-05-28 12:47:39 -07:00
Ryan Davis
cdf95cd160 Fixed 3 failures in cmp matcher.
+ float? comparison can raise a TypeError
+ octal? comparison was allowing non-octal values (which cast to 0)
+ symbol comparison was casting to a string, but then doing an == check instead of casecmp.

The latter seems optional, but consistent with the intent of cmp.

Signed-off-by: Ryan Davis <zenspider@chef.io>
2019-05-17 02:26:06 -07:00
Ryan Davis
bc249a78cb Changed cmp matcher to use send.
obj.method(name).call(*args) == obj.send(name, *args)

```
Calculating -------------------------------------
         method+call      2.561M (± 2.2%) i/s -     12.816M in   5.006835s
                send      6.299M (± 2.4%) i/s -     31.501M in   5.004045s

Comparison:
                send:  6299002.5 i/s
         method+call:  2560909.2 i/s - 2.46x  slower
```

There aren't any direct tests for this? But I forcefully failed 2
functionals and then verified they passed after my change.

Not sure how (or if) to write tests against rspec matchers in a
meaningful way, even tho all I really want to test is a plain ole
method in it. I'll poke to see if it is possible / practical.

Signed-off-by: Ryan Davis <zenspider@chef.io>
2019-05-17 02:26:06 -07:00
Miah Johnson
659b4b373a Remove # encoding: utf8 magic comments
Signed-off-by: Miah Johnson <miah@chia-pet.org>
2019-05-07 16:06:23 -07:00
Jerry Aldrich
40031a9b83 Use deprecation facility throughout code
This converts all current deprecation warnings/TODOs to use the
`Inspec.deprecate()` deprecation facility.

This also modifies `Inspec.deprecate()` to only require 1 argument.

Signed-off-by: Jerry Aldrich <jerryaldrichiii@gmail.com>
2019-04-11 19:15:01 -04:00
Jerry Aldrich
6381dd1b1d Modify cmp matcher output to use .inspect (#3450)
This modifies the output of failed test when using the `cmp` matcher by
calling `.inspect` on the actual value passed.

This makes it easier to diagnose failed matches due to characters such
as `\n` not being visible.

Current behavior:
```
inspec> describe command('echo demo') do
inspec>   its('stdout') { should cmp 'demo' }
inspec> end

Profile: inspec-shell
Version: (not specified)

  Command: `echo demo`
     ×  stdout should cmp == "demo"

     expected: "demo"
          got: demo

     (compared using `cmp` matcher)

Test Summary: 0 successful, 1 failure, 0 skipped
```

New behavior:
```
inspec> describe command('echo demo') do
inspec>   its('stdout') { should cmp 'demo' }
inspec> end

Profile: inspec-shell
Version: (not specified)

  Command: `echo demo`
     ×  stdout should cmp == "demo"

     expected: "demo"
          got: "demo\n"

     (compared using `cmp` matcher)

Test Summary: 0 successful, 1 failure, 0 skipped
```

Many thanks to @jazaval for discovering this!

Signed-off-by: Jerry Aldrich <jerryaldrichiii@gmail.com>
2018-10-02 15:27:48 -04:00
James Stocks
b42bfeb77d cmp should recognise a string being a negative int (#3007)
Signed-off-by: James Stocks <jstocks@chef.io>
2018-05-02 10:19:57 -04:00
Jerry Aldrich
84817366a1 Remove deprecations for InSpec 2.0 (#2506)
* Add `release-2.0` target branch to AppVeyor/Travis (#2510)

Signed-off-by: Jerry Aldrich <jerryaldrichiii@gmail.com>

* simpleconfig: Remove deprecated config keys

Signed-off-by: Jerry Aldrich <jerryaldrichiii@gmail.com>

* cli (exec): Remove `--cache` command line argument

Signed-off-by: Jerry Aldrich <jerryaldrichiii@gmail.com>

* platform: Remove lowercase os name protection

Signed-off-by: Jerry Aldrich <jerryaldrichiii@gmail.com>

* matcher: Remove `contain_legacy_plus` matcher

Signed-off-by: Jerry Aldrich <jerryaldrichiii@gmail.com>

* matcher: Remove `contain_match` matcher

Signed-off-by: Jerry Aldrich <jerryaldrichiii@gmail.com>

* matcher: Remove `with_version` matcher

Signed-off-by: Jerry Aldrich <jerryaldrichiii@gmail.com>

* matcher: Remove `belong_to_group` matcher

Signed-off-by: Jerry Aldrich <jerryaldrichiii@gmail.com>

* matcher: Remove `belong_to_primary_group` matcher

Signed-off-by: Jerry Aldrich <jerryaldrichiii@gmail.com>

* matcher: Remove `contain` matcher

Signed-off-by: Jerry Aldrich <jerryaldrichiii@gmail.com>

* passwd: Remove deprecated properties

This removes:
  - `passwd.count`
  - `passwd.username`
  - `passwd.usernames`
  - `passwd.uid`

Signed-off-by: Jerry Aldrich <jerryaldrichiii@gmail.com>

* auditd_rules: Remove in favor of `auditd` resource

Signed-off-by: Jerry Aldrich <jerryaldrichiii@gmail.com>

* cli: Remove `login_automate` command

Signed-off-by: Jerry Aldrich <jerryaldrichiii@gmail.com>

* Remove `resource_skipped` message method

Signed-off-by: Jerry Aldrich <jerryaldrichiii@gmail.com>
2018-02-08 11:05:21 +01:00
Adam Leff
4b9acb4800 Bump Rubocop to 0.49.1 (#2323)
* Bump Rubocop to 0.49.1

This change bumps Rubocop to 0.49.1. There have been a lot of changes
since 0.39.0 and this PR is hopefully a nice compromise of turning off
certain cops and updating our codebase to take advantage of new Ruby
2.3 methods and operators.

Signed-off-by: Adam Leff <adam@leff.co>

* Set end-of-line format to line-feed only, avoid Windows-related CRLF issues

Signed-off-by: Adam Leff <adam@leff.co>
2017-11-21 08:49:41 +01:00
Adam Leff
cbf58c7afa Enhance cmp matcher to work with symbols, fix file documentation (#2224)
* Enhance cmp matcher to work with symbols

The `cmp` matcher will now stringify symbol actual values if the
expected value was passed in as a string. This will help with the file
resource `type` method where Train returns the file type as a symbol.

Signed-off-by: Adam Leff <adam@leff.co>

* Fix documentation for file type character_device

Signed-off-by: Adam Leff <adam@leff.co>

* Fix docs for block_device

Signed-off-by: Adam Leff <adam@leff.co>

* Fix file mtime docs

Signed-off-by: Adam Leff <adam@leff.co>
2017-10-07 12:28:07 +02:00
Rony Xavier
041f64a87f New 'be_in' matcher for matching against values in a list (#2022)
* New matcher 'be_in'
Fixes #2018

Signed-off-by: Rony Xavier <rx294@nyu.edu>

* small fixes to wording.

Signed-off-by: Aaron Lippold <lippold@gmail.com>

* Added code to use be_in for with the following use case:
describe nginx do
   its(module_list) { should be_in AUTHORIZED_MODULE_LIST }
end
Fixes #2018

Signed-off-by: Rony Xavier <rx294@nyu.edu>

* Updates to the matcher
Fixes #2018

Signed-off-by: Rony Xavier <rx294@nyu.edu>

* Added tests for the be_in matcher

Signed-off-by: Rony Xavier <rx294@nyu.edu>

* Requested updates completed

Signed-off-by: Rony Xavier <rx294@nyu.edu>
2017-08-07 16:05:22 +02:00
Adam Leff
a6582bea9b Remove any "All Rights Reserved" references (#1969)
* Remove any "All Rights Reserved" references

InSpec is licensed and released under the Apache 2.0 license. This
change removes all reference to legacy code files that still had
any Copyright or License lines referring to "All Rights Reserved".

Signed-off-by: Adam Leff <adam@leff.co>

* fix functional tests

Signed-off-by: Christoph Hartmann <chris@lollyrock.com>
2017-06-28 04:14:19 -07:00
Adam Leff
5f58450ccd
Remove commented-out deprecation warning
We can add it back in when we have a better solution and we actually
want to deprecate it.

Signed-off-by: Adam Leff <adam@leff.co>
2017-06-06 07:25:04 -04:00
Alex Pop
3171f46c7d Commenting out the contain_duplicates deprecation until we have a good alternative.
Signed-off-by: Alex Pop <apop@chef.io>
2017-05-30 13:41:44 +01:00
Dominik Richter
144dede6eb rename old deprecations that were meant for 1.0
Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
2017-04-28 12:09:24 +02:00
Tom Duffield
1ea83f526c Address rubocop violations
Signed-off-by: Tom Duffield <tom@chef.io>
2017-02-08 16:49:16 -06:00
Jeremy J. Miller
6481f00454 cmp better support for version ops
Signed-off-by: Jeremy J. Miller <jm@chef.io>
2016-12-14 23:45:38 -05:00
Artem Sidorenko
9d766252f7 Contain matcher maps to include matcher with warning
to allow easier migration from serverspec, where contain
matcher is used often

Signed-off-by: Artem Sidorenko <artem@posteo.de>
2016-11-03 20:58:34 +01:00
Artem Sidorenko
489f314a79 Use include instead of match in the error message (#1248)
as include behaves like contain and not match

Signed-off-by: Artem Sidorenko <artem@posteo.de>
2016-10-25 22:45:57 +02:00
Alex Pop
5d51b7a0aa dot inspect actual value to match the expected string one 2016-10-13 07:13:51 -07:00
Alex Pop
de58a2588d fix cmp code description 2016-10-10 05:40:22 -07:00
Jeremy J. Miller
0d817017bb changed regex for integer to allow 0 2016-08-29 19:39:39 -04:00
Jeremy J. Miller
53dbaa9c3e add test 2016-08-29 15:57:46 -04:00
Christoph Hartmann
f87f25fb07 add boolean support for cmp matcher 2016-06-18 20:33:08 +02:00
Stephan Renatus
0a00d21113 integer?("0300") should not be true 2016-06-15 18:34:42 +02:00
Christoph Hartmann
f3b41ccea9 deprecate arrray matcher 2016-05-12 00:14:54 +02:00
Christoph Hartmann
1f470971d2 Revert "Add all_match to matchers"
This reverts commit 29cf4522e4.
2016-05-11 23:47:24 +02:00
Christoph Hartmann
48d8694789 Revert "fix contain_match, add none_match"
This reverts commit 54b397f3a5.
2016-05-11 23:47:24 +02:00
Alex Pop
54b397f3a5 fix contain_match, add none_match
update matchers doc and add more integration tests
allow non-string data types and non-arrays
2016-05-11 12:47:36 +01:00
Victoria Jeffrey
29cf4522e4 Add all_match to matchers 2016-05-10 10:00:55 -04:00
Alex Pop
f78afe0d75 Use only strings in resource examples, docs and tests 2016-05-03 23:27:18 +01:00
Alex Pop
b38e71b6f2 allow integers to be cmp regexed 2016-04-20 11:57:31 -04:00
Dominik Richter
9b199c9223 add regexp to cmp matcher
i.e. `123 should { cmp /2+/ }`
2016-04-20 11:57:31 -04:00
Dominik Richter
07f17a3f8d bugfix: fix formatting of cmp expectations
E.g. for regex it will print a very cryptic `(?-mix:123)` for `/123/` instead of the pure regex
2016-04-20 02:11:00 -04:00
Dominik Richter
0cb03e8726 bugfix: print cmp expectations 2016-04-17 18:50:21 -04:00
Dominik Richter
5d58fa267b feature: cmp < / > / <= / >= / == / != sth matcher 2016-04-15 19:19:15 -04:00
Christoph Hartmann
681f817992 enable cmp matcher to catch the case where expected is a number string, and actual is a number 2016-02-23 22:18:16 +01:00
Dominik Richter
03bf732d82 add cmp for Arrays 2016-02-18 13:58:37 +01:00
Dominik Richter
2bbbb29a9b simplify cmp matcher checks 2016-02-18 12:07:40 +01:00
Dominik Richter
4092691a78 lint 2016-01-15 04:07:25 +01:00
Christoph Hartmann
772df929f6 implement be_mounted.with for file resources 2016-01-03 00:03:24 +01:00
Stephan Renatus
3a1dcb7669 teach cmp matcher octal tricks 2015-12-16 11:32:31 +01:00
Christoph Hartmann
0185751ff5 lint exception 2015-12-11 17:48:05 +01:00
Christoph Hartmann
52cd0b38d1 update style of float? detection 2015-12-11 17:26:46 +01:00
Christoph Hartmann
31f8863701 update failure message for cmp matcher 2015-12-11 17:19:28 +01:00
Christoph Hartmann
53728ee03a lint fix 2015-12-11 17:17:01 +01:00
Christoph Hartmann
9f0755be99 add new cmp matcher that eases the comparison for values 2015-12-11 17:02:48 +01:00
Christoph Hartmann
98d5a40686 generalize matcher 2015-10-25 21:33:36 +01:00
Christoph Hartmann
25783ea283 fail with warning, if users use contain matcher 2015-10-24 11:15:53 +02:00
Christoph Hartmann
f5448e919b remove p 2015-10-12 11:10:32 +02:00