Class: ServerspecLauncherRakeTasks
- Inherits:
-
Object
- Object
- ServerspecLauncherRakeTasks
show all
- Includes:
- ExampleHelper, Rake::DSL
- Defined in:
- lib/serverspec_launcher/rake_tasks.rb
Overview
Class Method Summary
collapse
Instance Method Summary
collapse
-
#debug_tasks ⇒ Object
-
#initialize(properties = nil) ⇒ ServerspecLauncherRakeTasks
constructor
A new instance of ServerspecLauncherRakeTasks.
-
#load_tasks ⇒ Object
-
#serverspec_rake_task(host, key, task_name, spec_type, options = {}, target = {}) ⇒ Object
-
#serverspec_task_array(key, spec_type, target, options) ⇒ Object
-
#set_formatters(report_path, options, t) ⇒ Object
#load_bundled_examples, #load_examples_from_gem, #load_shared_examples, #shared_examples
Constructor Details
Returns a new instance of ServerspecLauncherRakeTasks.
21
22
23
24
25
26
27
|
# File 'lib/serverspec_launcher/rake_tasks.rb', line 21
def initialize(properties = nil)
@properties = properties
options = @properties[:options] || {}
@fail_on_err = options[:fail_on_err]
@formatters = options[:formatters] || ['tick']
@colorize = options[:color].nil? ? true : options[:color]
end
|
Class Method Details
.load(properties = nil) ⇒ Object
Instance Method Details
#debug_tasks ⇒ Object
135
136
137
138
139
140
141
142
143
144
145
146
|
# File 'lib/serverspec_launcher/rake_tasks.rb', line 135
def debug_tasks
namespace :debug do
desc 'View loaded Shared examples'
task :shared_examples do
puts 'Loaded Shared Examples:\n======================='
load_shared_examples @properties[:shared_example_gems] || []
shared_examples.each do |ex|
puts "\t#{ex}"
end
end
end
end
|
#load_tasks ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/serverspec_launcher/rake_tasks.rb', line 29
def load_tasks
task serverspec: 'serverspec:all'
namespace :serverspec do
targets = @properties[:targets] || {}
environments = @properties[:environments] || {}
desc 'Run all targets and environments'
task all: targets.keys.map { |key| 'serverspec:' + key.to_s.split('.')[0] }.concat(environments.keys.map {|key| 'serverspec:' + key.to_s.split('.')[0] })
targets.keys.each do |key|
target = targets[key]
process_target(key, target)
end
puts
environments.keys.each do |key|
desc "Run all tasks in environment #{key}"
task key.to_sym => "serverspec:#{key}:all"
namespace key.to_sym do
environment = environments[key]
task all: environment[:targets].map { |target, _hash| "serverspec:#{key}:#{target.to_s.split(':')[0].to_sym}" }
environment[:targets].each do |target, hash|
process_target("#{target}", hash, 'environment', key.to_s)
end
end
end
end
end
|
#serverspec_rake_task(host, key, task_name, spec_type, options = {}, target = {}) ⇒ Object
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/serverspec_launcher/rake_tasks.rb', line 79
def serverspec_rake_task(host, key, task_name, spec_type, options = {}, target = {})
desc "Run serverspec to #{key}"
RSpec::Core::RakeTask.new(task_name.to_s.to_sym) do |t|
ENV['TARGET_HOST'] = host.to_s
ENV['TARGET'] = key.to_s
ENV['TASK_NAME'] = task_name.to_s
ENV['TASK_SOURCE'] = options[:source]
ENV['TASK_ENV'] = options[:environment]
t.pattern = "spec/#{spec_type}_spec.rb"
t.fail_on_error = options[:fail_on_err]
report_name = options[:environment] ? "reports/#{options[:environment]}/#{key.to_s}/#{host.to_s}" : "reports/#{key.to_s}/#{host.to_s}"
set_formatters(report_name, options, t)
end
end
|
#serverspec_task_array(key, spec_type, target, options) ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/serverspec_launcher/rake_tasks.rb', line 61
def serverspec_task_array(key, spec_type, target, options)
env = options[:source] == 'environment' ? ":"+ options[:environment] : ""
desc "Run serverspec to #{key}"
task key.to_sym => "serverspec#{env}:#{key}:all"
namespace key.to_sym do
desc "Run #{key} against all hosts"
task :all do
target[:hosts].each do |host|
Rake::Task["serverspec#{env}:#{key}:#{host.split(':')[0].to_sym}"].execute
end
end
target[:hosts].each do |host|
task_name = "#{host || target[:name]}"
serverspec_rake_task(host, key, task_name, spec_type, options)
end
end
end
|
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
# File 'lib/serverspec_launcher/rake_tasks.rb', line 94
def set_formatters(report_path, options, t)
opts = t.rspec_opts
if options[:formatters].include?('junit') || options[:formatters].include?('xml')
opts = "#{opts} --format RspecJunitFormatter --out #{report_path}.xml"
end
if options[:formatters].include?('docs') || options[:formatters].include?('documentation') || options[:formatters].include?('docs_file')
opts = "#{opts} --format documentation --out #{report_path}.docs"
end
if options[:formatters].include?('docs_screen')
opts = "#{opts} --format documentation"
end
if options[:formatters].include?('tick')
opts = "#{opts} --format RspecTickFormatter"
end
if options[:formatters].include?('tick_file')
opts = "#{opts} --format RspecTickFormatter --out #{report_path}.tick"
end
if options[:formatters].include?('progress')
opts = "#{opts} --format progress"
end
if options[:formatters].include?('html')
opts = "#{opts} --format html --out #{report_path}.html"
end
if options[:formatters].include?('html_report') || options[:formatters].include?('html_pretty')
opts = "#{opts} --format RspecHtmlReporter"
end
if options[:formatters].include?('json')
opts = "#{opts} --format j --out #{report_path}.json"
end
if options[:formatters].include?('launcher')
opts = "#{opts} --format LauncherJsonFormatter --out #{report_path}_extended.json"
end
unless options[:color]
opts = "#{opts} --no-color"
end
if File.exist?('.rspec')
opts = "#{opts} --options .rspec"
end
t.rspec_opts = opts
end
|