sleeping_king_studios-tasks 0.1.0.rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +26 -0
  3. data/DEVELOPMENT.md +50 -0
  4. data/LICENSE +22 -0
  5. data/README.md +405 -0
  6. data/lib/sleeping_king_studios/tasks.rb +27 -0
  7. data/lib/sleeping_king_studios/tasks/apps.rb +49 -0
  8. data/lib/sleeping_king_studios/tasks/apps/app_configuration.rb +68 -0
  9. data/lib/sleeping_king_studios/tasks/apps/applications_task.rb +28 -0
  10. data/lib/sleeping_king_studios/tasks/apps/bundle.rb +8 -0
  11. data/lib/sleeping_king_studios/tasks/apps/bundle/install_runner.rb +21 -0
  12. data/lib/sleeping_king_studios/tasks/apps/bundle/install_task.rb +39 -0
  13. data/lib/sleeping_king_studios/tasks/apps/bundle/update_runner.rb +21 -0
  14. data/lib/sleeping_king_studios/tasks/apps/bundle/update_task.rb +39 -0
  15. data/lib/sleeping_king_studios/tasks/apps/ci.rb +8 -0
  16. data/lib/sleeping_king_studios/tasks/apps/ci/results_reporter.rb +69 -0
  17. data/lib/sleeping_king_studios/tasks/apps/ci/rspec_task.rb +29 -0
  18. data/lib/sleeping_king_studios/tasks/apps/ci/rspec_wrapper.rb +42 -0
  19. data/lib/sleeping_king_studios/tasks/apps/ci/rubocop_task.rb +29 -0
  20. data/lib/sleeping_king_studios/tasks/apps/ci/rubocop_wrapper.rb +29 -0
  21. data/lib/sleeping_king_studios/tasks/apps/ci/simplecov_task.rb +68 -0
  22. data/lib/sleeping_king_studios/tasks/apps/ci/step_wrapper.rb +49 -0
  23. data/lib/sleeping_king_studios/tasks/apps/ci/steps_runner.rb +37 -0
  24. data/lib/sleeping_king_studios/tasks/apps/ci/steps_task.rb +92 -0
  25. data/lib/sleeping_king_studios/tasks/ci.rb +8 -0
  26. data/lib/sleeping_king_studios/tasks/ci/cucumber_parser.rb +118 -0
  27. data/lib/sleeping_king_studios/tasks/ci/cucumber_results.rb +191 -0
  28. data/lib/sleeping_king_studios/tasks/ci/cucumber_runner.rb +53 -0
  29. data/lib/sleeping_king_studios/tasks/ci/cucumber_task.rb +47 -0
  30. data/lib/sleeping_king_studios/tasks/ci/results_helpers.rb +44 -0
  31. data/lib/sleeping_king_studios/tasks/ci/rspec_each_results.rb +118 -0
  32. data/lib/sleeping_king_studios/tasks/ci/rspec_each_task.rb +156 -0
  33. data/lib/sleeping_king_studios/tasks/ci/rspec_results.rb +126 -0
  34. data/lib/sleeping_king_studios/tasks/ci/rspec_runner.rb +62 -0
  35. data/lib/sleeping_king_studios/tasks/ci/rspec_task.rb +71 -0
  36. data/lib/sleeping_king_studios/tasks/ci/rubocop_results.rb +80 -0
  37. data/lib/sleeping_king_studios/tasks/ci/rubocop_runner.rb +46 -0
  38. data/lib/sleeping_king_studios/tasks/ci/rubocop_task.rb +44 -0
  39. data/lib/sleeping_king_studios/tasks/ci/simplecov_results.rb +62 -0
  40. data/lib/sleeping_king_studios/tasks/ci/simplecov_task.rb +25 -0
  41. data/lib/sleeping_king_studios/tasks/ci/steps_runner.rb +69 -0
  42. data/lib/sleeping_king_studios/tasks/ci/steps_task.rb +93 -0
  43. data/lib/sleeping_king_studios/tasks/configuration.rb +114 -0
  44. data/lib/sleeping_king_studios/tasks/file.rb +8 -0
  45. data/lib/sleeping_king_studios/tasks/file/new_task.rb +238 -0
  46. data/lib/sleeping_king_studios/tasks/process_runner.rb +70 -0
  47. data/lib/sleeping_king_studios/tasks/task.rb +95 -0
  48. data/lib/sleeping_king_studios/tasks/task_group.rb +37 -0
  49. data/lib/sleeping_king_studios/tasks/version.rb +58 -0
  50. metadata +271 -0
@@ -0,0 +1,93 @@
1
+ # lib/sleeping_king_studios/tasks/ci/steps_task.rb
2
+
3
+ require 'sleeping_king_studios/tasks/ci'
4
+ require 'sleeping_king_studios/tasks/ci/results_helpers'
5
+ require 'sleeping_king_studios/tasks/ci/steps_runner'
6
+
7
+ module SleepingKingStudios::Tasks::Ci
8
+ # Thor task for running each step in the CI suite and generating a report.
9
+ class StepsTask < SleepingKingStudios::Tasks::Ci::StepsRunner
10
+ include SleepingKingStudios::Tasks::Ci::ResultsHelpers
11
+
12
+ def self.description
13
+ 'Runs the configured steps for your test suite.'
14
+ end # class method description
15
+
16
+ option :except,
17
+ :type => :array,
18
+ :default => [],
19
+ :desc => 'Exclude steps from the CI process.'
20
+ option :only,
21
+ :type => :array,
22
+ :default => [],
23
+ :desc => 'Run only the specified steps from the CI process.'
24
+ option :quiet,
25
+ :aliases => '-q',
26
+ :type => :boolean,
27
+ :default => false,
28
+ :desc => 'Do not write intermediate results to STDOUT.'
29
+
30
+ def call *files
31
+ results = super
32
+
33
+ report results
34
+
35
+ report_failures results
36
+
37
+ results
38
+ end # method call
39
+
40
+ private
41
+
42
+ def ci_steps
43
+ SleepingKingStudios::Tasks.configuration.ci.steps_with_options
44
+ end # method ci_steps
45
+
46
+ def failing? step
47
+ return true if step.failing?
48
+
49
+ return true if step.respond_to?(:errored?) && step.errored?
50
+
51
+ false
52
+ end # method failing?
53
+
54
+ def format_failures failing_steps
55
+ tools.array.humanize_list(failing_steps) do |name|
56
+ set_color(name, :red)
57
+ end # humanize list
58
+ end # method format_failures
59
+
60
+ def report results
61
+ rows =
62
+ results.map do |key, obj|
63
+ [set_color("#{key}:", results_color(obj)), obj.to_s]
64
+ end # results
65
+
66
+ say "\n"
67
+
68
+ print_table rows
69
+ end # method report
70
+
71
+ # rubocop:disable Metrics/MethodLength
72
+ def report_failures results
73
+ failing_steps =
74
+ results.each.with_object([]) do |(key, step), ary|
75
+ ary << key if failing?(step)
76
+ end # each
77
+
78
+ say "\n"
79
+
80
+ if failing_steps.empty?
81
+ say 'The CI suite passed.', :green
82
+
83
+ return
84
+ end # if
85
+
86
+ say "The following steps failed: #{format_failures failing_steps}"
87
+ say "\n"
88
+
89
+ raise Thor::Error, 'The CI suite failed.'
90
+ end # method report_failures
91
+ # rubocop:enable Metrics/MethodLength
92
+ end # class
93
+ end # module
@@ -0,0 +1,114 @@
1
+ # lib/sleeping_king_studios/tasks/configuration.rb
2
+
3
+ require 'sleeping_king_studios/tools/toolbox/configuration'
4
+
5
+ require 'sleeping_king_studios/tasks'
6
+
7
+ module SleepingKingStudios::Tasks
8
+ # Task configuration options, grouped by namespace.
9
+ class Configuration < SleepingKingStudios::Tools::Toolbox::Configuration
10
+ # rubocop:disable Metrics/BlockLength
11
+ namespace :apps do
12
+ namespace :ci do
13
+ option :rspec, :default =>
14
+ {
15
+ :require => 'sleeping_king_studios/tasks/apps/ci/rspec_wrapper',
16
+ :class => 'SleepingKingStudios::Tasks::Apps::Ci::RSpecWrapper',
17
+ :title => 'RSpec'
18
+ } # end rspec
19
+
20
+ option :rubocop, :default =>
21
+ {
22
+ :require => 'sleeping_king_studios/tasks/apps/ci/rubocop_wrapper',
23
+ :class => 'SleepingKingStudios::Tasks::Apps::Ci::RuboCopWrapper',
24
+ :title => 'RuboCop'
25
+ } # end rspec
26
+
27
+ option :simplecov, :default =>
28
+ {
29
+ :require => 'sleeping_king_studios/tasks/apps/ci/simplecov_task',
30
+ :class => 'SleepingKingStudios::Tasks::Apps::Ci::SimpleCovTask',
31
+ :title => 'SimpleCov',
32
+ :global => true
33
+ } # end rspec
34
+
35
+ option :steps, :default => %i(rspec rubocop simplecov)
36
+
37
+ define_method :steps_with_options do
38
+ steps.each.with_object({}) do |step, hsh|
39
+ hsh[step] = send(step)
40
+ end # each
41
+ end # method steps_with_options
42
+ end # namespace
43
+
44
+ option :config_file, :default => 'applications.yml'
45
+ end # namespace
46
+ # rubocop:enable Metrics/BlockLength
47
+
48
+ # rubocop:disable Metrics/BlockLength
49
+ namespace :ci do
50
+ option :cucumber, :default =>
51
+ {
52
+ :require => 'sleeping_king_studios/tasks/ci/cucumber_task',
53
+ :class => 'SleepingKingStudios::Tasks::Ci::CucumberTask',
54
+ :title => 'Cucumber',
55
+ :default_files => ['step_definitions', 'step_definitions.rb']
56
+ } # end cucumber
57
+
58
+ option :rspec, :default =>
59
+ {
60
+ :require => 'sleeping_king_studios/tasks/ci/rspec_task',
61
+ :class => 'SleepingKingStudios::Tasks::Ci::RSpecTask',
62
+ :title => 'RSpec'
63
+ } # end rspec
64
+
65
+ option :rspec_each, :default =>
66
+ {
67
+ :require => 'sleeping_king_studios/tasks/ci/rspec_each_task',
68
+ :class => 'SleepingKingStudios::Tasks::Ci::RSpecEachTask',
69
+ :title => 'RSpec (Each)'
70
+ } # end rspec
71
+
72
+ option :rubocop, :default =>
73
+ {
74
+ :require => 'sleeping_king_studios/tasks/ci/rubocop_task',
75
+ :class => 'SleepingKingStudios::Tasks::Ci::RuboCopTask',
76
+ :title => 'RuboCop'
77
+ } # end rspec
78
+
79
+ option :simplecov, :default =>
80
+ {
81
+ :require => 'sleeping_king_studios/tasks/ci/simplecov_task',
82
+ :class => 'SleepingKingStudios::Tasks::Ci::SimpleCovTask',
83
+ :title => 'SimpleCov'
84
+ } # end rspec
85
+
86
+ option :steps, :default => %i(rspec rubocop simplecov)
87
+
88
+ define_method :steps_with_options do
89
+ steps.each.with_object({}) do |step, hsh|
90
+ hsh[step] = send(step)
91
+ end # each
92
+ end # method steps_with_options
93
+ end # namespace
94
+ # rubocop:enable Metrics/BlockLength
95
+
96
+ namespace :file do
97
+ def self.default_template_path
98
+ relative_path =
99
+ ::File.join(
100
+ SleepingKingStudios::Tasks.gem_path,
101
+ 'lib',
102
+ 'sleeping_king_studios',
103
+ 'tasks',
104
+ 'file',
105
+ 'templates'
106
+ ) # end join
107
+
108
+ ::File.expand_path(relative_path).freeze
109
+ end # method default_template_path
110
+
111
+ option :template_paths, :default => [default_template_path]
112
+ end # namespace
113
+ end # class
114
+ end # module
@@ -0,0 +1,8 @@
1
+ # lib/sleeping_king_studios/tasks/file.rb
2
+
3
+ require 'sleeping_king_studios/tasks'
4
+
5
+ module SleepingKingStudios::Tasks
6
+ # Thor tasks for managing the file system.
7
+ module File; end
8
+ end # module
@@ -0,0 +1,238 @@
1
+ # lib/sleeping_king_studios/tasks/file/new_task.rb
2
+
3
+ require 'erubi'
4
+
5
+ require 'fileutils'
6
+
7
+ require 'sleeping_king_studios/tasks/file'
8
+
9
+ module SleepingKingStudios::Tasks::File
10
+ # rubocop:disable Metrics/ClassLength
11
+
12
+ # Thor task for generating a new Ruby source file.
13
+ class NewTask < SleepingKingStudios::Tasks::Task
14
+ def self.description
15
+ 'Creates a Ruby source file and corresponding spec file.'
16
+ end # class method description
17
+
18
+ option :'dry-run',
19
+ :aliases => '-d',
20
+ :type => :boolean,
21
+ :default => false,
22
+ :desc =>
23
+ 'Lists the file(s) to create, but does not change the filesystem.'
24
+ option :force,
25
+ :aliases => '-f',
26
+ :type => :boolean,
27
+ :default => false,
28
+ :desc => 'Overwrite the files if the files already exist.'
29
+ option :prompt,
30
+ :aliases => '-p',
31
+ :type => :boolean,
32
+ :default => false,
33
+ :desc => 'Prompt the user for confirmation before creating the files.'
34
+ option :quiet,
35
+ :aliases => '-q',
36
+ :type => :boolean,
37
+ :default => false,
38
+ :desc => 'Suppress output to STDOUT.'
39
+ option :spec,
40
+ :type => :boolean,
41
+ :default => true,
42
+ :desc => 'Create a spec file for the new source file.'
43
+ option :verbose,
44
+ :aliases => '-v',
45
+ :type => :boolean,
46
+ :default => false,
47
+ :desc => 'Print additional information about the task.'
48
+
49
+ def call file_path
50
+ split_file_path(file_path)
51
+
52
+ check_for_existing_file file_path
53
+ check_for_existing_file spec_path if spec?
54
+
55
+ preview
56
+
57
+ return unless prompt_confirmation
58
+
59
+ create_source_file
60
+ create_spec_file
61
+
62
+ say 'Complete!', :green
63
+ end # method file_name
64
+
65
+ private
66
+
67
+ attr_reader :directory
68
+ attr_reader :file_name
69
+ attr_reader :file_path
70
+ attr_reader :relative_path
71
+ attr_reader :spec_path
72
+
73
+ alias_method :mute?, :quiet?
74
+
75
+ def check_for_existing_file file_path
76
+ return unless File.exist?(file_path)
77
+
78
+ raise "file already exists at #{file_path}" unless force?
79
+ end # method check_for_existing_file
80
+
81
+ def create_source_file
82
+ create_directories directory, *relative_path
83
+
84
+ File.write file_path, rendered_source unless dry_run?
85
+ end # method create_file
86
+
87
+ def create_spec_file
88
+ return unless spec?
89
+
90
+ return if spec_file?
91
+
92
+ create_directories 'spec', *relative_path
93
+
94
+ File.write spec_path, rendered_spec unless dry_run?
95
+ end # method create_spec_file
96
+
97
+ def create_directories *directory_names
98
+ return if dry_run?
99
+
100
+ FileUtils.mkdir_p directory_names.compact.join(File::SEPARATOR)
101
+ end # method create_directories
102
+
103
+ def find_template name
104
+ template_paths.each do |template_dir|
105
+ template_path = File.expand_path(File.join template_dir, name)
106
+
107
+ next unless File.exist?(template_path)
108
+
109
+ return File.read(template_path)
110
+ end # each
111
+
112
+ nil
113
+ end # method find_template
114
+
115
+ def preview
116
+ say 'Files to create:'
117
+ say "\n"
118
+
119
+ preview_files
120
+
121
+ say "\n" unless verbose?
122
+ end # method preview
123
+
124
+ def preview_file file_path, max:, template:
125
+ str = " %-#{max}.#{max}s # using template '%s'"
126
+
127
+ say format(str, file_path, template)
128
+
129
+ return unless verbose?
130
+
131
+ say "\n"
132
+ say yield
133
+ say "\n"
134
+ end # method preview_file
135
+
136
+ # rubocop:disable Metrics/AbcSize
137
+ def preview_files
138
+ max = spec? ? [file_path.length, spec_path.length].max : file_path.length
139
+
140
+ template = spec_file? ? 'rspec.erb' : 'ruby.erb'
141
+
142
+ preview_file file_path, :max => max, :template => template do
143
+ tools.string.indent(rendered_source, 4)
144
+ end # preview_file
145
+
146
+ return unless spec? && !spec_file?
147
+
148
+ preview_file spec_path, :max => max, :template => 'rspec.erb' do
149
+ tools.string.indent(rendered_spec, 4)
150
+ end # preview_file
151
+ end # method preview_files
152
+ # rubocop:enable Metrics/AbcSize
153
+
154
+ def prompt_confirmation
155
+ return true unless prompt?
156
+
157
+ unless yes? 'Create files? (yes|no)\n>'
158
+ say "\n"
159
+ say 'Cancelled!', :yellow
160
+
161
+ return false
162
+ end # if-else
163
+
164
+ say "\n"
165
+
166
+ true
167
+ end # prompt_confirmation
168
+
169
+ def render_template name, locals = {}
170
+ template = find_template(name)
171
+ source = Erubi::Engine.new(template).src
172
+ binding = Object.new.send(:binding)
173
+
174
+ locals.each do |key, value|
175
+ binding.local_variable_set key, value
176
+ end # each
177
+
178
+ binding.eval source
179
+ end # method render_template
180
+
181
+ def rendered_source
182
+ template = spec_file? ? 'rspec.erb' : 'ruby.erb'
183
+
184
+ @rendered_source ||=
185
+ render_template(
186
+ template,
187
+ :file_path => file_path,
188
+ :file_name => file_name,
189
+ :relative_path => relative_path
190
+ ) # end render template
191
+ end # method rendered_source
192
+
193
+ def rendered_spec
194
+ @rendered_spec ||=
195
+ render_template(
196
+ 'rspec.erb',
197
+ :file_path => spec_path,
198
+ :file_name => "#{file_name}_spec",
199
+ :relative_path => relative_path
200
+ ) # end render template
201
+ end # method rendered_spec
202
+
203
+ def spec_file?
204
+ directory == 'spec' && file_name.end_with?('_spec')
205
+ end # method spec_file?
206
+
207
+ def split_file_path file_path
208
+ @file_path = file_path
209
+ @directory = nil
210
+ extension = File.extname(file_path)
211
+ fragments = file_path.split(File::SEPARATOR)
212
+ @file_name = File.basename(fragments.pop, extension)
213
+
214
+ split_relative_path fragments
215
+
216
+ @spec_path =
217
+ File.join 'spec', *relative_path, "#{file_name}_spec#{extension}"
218
+ end # method split_file_path
219
+
220
+ def split_relative_path fragments
221
+ if %w(app apps lib spec tmp vendor).include?(fragments.first)
222
+ @directory = fragments.shift
223
+ end # if
224
+
225
+ @relative_path = fragments
226
+ end # method split_relative_path
227
+
228
+ def template_paths
229
+ SleepingKingStudios::Tasks.configuration.file.template_paths
230
+ end # method template_paths
231
+
232
+ def tools
233
+ SleepingKingStudios::Tools::Toolbelt.instance
234
+ end # method tools
235
+ end # class
236
+
237
+ # rubocop:enable Metrics/ClassLength
238
+ end # module