From 90fc6affd21cd783c799b46223d9c99ebb2eeeb8 Mon Sep 17 00:00:00 2001 From: Clinton Wolfe Date: Thu, 5 Oct 2017 13:18:12 -0400 Subject: [PATCH] Docs: describe custom matcher cmp on version strings (#2214) * Docs update to describe using cmp for version matching on packages Signed-off-by: Clinton Wolfe * Add 'and' and force Travis to re-run checks Signed-off-by: Clinton Wolfe --- docs/matchers.md | 7 +++++++ docs/resources/package.md.erb | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/docs/matchers.md b/docs/matchers.md index a7024fc4b..293239de1 100644 --- a/docs/matchers.md +++ b/docs/matchers.md @@ -68,6 +68,13 @@ end its('log_format') { should cmp 'RAW' } end ``` +* Recognize versions embedded in strings + + ```ruby + describe package(curl) do + its('version') { should cmp > '7.35.0-1ubuntu2.10' } + end + ``` * Compare arrays with only one entry to a value diff --git a/docs/resources/package.md.erb b/docs/resources/package.md.erb index 68ea4f1bc..049a60054 100644 --- a/docs/resources/package.md.erb +++ b/docs/resources/package.md.erb @@ -111,3 +111,9 @@ The `be_installed` matcher tests if the named package is installed on the system The `version` matcher tests if the named package version is on the system: its('version') { should eq '1.2.3' } + +You can also use the `cmp OPERATOR` matcher to perform comparisions using the version attribute: + + its('version') { should cmp >= '7.35.0-1ubuntu3.10' } + +`cmp` understands version numbers using Gem::Version, and can use the operators `==, <, <=, >=, and >`. It will compare versions by each segment, not as a string - so '7.4' is smaller than '7.30', for example.