spex 0.5.1 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.1
1
+ 0.5.2
@@ -25,6 +25,14 @@ module Spex
25
25
  Assertion.registry[name.to_sym] = self
26
26
  end
27
27
 
28
+ def self.example(description, text)
29
+ examples << [description, text]
30
+ end
31
+
32
+ def self.examples
33
+ @examples ||= []
34
+ end
35
+
28
36
  def self.options
29
37
  @options ||= {}
30
38
  end
@@ -6,6 +6,13 @@ module Spex
6
6
  option :to, "To group name or gid"
7
7
  option :from, "From group name or gid"
8
8
 
9
+ example "Changed the file group", "assert '/tmp/foo', :changed_group => true"
10
+ example "Did not change the file group", "assert '/tmp/foo', :changed_group => false"
11
+ example "Changed the file group from 'wheel' to 'www-users'", "assert '/tmp/foo', :changed_group => {:from => 'wheel', :to => 'www-users'}"
12
+ example "Changed the file group from gid 210 to gid 288", "assert '/tmp/foo', :changed_group => {:from => 210, :to => 288}"
13
+ example "Changed the file group to 'users'", "assert '/tmp/foo', :changed_group => {:to => 'users'}"
14
+ example "Changed the file group to gid 203", "assert '/tmp/foo', :changed_group => {:to => 203}"
15
+
9
16
  def before
10
17
  assert File.exist?(target), "File does not exist at #{target}"
11
18
  if from_groupname
@@ -3,6 +3,11 @@ module Spex
3
3
  as :changed_mode, "file mode change"
4
4
  option :from, "Mode changed from (octal, eg 0600)"
5
5
  option :to, "Mode changed to (octal, eg 0700)"
6
+
7
+ example "Changed the file mode", "assert '/tmp/foo', :changed_mode => true"
8
+ example "Did not change the file mode", "assert '/tmp/foo', :changed_mode => false"
9
+ example "Changed the file mode from 0666 to 0755", "assert '/tmp/foo', :changed_mode => {:from => 0666, :to => 0755}"
10
+ example "Changed the file mode to 0750", "assert '/tmp/foo', :changed_mode => {:to => 0750}"
6
11
 
7
12
  def before
8
13
  assert File.exist?(target), "File does not exist at #{target}"
@@ -5,6 +5,13 @@ module Spex
5
5
  as :changed_owner, 'file owner change'
6
6
  option :from, "From username or uid"
7
7
  option :to, "To username or uid"
8
+
9
+ example "Changed the file owner", "assert '/tmp/foo', :changed_owner => true"
10
+ example "Did not change the file owner", "assert '/tmp/foo', :changed_owner => false"
11
+ example "Changed the file owner from 'root' to 'bruce'", "assert '/tmp/foo', :changed_owner => {:from => 'root', :to => 'bruce'}"
12
+ example "Changed the file owner from uid 501 to uid 503", "assert '/tmp/foo', :changed_owner => {:from => 501, :to => 503}"
13
+ example "Changed the file owner to 'jim'", "assert '/tmp/foo', :changed_owner => {:to => 'jim'}"
14
+ example "Changed the file owner to uid 506", "assert '/tmp/foo', :changed_owner => {:to => 506}"
8
15
 
9
16
  def before
10
17
  assert File.exist?(target), "File does not exist at #{target}"
@@ -2,6 +2,10 @@ module Spex
2
2
  class CreatedAssertion < FileAssertion
3
3
  as :created, 'file creation'
4
4
  option :type, "Type ('file' or 'directory'), optional"
5
+ example "File was created", "assert '/tmp/foo', :created => true"
6
+ example "File was not created", "assert '/tmp/foo', :created => false"
7
+ example "Regular file was created", "assert '/tmp/foo', :created => {:type => 'file'}"
8
+ example "Directory was created", "assert '/tmp/foo', :created => {:type => 'directory'}"
5
9
 
6
10
  def before
7
11
  assert !File.exist?(target), "File already exists at #{target}"
@@ -9,6 +9,12 @@ module Spex
9
9
  as :modified, 'file modification'
10
10
  option :added, "Added content (string or regexp)"
11
11
  option :removed, "Removed content (string or regexp)"
12
+ example "Modified a file", "assert '/tmp/foo', :modified => true"
13
+ example "Did not modify a file", "assert '/tmp/foo', :modified => false"
14
+ example "Added a line with 'a substring' in it", "assert '/tmp/foo', :modified => {:added => 'a substring'}"
15
+ example "Added a line matching /a substring pattern/", "assert '/tmp/foo', :modified => {:added => /a substring pattern/}"
16
+ example "Removed a line with 'a substring' in it", "assert '/tmp/foo', :modified => {:removed => 'a substring'}"
17
+ example "Removed a line matching /a substring pattern/", "assert '/tmp/foo', :modified => {:removed => /a substring pattern/}"
12
18
 
13
19
  def prepare
14
20
  track_checksum!
@@ -1,9 +1,12 @@
1
1
  module Spex
2
- class RemovesFileAssertion < FileAssertion
3
- as :removes, 'file removal'
4
- option :mode, "Mode, in octal (eg: 0600), optional"
2
+ class RemovedAssertion < FileAssertion
3
+ as :removed, 'file removal'
5
4
  option :type, "Type (:file or :directory), optional"
6
-
5
+ example "File was removed", "assert '/tmp/foo', :removed => true"
6
+ example "File was not removed", "assert '/tmp/foo', :removed => false"
7
+ example "Regular file was removed", "assert '/tmp/foo', :removed => {:type => 'file'}"
8
+ example "Directory was removed", "assert '/tmp/foo', :removed => {:type => 'directory'}"
9
+
7
10
  def before
8
11
  assert File.exist?(target), "File does not exist at #{target}"
9
12
  check_type
data/lib/spex/cli.rb CHANGED
@@ -14,7 +14,7 @@ module Spex
14
14
 
15
15
  def parser
16
16
  @parser ||= OptionParser.new do |opts|
17
- opts.banner = 'spex DEFINITION_FILE [OPTIONS]'
17
+ opts.banner = "spex [OPTIONS] DEFINITION_FILE"
18
18
  opts.separator "\nOPTIONS:"
19
19
  opts.on_tail('--help', '-h', 'Show this message') do
20
20
  puts opts
@@ -23,6 +23,10 @@ module Spex
23
23
  opts.on('--describe', '-d', 'Describe DEFINITION_FILE') do
24
24
  options.describe = true
25
25
  end
26
+ opts.on('--assertions', '-a', "List supported assertions") do
27
+ display_assertions
28
+ exit
29
+ end
26
30
  end
27
31
  end
28
32
 
@@ -49,6 +53,30 @@ module Spex
49
53
  end
50
54
  end
51
55
 
56
+ def display_assertions
57
+ Assertion.registry.each_value do |klass|
58
+ line = "Assertion: :#{klass.name} (#{klass.description})"
59
+ puts line
60
+ if klass.options.any? || klass.examples.any?
61
+ puts('=' * line.size)
62
+ end
63
+ if klass.options.any?
64
+ puts "\nOptions\n-------\n\n"
65
+ klass.options.each do |key, value|
66
+ puts "* :#{key}, #{value.description}"
67
+ end
68
+ end
69
+ if klass.examples.any?
70
+ puts "\nExamples\n--------\n\n"
71
+ klass.examples.each do |description, example|
72
+ puts "#{description}:"
73
+ puts "\n #{example}\n\n"
74
+ end
75
+ end
76
+ puts
77
+ end
78
+ end
79
+
52
80
  def describe(script)
53
81
  script.scenarios.each do |scenario|
54
82
  puts %(In scenario "#{scenario.name}")
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 5
8
- - 1
9
- version: 0.5.1
8
+ - 2
9
+ version: 0.5.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Bruce Williams