rspec-system 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -6,6 +6,10 @@ Bundler.require :default
6
6
  require 'rspec/core/rake_task'
7
7
  require 'rspec-system/rake_task'
8
8
 
9
+ RSpec::Core::RakeTask.new(:spec) do |t|
10
+ t.pattern = "spec/unit/**/*_spec.rb"
11
+ end
12
+
9
13
  task :default do
10
14
  sh %{rake -T}
11
15
  end
@@ -70,12 +70,13 @@ module RSpecSystem::Helpers
70
70
 
71
71
  # Runs a shell command on a test host.
72
72
  #
73
- # When invoked as a block the status,stdout and stderr are yielded to the
74
- # block as parameters. If not these three variables are returned to the
75
- # caller.
73
+ # When invoked as a block a result hash is yielded to the block as a
74
+ # parameter. Alternatively the result hash it is returned to the caller.
76
75
  #
77
76
  # If you have only provided 1 node in your nodeset, or you have specified a
78
- # a default you can avoid entering the name of the node if you wish.
77
+ # a default you can avoid entering the name of the node if you wish. The
78
+ # method for simplicity can accept a string instead of an options hash
79
+ # and it knows to default everything else.
79
80
  #
80
81
  # The underlying implementation is actually performed by the particular
81
82
  # node provider, however this abstraction should mean you shouldn't need
@@ -119,7 +120,9 @@ module RSpecSystem::Helpers
119
120
  result = ns.run(options)
120
121
  log.info("system_run results:\n" +
121
122
  "-----------------------\n" +
122
- result.pretty_inspect +
123
+ "exit_code: #{result[:exit_code]}\n" +
124
+ "stdout:\n #{result[:stdout]}\n" +
125
+ "stderr:\n #{result[:stderr]}\n" +
123
126
  "-----------------------\n")
124
127
 
125
128
  if block_given?
@@ -152,13 +155,14 @@ module RSpecSystem::Helpers
152
155
  # @option options [RSpecSystem::Node] :s alias for source_node
153
156
  # @return [Bool] returns true if successful
154
157
  def system_rcp(options)
158
+ ns = rspec_system_node_set
155
159
  options = {
156
160
  :source_path => options[:sp],
157
161
  :destination_path => options[:dp],
158
162
  :dp => options[:destination_path],
159
163
  :sp => options[:source_path],
160
- :destination_node => rspec_system_node_set.default_node,
161
- :d => rspec_system_node_set.default_node,
164
+ :destination_node => ns.default_node,
165
+ :d => ns.default_node,
162
166
  :source_node => nil,
163
167
  :s => nil,
164
168
  }.merge(options)
@@ -168,17 +172,7 @@ module RSpecSystem::Helpers
168
172
  dp = options[:dp]
169
173
 
170
174
  log.info("system_rcp from #{sp} to #{d.name}:#{dp} executed")
171
- results = rspec_system_node_set.rcp(options)
172
- log.info("rcp results:\n" +
173
- "-----------------------\n" +
174
- results.pretty_inspect +
175
- "-----------------------\n")
176
-
177
- if results[:exit_code] == 1
178
- return true
179
- else
180
- return false
181
- end
175
+ ns.rcp(options)
182
176
  end
183
177
 
184
178
  # @!group Queries
@@ -8,32 +8,43 @@ module RSpecSystem
8
8
 
9
9
  ENV_TYPE = 'vagrant'
10
10
 
11
+ # Creates a new instance of RSpecSystem::NodeSet::Vagrant
12
+ #
13
+ # @param setname [String] name of the set to instantiate
14
+ # @param config [Hash] nodeset configuration hash
11
15
  def initialize(setname, config)
12
16
  super
13
17
  @vagrant_path = File.expand_path(File.join(RSpec.configuration.system_tmp, 'vagrant_projects', setname))
14
18
  end
15
19
 
16
20
  # Setup the NodeSet by starting all nodes.
21
+ #
22
+ # @return [void]
17
23
  def setup
18
24
  log.info "[Vagrant#setup] Begin setting up vagrant"
19
- create_vagrantfile
20
25
 
21
- log.info "[Vagrant#setup] Running 'vagrant destroy'"
22
- vagrant("destroy --force")
26
+ create_vagrantfile()
27
+
28
+ teardown()
23
29
 
24
30
  log.info "[Vagrant#setup] Running 'vagrant up'"
25
31
  vagrant("up")
32
+ nil
26
33
  end
27
34
 
28
35
  # Shutdown the NodeSet by shutting down or pausing all nodes.
36
+ #
37
+ # @return [void]
29
38
  def teardown
30
39
  log.info "[Vagrant#teardown] Running 'vagrant destroy'"
31
40
  vagrant("destroy --force")
41
+ nil
32
42
  end
33
43
 
34
44
  # Run a command on a host in the NodeSet.
35
45
  #
36
46
  # @param opts [Hash] options
47
+ # @return [Hash] a hash containing :exit_code, :stdout and :stderr
37
48
  def run(opts)
38
49
  #log.debug("[Vagrant#run] called with #{opts.inspect}")
39
50
 
@@ -58,11 +69,10 @@ module RSpecSystem
58
69
  # Transfer files to a host in the NodeSet.
59
70
  #
60
71
  # @param opts [Hash] options
72
+ # @return [Boolean] returns true if command succeeded, false otherwise
61
73
  # @todo This is damn ugly, because we ssh in as vagrant, we copy to a temp
62
74
  # path then move it later. Its slow and brittle and we need a better
63
75
  # solution. Its also very Linux-centrix in its use of temp dirs.
64
- # @todo Need to return more interesting information, not just the systemu
65
- # results. This will require a formalisation of this API.
66
76
  def rcp(opts)
67
77
  #log.debug("[Vagrant@rcp] called with #{opts.inspect}")
68
78
 
@@ -86,13 +96,26 @@ module RSpecSystem
86
96
  :stderr => r[2]
87
97
  }
88
98
 
89
- log.info("system_run results:\n" +
99
+ log.info("scp results:\n" +
90
100
  "-----------------------\n" +
91
- result.pretty_inspect +
101
+ "exit_code: #{result[:exit_code]}\n" +
102
+ "stdout:\n #{result[:stdout]}\n" +
103
+ "stderr:\n #{result[:stderr]}\n" +
92
104
  "-----------------------\n")
93
105
 
94
106
  # Now we move the file into their final destination
95
- run(:n => opts[:d], :c => "mv #{tmpdest} #{dest_path}")
107
+ result = run(:n => opts[:d], :c => "mv #{tmpdest} #{dest_path}")
108
+ log.info("move results:\n" +
109
+ "-----------------------\n" +
110
+ "exit_code: #{result[:exit_code]}\n" +
111
+ "stdout:\n #{result[:stdout]}\n" +
112
+ "stderr:\n #{result[:stderr]}\n" +
113
+ "-----------------------\n")
114
+ if result[:exit_code] == 0
115
+ return true
116
+ else
117
+ return false
118
+ end
96
119
  end
97
120
 
98
121
  # Create the Vagrantfile for the NodeSet.
@@ -105,16 +128,21 @@ module RSpecSystem
105
128
  f.write('Vagrant::Config.run do |c|')
106
129
  nodes.each do |k,v|
107
130
  log.debug "Filling in content for #{k}"
131
+
132
+ ps = v.provider_specifics['vagrant']
133
+
108
134
  f.write(<<-EOS)
109
- c.vm.define '#{k}' do |vmconf|
110
- vmconf.vm.host_name = "#{k}"
111
- #{template_node(v.provider_specifics['vagrant'])}
135
+ c.vm.define '#{k}' do |v|
136
+ v.vm.host_name = '#{k}'
137
+ v.vm.box = '#{ps['box']}'
138
+ v.vm.box_url = '#{ps['box_url']}'
112
139
  end
113
140
  EOS
114
141
  end
115
142
  f.write('end')
116
143
  end
117
144
  log.debug "[Vagrant#create_vagrantfile] Finished creating vagrant file"
145
+ nil
118
146
  end
119
147
 
120
148
  # Here we get vagrant to drop the ssh_config its using so we can monopolize
@@ -122,6 +150,7 @@ module RSpecSystem
122
150
  # since its indexed based on our own node names its quite ideal.
123
151
  #
124
152
  # @api private
153
+ # @return [String] path to ssh_config file
125
154
  def ssh_config
126
155
  ssh_config_path = File.expand_path(File.join(@vagrant_path, "ssh_config"))
127
156
  begin
@@ -137,17 +166,6 @@ module RSpecSystem
137
166
  ssh_config_path
138
167
  end
139
168
 
140
- # Provide Vagrantfile templates from node definition.
141
- #
142
- # @api private
143
- # @param settings [Hash] provider specific settings for vagrant
144
- def template_node(settings)
145
- template = <<-EOS
146
- vmconf.vm.box = '#{settings['box']}'
147
- vmconf.vm.box_url = '#{settings['box_url']}'
148
- EOS
149
- end
150
-
151
169
  # Execute vagrant command in vagrant_path
152
170
  #
153
171
  # @api private
@@ -2,7 +2,7 @@
2
2
  Gem::Specification.new do |s|
3
3
  # Metadata
4
4
  s.name = "rspec-system"
5
- s.version = "0.3.1"
5
+ s.version = "0.3.2"
6
6
  s.authors = ["Ken Barber"]
7
7
  s.email = ["ken@bob.sh"]
8
8
  s.homepage = "https://github.com/kbarber/rspec-system"
@@ -13,12 +13,18 @@ Pathname.glob("#{dir}/shared_behaviours/**/*.rb") do |behaviour|
13
13
  require behaviour.relative_path_from(Pathname.new(dir))
14
14
  end
15
15
 
16
+ def root_path
17
+ Pathname.new(File.expand_path(File.join(__FILE__, '..', '..')))
18
+ end
19
+
16
20
  def fixture_path
17
- Pathname.new(File.expand_path(File.join(__FILE__, '..', 'fixtures')))
21
+ root_path + 'spec' + 'fixtures'
18
22
  end
23
+
19
24
  def resources_path
20
- Pathname.new(File.expand_path(File.join(__FILE__, '..', '..', 'resources')))
25
+ root_path + 'resources'
21
26
  end
27
+
22
28
  def schema_path
23
29
  resources_path + 'kwalify-schemas'
24
30
  end
@@ -25,4 +25,15 @@ describe 'nodeset_schema' do
25
25
  errors.should == []
26
26
  end
27
27
  end
28
+
29
+ it "my own .nodeset.yml should validate" do
30
+ ydoc = parser.parse_file(root_path + '.nodeset.yml')
31
+ errors = parser.errors
32
+ if errors && !errors.empty?
33
+ errors.each do |e|
34
+ puts "line=#{e.linenum}, path=#{e.path}, mesg=#{e.message}"
35
+ end
36
+ end
37
+ errors.should == []
38
+ end
28
39
  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: 0.3.1
4
+ version: 0.3.2
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-04-11 00:00:00.000000000 Z
12
+ date: 2013-04-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec