rspec-system 2.1.2 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ 2.2.0
2
+ =====
3
+
4
+ This feature release adds the ability to pass a node as a string to helpers, and improves documentation on multi-node support.
5
+
6
+ #### Detailed Changes
7
+
8
+ * Rename system_node to node in yarddoc (Ken Barber)
9
+ * Add support for passing a node name as a string to the :node meta-parameter (Ken Barber)
10
+ * Document basic multi-node usage (Ken Barber)
11
+ * Created an FAQ section and included info about serverspec (Ken Barber)
12
+
1
13
  2.1.2
2
14
  =====
3
15
 
data/README.md CHANGED
@@ -6,6 +6,26 @@ The goal here is to provide facilities to aid in the launching of tests nodes, c
6
6
 
7
7
  *Note:* This library is fairly new at the moment, so your mileage may vary. That said, if you're good at ruby and have an opinion, I'd appreciate patches and improvements to move this further torwards stability.
8
8
 
9
+ ### FAQ
10
+
11
+ #### What is this tool, and why do I need it?
12
+
13
+ `rspec-system` is a system testing tool that specializes in preparing test systems, running setup commands for a test and providing rspec helpers to assist with writing rspec assertions.
14
+
15
+ In short, it tests software on real systems. For realz. It doesn't mock the execution of anything. So you would use this software, if you want more complete guarantees around the ability to run your software on a real operating system.
16
+
17
+ For writing tests it uses the [rspec](https://www.relishapp.com/rspec) testing framework, used by many Ruby projects, your software however does not actually need to be written in Ruby - you just need to know a minimal amount of Ruby to write the tests.
18
+
19
+ #### Can this tool be used to test Puppet?
20
+
21
+ Yes it can. Check out the plugin: [rspec-system-serverspec](http://rubygems.org/gems/rspec-system-serverspec).
22
+
23
+ #### How does this tool overlap with serverspec?
24
+
25
+ `rspec-system` and `serverspec` are similar tools built to solve different testing perspectives. `serverspec` is aimed at validating a running environment with great tests and matchers that are made simple for administrators to write. `rspec-system` is an integration/system testing suite more then for built system validation. It is also used for testing a running environment, but its focus is more around testing system tools (such as Puppet for example) by launching nodes, setting up the software in question and performing tests on it. Thus `rspec-system` is appropriate for testing a piece of software, whereas `serverspec` is for validating a test or production system that has been built by some outside force.
26
+
27
+ Of course the overlap is in what these tools do ultimately. `serverspec` logs into systems and runs commands to achieve its tests, and `rspec-system` is no different. However we have recognized `serverspec`'s strengths at the 'testing' end of the phase, so we have built a bridge so you can use `rspec-system` in your dev projects but benefit from the power of the `serverspec` tests and matchers: [rspec-system-serverspec](http://rubygems.org/gems/rspec-system-serverspec).
28
+
9
29
  ### Gem installation
10
30
 
11
31
  The intention is that this gem is used within your project as a development library.
@@ -94,6 +114,32 @@ The file must adhere to the Kwalify schema supplied in `resources/kwalify-schema
94
114
  * `sets -> [setname] -> nodes -> [name] -> prefab`: This relates to the prefabricated node template you wish to use. Currently this is the only way to launch a node. Look in `resources/prefabs.yml` for more details.
95
115
  * `default_set`: this is the default set to run if none are provided with `bundle exec rake spec:system`. This should be the most common platform normally.
96
116
 
117
+ ### Multi-node tests
118
+
119
+ With `rspec-system` you can launch and perform tests and setup actions on multiple nodes.
120
+
121
+ In your `.nodeset.yml` file you will need to define multiple nodes:
122
+
123
+ ---
124
+ sets:
125
+ 'centos-59-x64-multinode':
126
+ nodes:
127
+ default_node: 'first.mydomain.vm':
128
+ 'first.mydomain.vm':
129
+ prefab: 'centos-59-x64'
130
+ 'second.mydomain.vm':
131
+ prefab: 'centos-59-x64'
132
+
133
+ When you now run `rake spec:system` both nodes will launch.
134
+
135
+ Tests need to be written specifically with multi-node in mind however. Normally, helpers will try to use the first (and thus default) node only when executed. If you wish to use a helper against a particular node instead, you can use the `:node` metaparameter to specify execution on a particular node.
136
+
137
+ An example using the `shell` helper:
138
+
139
+ shell(:node => 'second.mydomain.vm', :command => 'hostname')
140
+
141
+ This would execute the command `hostname` on node `second.mydomain.vm`.
142
+
97
143
  ### Prefabs
98
144
 
99
145
  Prefabs are 'pre-rolled' virtual images, for now its the only way to specify a template.
@@ -215,7 +261,8 @@ Right now we have two types of plugins, the framework is in a state of flux as t
215
261
 
216
262
  Libraries that provide test helpers, and setup helpers for testing development on the software in question.
217
263
 
218
- * [rspec-system-puppet](http://rubygems.org/gems/rspec-system-puppet)
264
+ * [rspec-system-puppet](http://rubygems.org/gems/rspec-system-puppet) - Helpers for testing out Puppet plugins
265
+ * [rspec-system-serverspec](http://rubygems.org/gems/rspec-system-serverspec) - Imports the serverspec helpers and matchers so they can be used in rspec-system.
219
266
 
220
267
  #### Node providers
221
268
 
@@ -0,0 +1,6 @@
1
+ Run the tests with:
2
+
3
+ bundle update
4
+ rake spec:system
5
+
6
+ FYI: Some of these tests fail on purpose, so you can see how failures are handled. This is an example after-all :-).
@@ -72,15 +72,21 @@ module RSpecSystem
72
72
  lazy = false
73
73
  end
74
74
 
75
- opts = {
75
+ # Merge defaults and such
76
+ @opts = {
76
77
  :node => opts[:n] || dn,
77
78
  :n => opts[:node] || dn,
78
79
  :timeout => opts[:timeout] || 0,
79
80
  :lazy => lazy,
80
81
  }.merge(opts)
81
82
 
82
- @opts = opts
83
- r = result_data unless opts[:lazy]
83
+ # Try to figure out :node using the node helper if a string is passed
84
+ if @opts[:node].is_a? String
85
+ @opts[:n] = @opts[:node] = get_node_by_name(@opts[:node])
86
+ end
87
+
88
+ # Try to lookup result_data now, unless we are lazy
89
+ result_data unless @opts[:lazy]
84
90
 
85
91
  # If called as a block, yield the result as a block
86
92
  if block_given?
@@ -165,5 +171,15 @@ module RSpecSystem
165
171
  def default_node
166
172
  rspec_system_node_set.default_node
167
173
  end
174
+
175
+ # Returns a node by its name.
176
+ #
177
+ # To be used by helpers that wish to retrieve a node by its name.
178
+ #
179
+ # @param name [String] name of the node
180
+ # @return [RSpecSystem::Node] node found
181
+ def get_node_by_name(name)
182
+ rspec_system_node_set.nodes[name]
183
+ end
168
184
  end
169
185
  end
@@ -13,7 +13,7 @@ require 'rspec-system/helpers/rcp'
13
13
  #
14
14
  # The helpers themselves are split into two main groups, Queries:
15
15
  #
16
- # * +system_node+ - queries and returns node information
16
+ # * +node+ - queries and returns node information
17
17
  #
18
18
  # And Actions:
19
19
  #
@@ -75,10 +75,10 @@ module RSpecSystem::Helpers
75
75
  # @param options [Hash] options for command execution
76
76
  # @option options [String] :command command to execute. Mandatory.
77
77
  # @option options [String] :c alias for :command
78
- # @option options [RSpecSystem::Node] :node (defaults to what was defined
78
+ # @option options [String,RSpecSystem::Node] :node (defaults to what was defined
79
79
  # default in your YAML file, otherwise if there is only one node it uses
80
80
  # that) specifies node to execute command on.
81
- # @option options [RSpecSystem::Node] :n alias for :node
81
+ # @option options [String,RSpecSystem::Node] :n alias for :node
82
82
  # @option options [Fixnum] :timeout seconds of time to allow before timing
83
83
  # out. Defaults to 0 (not timeout).
84
84
  # @overload shell(command)
@@ -19,6 +19,14 @@ module RSpecSystem::Helpers
19
19
  :s => nil,
20
20
  }.merge(opts)
21
21
 
22
+ # Try to figure out :*_node using the node helper if a string is passed
23
+ if opts[:destination_node].is_a? String
24
+ opts[:d] = opts[:destination_node] = get_node_by_name(opts[:destination_node])
25
+ end
26
+ if opts[:source_node].is_a? String
27
+ opts[:s] = opts[:source_node] = get_node_by_name(opts[:source_node])
28
+ end
29
+
22
30
  super(opts, clr, &block)
23
31
  end
24
32
 
data/rspec-system.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
  Gem::Specification.new do |s|
3
3
  # Metadata
4
4
  s.name = "rspec-system"
5
- s.version = "2.1.2"
5
+ s.version = "2.2.0"
6
6
  s.authors = ["Ken Barber"]
7
7
  s.email = ["info@puppetlabs.com"]
8
8
  s.homepage = "https://github.com/puppetlabs/rspec-system"
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper_system'
2
2
 
3
3
  describe "rcp:" do
4
- it 'check rcp works with block matchers' do
4
+ it 'check it works with block matchers' do
5
5
  rcp(
6
6
  :sp => fixture_root + 'example_dir',
7
7
  :dp => '/tmp/example_destination1'
@@ -15,7 +15,7 @@ describe "rcp:" do
15
15
  end
16
16
  end
17
17
 
18
- it 'check rcp works outside a block' do
18
+ it 'check it works outside a block' do
19
19
  r = rcp(
20
20
  :sp => fixture_root + 'example_dir',
21
21
  :dp => '/tmp/example_destination2'
@@ -27,4 +27,32 @@ describe "rcp:" do
27
27
  r.stdout.should =~ /Test content 1234/
28
28
  end
29
29
  end
30
+
31
+ it 'should support being passed a node as a string' do |r|
32
+ r = rcp(
33
+ :sp => fixture_root + 'example_dir',
34
+ :dp => '/tmp/example_destination3',
35
+ :destination_node => 'main',
36
+ )
37
+ r.success.should be_true
38
+
39
+ shell 'cat /tmp/example_destination3/example_file' do |r|
40
+ r.exit_code.should be_zero
41
+ r.stdout.should =~ /Test content 1234/
42
+ end
43
+ end
44
+
45
+ it 'should support being passed a node as an object' do |r|
46
+ r = rcp(
47
+ :sp => fixture_root + 'example_dir',
48
+ :dp => '/tmp/example_destination3',
49
+ :destination_node => node(:name => 'main'),
50
+ )
51
+ r.success.should be_true
52
+
53
+ shell 'cat /tmp/example_destination3/example_file' do |r|
54
+ r.exit_code.should be_zero
55
+ r.stdout.should =~ /Test content 1234/
56
+ end
57
+ end
30
58
  end
@@ -113,6 +113,18 @@ describe "shell:" do
113
113
  end
114
114
  end
115
115
 
116
+ it 'should support passing a node as an object' do
117
+ shell(:c => 'cat /etc/hosts', :n => node(:name => 'main')) do |r|
118
+ r.stdout.should =~ /localhost/
119
+ end
120
+ end
121
+
122
+ it 'should support passing a node as a string' do
123
+ shell(:c => 'cat /etc/hosts', :node => 'main') do |r|
124
+ r.stdout.should =~ /localhost/
125
+ end
126
+ end
127
+
116
128
  context 'legacy tests' do
117
129
  it 'cat /etc/hosts - test results using hash method' do
118
130
  shell 'cat /etc/hosts' do |r|
@@ -23,6 +23,13 @@ describe 'RSpecSystem::Helper' do
23
23
  end
24
24
  block_exec.should be_true
25
25
  end
26
+
27
+ it 'should convert :node using get_node_by_name when passed as a string' do
28
+ RSpecSystem::Helper.any_instance.expects(:result_data)
29
+ RSpecSystem::Helper.any_instance.expects(:get_node_by_name).with('mynode').returns(node)
30
+ helper = RSpecSystem::Helper.new({:node => 'mynode'}, self)
31
+ helper.opts[:node].should == node
32
+ end
26
33
  end
27
34
 
28
35
  context '#refresh' do
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: 2.1.2
4
+ version: 2.2.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-07-24 00:00:00.000000000 Z
12
+ date: 2013-08-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -142,6 +142,7 @@ files:
142
142
  - examples/.nodeset.yml
143
143
  - examples/.ruby-version
144
144
  - examples/Gemfile
145
+ - examples/README.md
145
146
  - examples/Rakefile
146
147
  - examples/spec/spec_helper.rb
147
148
  - examples/spec/system/test1_spec.rb