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:
-
shell- runs a command on a node -
rcp- remote copies to a node
Actions collapse
-
#rcp(options) ⇒ Bool
Remotely copy files to a test host.
-
#shell(options) {|result| ... } ⇒ RSpecSystem::Result
Runs a shell command on a test host.
-
#system_rcp(options) ⇒ Bool
deprecated
Deprecated.
Use #rcp instead
-
#system_run(options) {|result| ... } ⇒ RSpecSystem::Result
deprecated
Deprecated.
Use #shell instead
Queries collapse
-
#node(options = {}) ⇒ RSpecSystem::Node
Returns a particular node object from the current nodeset given a set of criteria.
-
#system_node(options = {}) ⇒ RSpecSystem::Node
deprecated
Deprecated.
Use #node instead
Instance Method Details
#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.
228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/rspec-system/helpers.rb', line 228 def 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 |
#rcp(options) ⇒ Bool
Remotely copy files to a test host
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.
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/rspec-system/helpers.rb', line 185 def 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("rcp from #{sp} to #{d.name}:#{dp} executed") ns.rcp() end |
#shell(options) ⇒ RSpecSystem::Result #shell(command) ⇒ 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.
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/rspec-system/helpers.rb', line 113 def shell(, &block) 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 shell with no :command option" end result = RSpecSystem::Result.new(ns.run()) if block_given? yield(result) else result end end |
#system_node(options = {}) ⇒ RSpecSystem::Node
Use #node instead
Legacy method for querying nodes
247 248 249 250 |
# File 'lib/rspec-system/helpers.rb', line 247 def system_node( = {}) log.warn('system_node is deprecated, use node instead') node() end |
#system_rcp(options) ⇒ Bool
Use #rcp instead
Legacy method for copying a file to a test host
210 211 212 213 |
# File 'lib/rspec-system/helpers.rb', line 210 def system_rcp() log.warn('system_rcp is deprecated, use rcp instead') rcp() end |
#system_run(options) ⇒ RSpecSystem::Result #system_run(command) ⇒ RSpecSystem::Result
Use #shell instead
Legacy method for running a shell command.
148 149 150 151 152 |
# File 'lib/rspec-system/helpers.rb', line 148 def system_run(, &block) log.warn('system_run is deprecated, use shell instead') shell(, &block) end |