Module: RSpecSystem::Helpers
- Defined in:
- lib/rspec-system/helpers.rb
Overview
This module contains the main rspec helpers that are to be used within rspec-system tests. These are the meat-and-potatoes of your system tests, and in theory there shouldn’t be anything you can’t do without the helpers here.
These helpers in particular are core to the framework. You can however combine these helpers to create your own more powerful helpers in rspec if you wish.
The helpers themselves are split into two main groups, Queries:
-
system_node- queries and returns node information
And Actions:
-
system_run- runs a command on a node -
system_rcp- remote copies to a node
Actions collapse
-
#system_rcp(options) ⇒ Bool
Remotely copy files to a test node.
-
#system_run(options) {|result| ... } ⇒ RSpecSystem::Result
Runs a shell command on a test host.
Queries collapse
-
#system_node(options = {}) ⇒ RSpecSystem::Node
Returns a particular node object from the current nodeset given a set of criteria.
Instance Method Details
#system_node(options = {}) ⇒ RSpecSystem::Node
Returns a particular node object from the current nodeset given a set of criteria.
If no options are supplied, it tries to return the default node.
185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/rspec-system/helpers.rb', line 185 def system_node( = {}) ns = rspec_system_node_set = { :name => ns.default_node.name, }.merge() name = [:name] if name.nil? raise "No nodes search specified, and no default" else return ns.nodes[name] end end |
#system_rcp(options) ⇒ Bool
Remotely copy files to a test node
Just specify a source path, destination path, and optionally a destination node (if the default isn’t enough) and go.
The underlying implementation is actually performed by the particular node provider, however this abstraction should mean you shouldn’t need to worry about that.
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/rspec-system/helpers.rb', line 154 def system_rcp() ns = rspec_system_node_set = { :source_path => [:sp], :destination_path => [:dp], :dp => [:destination_path], :sp => [:source_path], :destination_node => ns.default_node, :d => ns.default_node, :source_node => nil, :s => nil, }.merge() d = [:d] sp = [:sp] dp = [:dp] log.info("system_rcp from #{sp} to #{d.name}:#{dp} executed") ns.rcp() end |
#system_run(options) {|result| ... } ⇒ RSpecSystem::Result
Runs a shell command on a test host.
When invoked as a block a result hash is yielded to the block as a parameter. Alternatively the result hash it is returned to the caller.
If you have only provided 1 node in your nodeset, or you have specified a a default you can avoid entering the name of the node if you wish. The method for simplicity can accept a string instead of an options hash and it knows to default everything else.
The underlying implementation is actually performed by the particular node provider, however this abstraction should mean you shouldn’t need to worry about that.
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/rspec-system/helpers.rb', line 101 def system_run() ns = rspec_system_node_set dn = ns.default_node # If options is a string, turn the string into a command in the normal # options hash. if .is_a?(String) = {:c => } end # Defaults etc. = { :node => [:n] || dn, :n => [:node] || dn, :c => [:command], :command => [:c], }.merge() if [:c].nil? raise "Cannot use system_run with no :command option" end result = RSpecSystem::Result.new(ns.run()) if block_given? yield(result) else result end end |