Add rake tasks to test both beaker and beaker-rspec in one go
[puppet_vcsrepo.git] / Rakefile
1 require 'puppetlabs_spec_helper/rake_tasks'
2 require 'rake'
3
4 task 'beaker:test',[:host,:type] => :set_beaker_variables do |t,args|
5
6   Rake::Task['beaker-rspec:test'].invoke(args)
7
8   if File.exists?('./acceptance')
9     Dir.chdir('./acceptance')
10     exec(build_beaker_command args)
11     Dir.chdir('../')
12   else
13     puts "No acceptance directory found, not running beaker tests"
14   end
15
16 end
17
18 desc "Run beaker rspec tasks against pe"
19 RSpec::Core::RakeTask.new('beaker-rspec:test',[:host,:type]=>:set_beaker_variables) do |t,args|
20   t.pattern     = 'spec/acceptance'
21   t.rspec_opts  = '--color'
22   t.verbose     = true
23 end
24
25 desc "Run beaker and beaker-rspec tasks"
26 task 'beaker:test:pe',:host do |t,args|
27   args.with_defaults(:type=> 'pe')
28   Rake::Task['beaker:test'].invoke(args[:host],args[:type])
29 end
30
31 task 'beaker:test:git',:host do |t,args|
32   args.with_defaults({:type=> 'git'})
33   Rake::Task['beaker:test'].invoke(args[:host],args[:type])
34 end
35
36 task :set_beaker_variables do |t,args|
37   puts 'Setting environment variables for testing'
38   if args[:host]
39     ENV['BEAKER_set'] = args[:host]
40     puts "Host to test #{ENV['BEAKER_set']}"
41   end
42   ENV['BEAKER_IS_PE'] = args[:type] == 'pe'? "true": "false"
43 end
44
45 def build_beaker_command(args)
46   cmd = ["beaker"]
47   cmd << "--type #{args[:type]}" unless !args[:type]
48   if File.exists?("./.beaker-#{args[:type]}.cfg")
49     cmd << "--options-file ./.beaker-#{args[:type]}.cfg"
50   end
51   if File.exists?("config/#{args[:host]}.cfg")
52     cmd << "--hosts config/#{args[:host]}.cfg"
53   end
54   if File.exists?("./tests")
55     cmd << "--tests ./tests"
56   end
57   cmd.join(" ")
58 end