rspec-system 1.4.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +20 -0
- data/README.md +17 -13
- data/examples/spec/system/test1_spec.rb +2 -2
- data/lib/rspec-system/helpers.rb +116 -64
- data/lib/rspec-system/spec_helper.rb +20 -7
- data/rspec-system.gemspec +1 -1
- data/spec/spec_helper_system.rb +11 -1
- data/spec/system/rcp_spec.rb +29 -0
- data/spec/system/shell_spec.rb +98 -0
- metadata +6 -6
- data/spec/system/system_rcp_spec.rb +0 -15
- data/spec/system/system_run_spec.rb +0 -70
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,23 @@
|
|
1
|
+
1.5.0
|
2
|
+
=====
|
3
|
+
|
4
|
+
This release renames the helpers to something more succinct:
|
5
|
+
|
6
|
+
* shell (was system_run)
|
7
|
+
* rcp (was system_rcp)
|
8
|
+
* node (was system_node)
|
9
|
+
|
10
|
+
This patch also deprecates the system_setup_block in favour of before :suite instead.
|
11
|
+
|
12
|
+
In the next major release, the old helpers and system_setup_block will stop working so it is recommended to look out for the deprecation messages and adjust your code now so that the next major release (2.x) will continue to work.
|
13
|
+
|
14
|
+
#### Detailed Changes
|
15
|
+
|
16
|
+
* Deprecate usage of system_setup_block (Ken Barber)
|
17
|
+
* Rename old helpers to shell, node, rcp (Ken Barber)
|
18
|
+
|
19
|
+
-------------------------------
|
20
|
+
|
1
21
|
1.4.0
|
2
22
|
=====
|
3
23
|
|
data/README.md
CHANGED
@@ -29,21 +29,26 @@ Start by creating a helper file in `spec/spec_helper_system.rb` containing somet
|
|
29
29
|
require 'rspec-system/spec_helper'
|
30
30
|
|
31
31
|
RSpec.configure do |c|
|
32
|
-
c.
|
33
|
-
include RSpecSystem::Helpers
|
32
|
+
c.before :suite do
|
34
33
|
# Insert some setup tasks here
|
35
|
-
|
34
|
+
shell 'yum install -y ntp'
|
36
35
|
end
|
37
36
|
end
|
38
37
|
|
39
|
-
|
38
|
+
Within this file we can fine tune the behaviour of rspec-system, but more importantly we can use the before :suite rspec hook to provide setup tasks that must occur before all your tests.
|
39
|
+
|
40
|
+
Create the directory `spec/system` in your project, its recommended to make sure your unit tests go into `spec/unit` instead so you can isolate them easily during test time. Add files with the spec prefix ie. `mytests_spec.rb` and make sure they always include the line `require 'spec_helper_system'`.
|
41
|
+
|
42
|
+
An example file would look like this:
|
40
43
|
|
41
44
|
require 'spec_helper_system'
|
42
45
|
|
43
46
|
describe 'basics' do
|
44
47
|
it 'should cat /etc/resolv.conf' do
|
45
|
-
|
48
|
+
shell 'cat /etc/hosts' do |r|
|
46
49
|
r.stdout.should =~ /localhost/
|
50
|
+
r.exit_code.should be_zero
|
51
|
+
r.stderr.should be_empty
|
47
52
|
end
|
48
53
|
end
|
49
54
|
end
|
@@ -52,7 +57,6 @@ Also consult the examples in the `examples` directory in the source of this libr
|
|
52
57
|
|
53
58
|
For your reference, here are the list of custom rspec configuration items that can be overriden in your `spec_helper_system.rb` file:
|
54
59
|
|
55
|
-
* *system_setup_block* - this accepts a proc that is called after node setup, but before every test (ie. before suite). The goal of this option is to provide a good place for node setup independant of tests.
|
56
60
|
* *system_tmp* - For some of our activity, we require a temporary file area. By default we just a random temporary path, so you normally do not need to set this.
|
57
61
|
|
58
62
|
Currently to get the nice formatting rspec-system specific formatter its recommended to use the Rake task, so add the following to your `Rakefile`:
|
@@ -66,16 +70,16 @@ That will setup the `spec:system` rake task.
|
|
66
70
|
A nodeset file outlines all the node configurations for your tests. The concept here is to define one or more 'nodesets' each nodeset containing one or more 'nodes'. Create the file in your projects root directory as `.nodeset.yml`.
|
67
71
|
|
68
72
|
---
|
69
|
-
default_set: 'centos-
|
73
|
+
default_set: 'centos-59-x64'
|
70
74
|
sets:
|
71
|
-
'centos-
|
75
|
+
'centos-59-x64':
|
72
76
|
nodes:
|
73
77
|
'main.vm':
|
74
|
-
prefab: 'centos-
|
75
|
-
'debian-
|
78
|
+
prefab: 'centos-59-x64'
|
79
|
+
'debian-607-x64':
|
76
80
|
nodes:
|
77
81
|
'main.vm':
|
78
|
-
prefab: 'debian-
|
82
|
+
prefab: 'debian-607-x64'
|
79
83
|
|
80
84
|
The file must adhere to the Kwalify schema supplied in `resources/kwalify-schemas/nodeset_schema.yml`.
|
81
85
|
|
@@ -94,7 +98,7 @@ Prefabs are designed to be generic across different hosting environments. For ex
|
|
94
98
|
|
95
99
|
For this reason there are various `provider_specific` settings that apply to different provider types. For now though, only `vagrant` specific settings are provided.
|
96
100
|
|
97
|
-
`facts` in the prefab are literally dumps of `facter -p` on the host stored in the prefab file so you can look them up without addressing the machine. These are accessed using the `
|
101
|
+
`facts` in the prefab are literally dumps of `facter -p` on the host stored in the prefab file so you can look them up without addressing the machine. These are accessed using the `node#facts` method on the helper results and can be used in conditional logic during test runs and setup tasks. Not all the facts are supplied, only the more interesting ones.
|
98
102
|
|
99
103
|
#### Custom Prefabs
|
100
104
|
|
@@ -214,7 +218,7 @@ I want to start an eco-system of plugins for rspec-system, but do it in a sane w
|
|
214
218
|
|
215
219
|
* node providers - that is, abstractions around other virtualisation, cloud or system tools. Right now a NodeSet is tied to a virtual type, but I think this isn't granual enough. Some ideas for future providers are:
|
216
220
|
* blimpy - for firing up EC2 and OpenStack nodes, useful for Jenkins integration
|
217
|
-
* vmware
|
221
|
+
* vmware fusion - for using vmware fusion with vagrant
|
218
222
|
* razor - for launching bare metail nodes for testing purposes. Could be really useful to have baremetal tests for software that needs it like `facter`.
|
219
223
|
* manual - not everything has to be 'launched' I can see a need for defining a static configuration for older machines that can't be poked and peeked. Of course, we might need to add cleanup tasks for this case.
|
220
224
|
* helper libraries - libraries that provide test helpers, and setup helpers for testing development on the software in question.
|
data/lib/rspec-system/helpers.rb
CHANGED
@@ -15,61 +15,64 @@ require 'rspec-system/result'
|
|
15
15
|
#
|
16
16
|
# And Actions:
|
17
17
|
#
|
18
|
-
# * +
|
19
|
-
# * +
|
18
|
+
# * +shell+ - runs a command on a node
|
19
|
+
# * +rcp+ - remote copies to a node
|
20
20
|
#
|
21
|
-
# @example Using run within your tests
|
22
|
-
# describe 'test running' do
|
23
|
-
# it 'run cat' do
|
24
|
-
# system_run 'cat /etc/resolv.conf' do |r|
|
25
|
-
# r.exit_code.should == 0
|
26
|
-
# r.stdout.should =~ /localhost/
|
27
|
-
# end
|
28
|
-
# end
|
29
|
-
# end
|
30
|
-
# @example Using rcp in your tests
|
31
|
-
# describe 'test running' do
|
32
|
-
# it 'copy my files' do
|
33
|
-
# system_rcp :sp => 'mydata', :dp => '/srv/data'.should be_true
|
34
|
-
# end
|
35
|
-
# end
|
36
21
|
# @example Using node in your tests
|
37
22
|
# describe 'test running' do
|
38
23
|
# it 'do something if redhat' do
|
39
|
-
# if
|
40
|
-
#
|
24
|
+
# if node.facts['operatingsystem'] == 'RedHat' do
|
25
|
+
# shell 'cat /etc/redhat-release'
|
41
26
|
# end
|
42
27
|
# end
|
43
28
|
# end
|
44
29
|
# @example Make your own helper
|
45
30
|
# describe 'my own helper' do
|
46
31
|
# def install_puppet
|
47
|
-
# facts =
|
32
|
+
# facts = node.facts
|
48
33
|
#
|
49
34
|
# # Grab PL repository and install PL copy of puppet
|
50
35
|
# if facts['osfamily'] == 'RedHat'
|
51
|
-
#
|
52
|
-
#
|
36
|
+
# shell 'rpm -ivh http://yum.puppetlabs.com/el/5/products/i386/puppetlabs-release-5-6.noarch.rpm'
|
37
|
+
# shell 'yum install -y puppet'
|
53
38
|
# elsif facts['osfamily'] == 'Debian'
|
54
|
-
#
|
55
|
-
#
|
56
|
-
#
|
57
|
-
#
|
39
|
+
# shell "wget http://apt.puppetlabs.com/puppetlabs-release-#{facts['lsbdistcodename']}.deb"
|
40
|
+
# shell "dpkg -i puppetlabs-release-#{facts['lsbdistcodename']}.deb"
|
41
|
+
# shell 'apt-get update'
|
42
|
+
# shell 'apt-get install -y puppet'
|
58
43
|
# end
|
59
44
|
# end
|
60
45
|
#
|
61
46
|
# it 'test installing latest puppet' do
|
62
47
|
# install_puppet
|
63
|
-
#
|
64
|
-
# r.exit_code
|
48
|
+
# shell 'puppet apply --version' do |r|
|
49
|
+
# r.exit_code.should be_zero
|
65
50
|
# r.stdout.should =~ /3.1/
|
66
|
-
# r.stderr.should
|
51
|
+
# r.stderr.should be_empty
|
67
52
|
# end
|
68
53
|
# end
|
69
54
|
# end
|
70
55
|
module RSpecSystem::Helpers
|
71
56
|
# @!group Actions
|
72
57
|
|
58
|
+
# @!macro shell_method
|
59
|
+
# @api public
|
60
|
+
# @overload $0(options)
|
61
|
+
# @param options [Hash] options for command execution
|
62
|
+
# @option options [String] :command command to execute. Mandatory.
|
63
|
+
# @option options [String] :c alias for :command
|
64
|
+
# @option options [RSpecSystem::Node] :node (defaults to what was defined
|
65
|
+
# default in your YAML file, otherwise if there is only one node it uses
|
66
|
+
# that) specifies node to execute command on.
|
67
|
+
# @option options [RSpecSystem::Node] :n alias for :node
|
68
|
+
# @overload $0(command)
|
69
|
+
# @param command [String] command to execute
|
70
|
+
# @yield [result] yields result when called as a block
|
71
|
+
# @yieldparam result [RSpecSystem::Result] result of run containing
|
72
|
+
# :exit_code, :stdout and :stderr
|
73
|
+
# @return [RSpecSystem::Result] result of run containing :exit_code,
|
74
|
+
# :stdout and :stderr
|
75
|
+
|
73
76
|
# Runs a shell command on a test host.
|
74
77
|
#
|
75
78
|
# When invoked as a block a result hash is yielded to the block as a
|
@@ -85,20 +88,29 @@ module RSpecSystem::Helpers
|
|
85
88
|
# to worry about that.
|
86
89
|
#
|
87
90
|
# @api public
|
88
|
-
# @
|
89
|
-
#
|
90
|
-
#
|
91
|
-
#
|
92
|
-
#
|
93
|
-
#
|
94
|
-
#
|
95
|
-
#
|
96
|
-
#
|
97
|
-
#
|
98
|
-
#
|
99
|
-
#
|
100
|
-
#
|
101
|
-
|
91
|
+
# @macro shell_method
|
92
|
+
# @example Using it as a helper
|
93
|
+
# it 'test a command' do
|
94
|
+
# shell 'cat /etc/hosts' do |r|
|
95
|
+
# # Test stdout contains 'localhost'
|
96
|
+
# r.stdout.should =~ /localhost/
|
97
|
+
# # Test stderr is empty
|
98
|
+
# r.stderr.should == ''
|
99
|
+
# # Test exit_code is 0
|
100
|
+
# r.exit_code.should == 0
|
101
|
+
# end
|
102
|
+
# end
|
103
|
+
# @example Running arbitrary commands
|
104
|
+
# it 'run some commands' do
|
105
|
+
# # Run a command without testing results
|
106
|
+
# shell 'echo "foobar" > /tmp/foo'
|
107
|
+
#
|
108
|
+
# # Now we try to cat the file, and make sure it worked
|
109
|
+
# shell 'cat /tmp/foo' do |r|
|
110
|
+
# r.stdout.should =~ /foobar/
|
111
|
+
# end
|
112
|
+
# end
|
113
|
+
def shell(options, &block)
|
102
114
|
ns = rspec_system_node_set
|
103
115
|
dn = ns.default_node
|
104
116
|
|
@@ -117,7 +129,7 @@ module RSpecSystem::Helpers
|
|
117
129
|
}.merge(options)
|
118
130
|
|
119
131
|
if options[:c].nil?
|
120
|
-
raise "Cannot use
|
132
|
+
raise "Cannot use shell with no :command option"
|
121
133
|
end
|
122
134
|
|
123
135
|
result = RSpecSystem::Result.new(ns.run(options))
|
@@ -129,7 +141,32 @@ module RSpecSystem::Helpers
|
|
129
141
|
end
|
130
142
|
end
|
131
143
|
|
132
|
-
#
|
144
|
+
# Legacy method for running a shell command.
|
145
|
+
#
|
146
|
+
# @deprecated Use {#shell} instead
|
147
|
+
# @macro shell_method
|
148
|
+
def system_run(options, &block)
|
149
|
+
log.warn('system_run is deprecated, use shell instead')
|
150
|
+
|
151
|
+
shell(options, &block)
|
152
|
+
end
|
153
|
+
|
154
|
+
# @!macro rcp_method
|
155
|
+
# @param options [Hash] options for command execution
|
156
|
+
# @option options [String] :source_path source to copy files from (currently
|
157
|
+
# only locally)
|
158
|
+
# @option options [String] :sp alias for source_path
|
159
|
+
# @option options [String] :destination_path destination for copy
|
160
|
+
# @option options [String] :dp alias for dest_path
|
161
|
+
# @option options [RSpecSystem::Node] :destination_node (default_node) destination node
|
162
|
+
# to transfer files to. Optional.
|
163
|
+
# @option options [RSpecSystem::Node] :d alias for destination_node
|
164
|
+
# @option options [RSpecSystem::Node] :source_node ('') Reserved
|
165
|
+
# for future use. Patches welcome.
|
166
|
+
# @option options [RSpecSystem::Node] :s alias for source_node
|
167
|
+
# @return [Bool] returns true if successful
|
168
|
+
|
169
|
+
# Remotely copy files to a test host
|
133
170
|
#
|
134
171
|
# Just specify a source path, destination path, and optionally a destination
|
135
172
|
# node (if the default isn't enough) and go.
|
@@ -138,20 +175,14 @@ module RSpecSystem::Helpers
|
|
138
175
|
# node provider, however this abstraction should mean you shouldn't need
|
139
176
|
# to worry about that.
|
140
177
|
#
|
141
|
-
# @
|
142
|
-
# @
|
143
|
-
#
|
144
|
-
#
|
145
|
-
#
|
146
|
-
#
|
147
|
-
#
|
148
|
-
|
149
|
-
# @option options [RSpecSystem::Node] :d alias for destination_node
|
150
|
-
# @option options [RSpecSystem::Node] :source_node ('') Reserved
|
151
|
-
# for future use. Patches welcome.
|
152
|
-
# @option options [RSpecSystem::Node] :s alias for source_node
|
153
|
-
# @return [Bool] returns true if successful
|
154
|
-
def system_rcp(options)
|
178
|
+
# @macro rcp_method
|
179
|
+
# @example Copying a path remotely
|
180
|
+
# describe 'test running' do
|
181
|
+
# it 'copy my files' do
|
182
|
+
# rcp :sp => 'mydata', :dp => '/srv/data'.should be_true
|
183
|
+
# end
|
184
|
+
# end
|
185
|
+
def rcp(options)
|
155
186
|
ns = rspec_system_node_set
|
156
187
|
options = {
|
157
188
|
:source_path => options[:sp],
|
@@ -168,21 +199,33 @@ module RSpecSystem::Helpers
|
|
168
199
|
sp = options[:sp]
|
169
200
|
dp = options[:dp]
|
170
201
|
|
171
|
-
log.info("
|
202
|
+
log.info("rcp from #{sp} to #{d.name}:#{dp} executed")
|
172
203
|
ns.rcp(options)
|
173
204
|
end
|
174
205
|
|
206
|
+
# Legacy method for copying a file to a test host
|
207
|
+
#
|
208
|
+
# @deprecated Use {#rcp} instead
|
209
|
+
# @macro rcp_method
|
210
|
+
def system_rcp(options)
|
211
|
+
log.warn('system_rcp is deprecated, use rcp instead')
|
212
|
+
rcp(options)
|
213
|
+
end
|
214
|
+
|
175
215
|
# @!group Queries
|
176
216
|
|
217
|
+
# @!macro node_method
|
218
|
+
# @param options [Hash] search criteria
|
219
|
+
# @option options [String] :name the canonical name of the node
|
220
|
+
# @return [RSpecSystem::Node] node object
|
221
|
+
|
177
222
|
# Returns a particular node object from the current nodeset given a set of
|
178
223
|
# criteria.
|
179
224
|
#
|
180
225
|
# If no options are supplied, it tries to return the default node.
|
181
226
|
#
|
182
|
-
# @
|
183
|
-
|
184
|
-
# @return [RSpecSystem::Node] node object
|
185
|
-
def system_node(options = {})
|
227
|
+
# @macro node_method
|
228
|
+
def node(options = {})
|
186
229
|
ns = rspec_system_node_set
|
187
230
|
options = {
|
188
231
|
:name => ns.default_node.name,
|
@@ -196,4 +239,13 @@ module RSpecSystem::Helpers
|
|
196
239
|
return ns.nodes[name]
|
197
240
|
end
|
198
241
|
end
|
242
|
+
|
243
|
+
# Legacy method for querying nodes
|
244
|
+
#
|
245
|
+
# @deprecated Use {#node} instead
|
246
|
+
# @macro node_method
|
247
|
+
def system_node(options = {})
|
248
|
+
log.warn('system_node is deprecated, use node instead')
|
249
|
+
node(options)
|
250
|
+
end
|
199
251
|
end
|
@@ -6,6 +6,8 @@ require 'yaml'
|
|
6
6
|
require 'pp'
|
7
7
|
require 'tempfile'
|
8
8
|
|
9
|
+
include RSpecSystem::Helpers
|
10
|
+
|
9
11
|
RSpec.configure do |c|
|
10
12
|
include RSpecSystem::Log
|
11
13
|
c.include RSpecSystem::Helpers
|
@@ -52,25 +54,35 @@ RSpec.configure do |c|
|
|
52
54
|
def start_nodes
|
53
55
|
ns = rspec_system_node_set
|
54
56
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
57
|
+
puts "Starting nodes"
|
58
|
+
puts
|
59
|
+
puts "Setname is: " + ns.setname
|
60
|
+
puts "Configuration is: " + ns.config.pretty_inspect
|
61
|
+
puts "Virtual Environment type is: #{ns.env_type}"
|
62
|
+
puts "Default node is: #{ns.default_node.name}"
|
63
|
+
puts "Destroy node is: #{ns.destroy}"
|
64
|
+
puts
|
61
65
|
|
62
66
|
ns.setup
|
67
|
+
|
68
|
+
puts
|
69
|
+
puts "Finished starting nodes"
|
70
|
+
puts "================================================================="
|
63
71
|
end
|
64
72
|
|
65
73
|
def stop_nodes
|
66
|
-
|
74
|
+
puts 'Stopping nodes'
|
75
|
+
puts
|
67
76
|
rspec_system_node_set.teardown
|
77
|
+
puts 'Finished stopping nodes'
|
78
|
+
puts "================================================================="
|
68
79
|
end
|
69
80
|
|
70
81
|
def call_custom_setup_block
|
71
82
|
# Run test specific setup routines
|
72
83
|
if pr = RSpec.configuration.system_setup_block then
|
73
84
|
log.info "Running custom setup block"
|
85
|
+
log.warn "The system_setup_block methodology will be deprecated in the next major release, use before :suite instead"
|
74
86
|
pr.call
|
75
87
|
log.info "Finished running custom setup block"
|
76
88
|
end
|
@@ -92,6 +104,7 @@ RSpec.configure do |c|
|
|
92
104
|
end
|
93
105
|
|
94
106
|
c.after :suite do
|
107
|
+
puts "================================================================="
|
95
108
|
# After Suite exceptions get captured it seems
|
96
109
|
begin
|
97
110
|
stop_nodes
|
data/rspec-system.gemspec
CHANGED
data/spec/spec_helper_system.rb
CHANGED
@@ -11,6 +11,16 @@ module LocalHelpers
|
|
11
11
|
end
|
12
12
|
|
13
13
|
RSpec.configure do |c|
|
14
|
-
c.include RSpecSystem::Helpers
|
15
14
|
c.include ::LocalHelpers
|
15
|
+
|
16
|
+
c.before :suite do
|
17
|
+
shell 'echo foobar > /tmp/setupblock'
|
18
|
+
end
|
19
|
+
|
20
|
+
# NOTE: this is deprecated, but we do this for legacy testing purposes
|
21
|
+
# with the next major release we should remove this capability, and remove
|
22
|
+
# the test. Do not use this in your own tests any more!
|
23
|
+
c.system_setup_block = proc do
|
24
|
+
shell 'echo foobar > /tmp/setupblockold'
|
25
|
+
end
|
16
26
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper_system'
|
2
|
+
|
3
|
+
describe "rcp:" do
|
4
|
+
it 'check rcp works' do
|
5
|
+
rcp(
|
6
|
+
:sp => fixture_root + 'example_dir',
|
7
|
+
:dp => '/tmp/example_destination'
|
8
|
+
)
|
9
|
+
|
10
|
+
shell 'cat /tmp/example_destination/example_file' do |r|
|
11
|
+
r.exit_code.should be_zero
|
12
|
+
r.stdout.should =~ /Test content 1234/
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'legacy tests' do
|
17
|
+
it 'check system_rcp works' do
|
18
|
+
system_rcp(
|
19
|
+
:sp => fixture_root + 'example_dir',
|
20
|
+
:dp => '/tmp/example_destination'
|
21
|
+
)
|
22
|
+
|
23
|
+
shell 'cat /tmp/example_destination/example_file' do |r|
|
24
|
+
r.exit_code.should be_zero
|
25
|
+
r.stdout.should =~ /Test content 1234/
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'spec_helper_system'
|
2
|
+
|
3
|
+
describe "shell:" do
|
4
|
+
it 'check /tmp/setupblock to ensure before :suite executed' do
|
5
|
+
shell 'cat /tmp/setupblock' do |r|
|
6
|
+
r.stdout.should =~ /foobar/
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
it "cat /etc/hosts" do
|
11
|
+
shell "cat /etc/hosts" do |r|
|
12
|
+
r.exit_code.should be_zero
|
13
|
+
r.stdout.should =~ /localhost/
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it "cat /etc/hosts - test results using hash method" do
|
18
|
+
shell "cat /etc/hosts" do |r|
|
19
|
+
r[:exit_code].should be_zero
|
20
|
+
r[:stdout].should =~ /localhost/
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'piping should be preserved' do
|
25
|
+
shell 'rm -f /tmp/foo'
|
26
|
+
shell 'echo "foo bar baz" > /tmp/foo' do |r|
|
27
|
+
r.stderr.should be_empty
|
28
|
+
r.exit_code.should be_zero
|
29
|
+
end
|
30
|
+
|
31
|
+
shell 'cat /tmp/foo' do |r|
|
32
|
+
r.stdout.should =~ /foo bar baz/
|
33
|
+
r.exit_code.should be_zero
|
34
|
+
end
|
35
|
+
shell 'rm -f /tmp/foo'
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'escape single quotes properly' do
|
39
|
+
shell 'rm -f /tmp/foo'
|
40
|
+
shell "echo 'foo bar baz' > /tmp/foo" do |r|
|
41
|
+
r.stderr.should be_empty
|
42
|
+
r.exit_code.should be_zero
|
43
|
+
end
|
44
|
+
|
45
|
+
shell 'cat /tmp/foo' do |r|
|
46
|
+
r.stdout.should =~ /foo bar baz/
|
47
|
+
r.exit_code.should be_zero
|
48
|
+
end
|
49
|
+
shell 'rm -f /tmp/foo'
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'escape all quotes properly' do
|
53
|
+
shell 'rm -f ~vagrant/foo'
|
54
|
+
shell "su - vagrant -c 'echo \"foo bar baz\" > ~/foo'" do |r|
|
55
|
+
r.stderr.should be_empty
|
56
|
+
r.exit_code.should be_zero
|
57
|
+
end
|
58
|
+
|
59
|
+
shell 'cat ~vagrant/foo' do |r|
|
60
|
+
r.stdout.should =~ /foo bar baz/
|
61
|
+
r.exit_code.should be_zero
|
62
|
+
end
|
63
|
+
shell 'rm -f ~vagrant/foo'
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'a string of commands should succeed' do
|
67
|
+
r = shell <<-EOS.gsub(/^ {6}/, '')
|
68
|
+
rm /tmp/foo
|
69
|
+
echo 'foo bar baz' > /tmp/foo
|
70
|
+
cat /tmp/foo
|
71
|
+
rm /tmp/foo
|
72
|
+
EOS
|
73
|
+
r.stdout.should =~ /foo bar baz/
|
74
|
+
r.exit_code.should be_zero
|
75
|
+
end
|
76
|
+
|
77
|
+
context 'legacy tests' do
|
78
|
+
it 'cat /etc/hosts - test results using hash method' do
|
79
|
+
shell 'cat /etc/hosts' do |r|
|
80
|
+
r[:exit_code].should be_zero
|
81
|
+
r[:stdout].should =~ /localhost/
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'cat /etc/hosts - using system_run' do
|
86
|
+
system_run 'cat /etc/hosts' do |r|
|
87
|
+
r.exit_code.should be_zero
|
88
|
+
r.stdout.should =~ /localhost/
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'cat /tmp/setupblockold to ensure the system_setup_block still works' do
|
93
|
+
shell 'cat /tmp/setupblockold' do |r|
|
94
|
+
r.stdout.should =~ /foobar/
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-system
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -155,8 +155,8 @@ files:
|
|
155
155
|
- spec/fixtures/nodeset_example2.yml
|
156
156
|
- spec/spec_helper.rb
|
157
157
|
- spec/spec_helper_system.rb
|
158
|
-
- spec/system/
|
159
|
-
- spec/system/
|
158
|
+
- spec/system/rcp_spec.rb
|
159
|
+
- spec/system/shell_spec.rb
|
160
160
|
- spec/unit/kwalify-schemas/nodeset_schema_spec.rb
|
161
161
|
- spec/unit/kwalify-schemas/prefabs_schema_spec.rb
|
162
162
|
- spec/unit/result_spec.rb
|
@@ -187,8 +187,8 @@ signing_key:
|
|
187
187
|
specification_version: 3
|
188
188
|
summary: System testing with rspec
|
189
189
|
test_files:
|
190
|
-
- spec/system/
|
191
|
-
- spec/system/
|
190
|
+
- spec/system/rcp_spec.rb
|
191
|
+
- spec/system/shell_spec.rb
|
192
192
|
- spec/unit/kwalify-schemas/nodeset_schema_spec.rb
|
193
193
|
- spec/unit/kwalify-schemas/prefabs_schema_spec.rb
|
194
194
|
- spec/unit/result_spec.rb
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'spec_helper_system'
|
2
|
-
|
3
|
-
describe "system_rcp:" do
|
4
|
-
it 'check system_rcp works' do
|
5
|
-
system_rcp(
|
6
|
-
:sp => fixture_root + 'example_dir',
|
7
|
-
:dp => '/tmp/example_destination'
|
8
|
-
)
|
9
|
-
|
10
|
-
system_run('cat /tmp/example_destination/example_file') do |r|
|
11
|
-
r.exit_code.should == 0
|
12
|
-
r.stdout.should =~ /Test content 1234/
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,70 +0,0 @@
|
|
1
|
-
require 'spec_helper_system'
|
2
|
-
|
3
|
-
describe "system_run:" do
|
4
|
-
it "cat /etc/hosts" do
|
5
|
-
system_run("cat /etc/hosts") do |r|
|
6
|
-
r.exit_code.should == 0
|
7
|
-
r.stdout.should =~ /localhost/
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
it "cat /etc/hosts - test results using hash method" do
|
12
|
-
system_run("cat /etc/hosts") do |r|
|
13
|
-
r[:exit_code].should == 0
|
14
|
-
r[:stdout].should =~ /localhost/
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'piping should be preserved' do
|
19
|
-
system_run('rm -f /tmp/foo')
|
20
|
-
system_run('echo "foo bar baz" > /tmp/foo') do |r|
|
21
|
-
r.stderr.should == ''
|
22
|
-
r.exit_code.should == 0
|
23
|
-
end
|
24
|
-
|
25
|
-
system_run('cat /tmp/foo') do |r|
|
26
|
-
r.stdout.should =~ /foo bar baz/
|
27
|
-
r.exit_code.should == 0
|
28
|
-
end
|
29
|
-
system_run('rm -f /tmp/foo')
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'escape single quotes properly' do
|
33
|
-
system_run('rm -f /tmp/foo')
|
34
|
-
system_run("echo 'foo bar baz' > /tmp/foo") do |r|
|
35
|
-
r.stderr.should == ''
|
36
|
-
r.exit_code.should == 0
|
37
|
-
end
|
38
|
-
|
39
|
-
system_run('cat /tmp/foo') do |r|
|
40
|
-
r.stdout.should =~ /foo bar baz/
|
41
|
-
r.exit_code.should == 0
|
42
|
-
end
|
43
|
-
system_run('rm -f /tmp/foo')
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'escape all quotes properly' do
|
47
|
-
system_run('rm -f ~vagrant/foo')
|
48
|
-
system_run("su - vagrant -c 'echo \"foo bar baz\" > ~/foo'") do |r|
|
49
|
-
r.stderr.should == ''
|
50
|
-
r.exit_code.should == 0
|
51
|
-
end
|
52
|
-
|
53
|
-
system_run('cat ~vagrant/foo') do |r|
|
54
|
-
r.stdout.should =~ /foo bar baz/
|
55
|
-
r.exit_code.should == 0
|
56
|
-
end
|
57
|
-
system_run('rm -f ~vagrant/foo')
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'a string of commands should succeed' do
|
61
|
-
r = system_run(<<-EOS.gsub(/^ {6}/, ''))
|
62
|
-
rm /tmp/foo
|
63
|
-
echo 'foo bar baz' > /tmp/foo
|
64
|
-
cat /tmp/foo
|
65
|
-
rm /tmp/foo
|
66
|
-
EOS
|
67
|
-
r.stdout.should =~ /foo bar baz/
|
68
|
-
r.exit_code.should == 0
|
69
|
-
end
|
70
|
-
end
|