Class: InitPluginCli
- Inherits:
-
Minitest::Test
- Object
- Minitest::Test
- InitPluginCli
- Includes:
- CorePluginFunctionalHelper
- Defined in:
- lib/plugins/inspec-init/test/functional/inspec_init_plugin_test.rb
Constant Summary
Constants included from CorePluginFunctionalHelper
CorePluginFunctionalHelper::TRAIN_CONNECTION
Instance Method Summary collapse
- #test_generating_inspec_plugin_correct_prefix_required ⇒ Object
- #test_generating_inspec_plugin_with_custom_options ⇒ Object
- #test_generating_inspec_plugin_with_default_options ⇒ Object
Methods included from CorePluginFunctionalHelper
#__find_plugin_path_from_caller, #__make_empty_plugin_file_data_structure, #__make_plugin_file_data_structure_with_path, #run_inspec_process, #run_inspec_process_with_this_plugin
Instance Method Details
#test_generating_inspec_plugin_correct_prefix_required ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/plugins/inspec-init/test/functional/inspec_init_plugin_test.rb', line 6 def Dir.mktmpdir do |dir| plugin = "wacky-name" run_result = run_inspec_process("init plugin --no-prompt #{plugin} ", prefix: "cd #{dir} &&") skip_windows! assert_includes run_result.stdout, "ERROR" assert_includes run_result.stdout, "Plugin names must begin with" assert_empty run_result.stderr assert_exit_code 1, run_result end end |
#test_generating_inspec_plugin_with_custom_options ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/plugins/inspec-init/test/functional/inspec_init_plugin_test.rb', line 117 def Dir.mktmpdir do |dir| plugin = "inspec-test-generated-plugin" snake_case = plugin.tr("-", "_") opts = "" opts += " --author-email [email protected] " opts += " --author-name Bob " opts += ' --copyright "Copyright © 2018 Bob" ' opts += ' --description "That you will really like" ' opts += " --license-name BSD-3-Clause " opts += ' --summary "A fantastic plugin" ' opts += " --homepage http://example.com " opts += " --module_name FunPlugin" run_result = run_inspec_process("init plugin #{plugin} --no-prompt #{opts}", prefix: "cd #{dir} &&") skip_windows! assert_includes run_result.stdout, "Creating new inspec plugin at" assert_includes run_result.stdout, plugin assert_empty run_result.stderr assert_exit_code 0, run_result # Check generated files and contents. # Each file must exist, and its contents must match each of the regexen given. { File.join(plugin, "README.md") => [], File.join(plugin, "LICENSE") => [ /Copyright © 2018 Bob/, /used to endorse or promote/, ], File.join(plugin, "Gemfile") => [], File.join(plugin, "Rakefile") => [], File.join(plugin, plugin + ".gemspec") => [ /spec\.version\s+=\s+InspecPlugins::FunPlugin::VERSION/, /spec\.authors\s+=\s+\['Bob'\]/, /spec\.email\s+=\s+\['bob@example\.com'\]/, /spec\.summary\s+=\s+'A fantastic plugin'/, /spec\.description\s+=\s+'That you will really like'/, %r{spec\.homepage\s+=\s+'http://example.com'}, /spec\.license\s+=\s+'BSD-3-Clause'/, ], File.join(plugin, "lib", plugin + ".rb") => [], File.join(plugin, "lib", plugin, "plugin.rb") => [], File.join(plugin, "lib", plugin, "version.rb") => [], File.join(plugin, "lib", plugin, "cli_command.rb") => [], File.join(plugin, "test", "helper.rb") => [], File.join(plugin, "test", "functional", snake_case + "_test.rb") => [], File.join(plugin, "test", "unit", "plugin_def_test.rb") => [], File.join(plugin, "test", "unit", "cli_args_test.rb") => [], }.each do |path, regexen| full_path = File.join(dir, path) assert(File.exist?(full_path), "#{path} should have been generated") next if regexen.empty? contents = File.read(full_path) regexen.each do |re| assert_match re, contents, "#{path} should match #{re}" end end end end |
#test_generating_inspec_plugin_with_default_options ⇒ Object
21 22 23 24 25 26 27 28 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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/plugins/inspec-init/test/functional/inspec_init_plugin_test.rb', line 21 def Dir.mktmpdir do |dir| plugin = "inspec-test-generated-plugin" snake_case = plugin.tr("-", "_") module_name = plugin.sub(/^inspec\-/, "").split("-").map(&:capitalize).join("") run_result = run_inspec_process("init plugin --no-prompt #{plugin}", prefix: "cd #{dir} &&") skip_windows! assert_includes run_result.stdout, "Creating new inspec plugin at" assert_includes run_result.stdout, plugin assert_empty run_result.stderr assert_exit_code 0, run_result # Check generated files and contents. # Each file must exist, and its contents must match each of the regexen given. { File.join(plugin, "README.md") => [ /#{plugin}/, ], File.join(plugin, "LICENSE") => [ /(?!opyright)/, # No copyright by default /Apache License/, ], File.join(plugin, "Gemfile") => [], # No interpolation File.join(plugin, "Rakefile") => [], # No interpolation File.join(plugin, plugin + ".gemspec") => [ %r{require '#{plugin}/version'}, /spec\.name\s+=\s+'#{plugin}'/, /spec\.version\s+=\s+InspecPlugins::#{module_name}::VERSION/, /README\.md\s+#{snake_case}\.gemspec\s+Gemfile/, /spec\.authors\s+=\s+\['Your Name'\]/, /spec\.email\s+=\s+\['you@example\.com'\]/, /spec\.summary\s+=\s+'A plugin with a default summary'/, /spec\.description\s+=\s+''/, %r{spec\.homepage\s+=\s+'https://github.com/you/#{plugin}'}, /spec\.license\s+=\s+'Apache-2\.0'/, ], File.join(plugin, "lib", plugin + ".rb") => [ %r{require\s'#{plugin}/plugin'}, ], File.join(plugin, "lib", plugin, "plugin.rb") => [ %r{require\s'#{plugin}/version'}, /\#\s#{plugin}\s=>\s#{module_name}/, /module\s#{module_name}/, /plugin_name\s+:'#{plugin}'/, # Default assumes one cli hook /cli_command :my_command/, %r{require\s'#{plugin}/cli_command'}, /InspecPlugins::#{module_name}::CliCommand/, ], File.join(plugin, "lib", plugin, "version.rb") => [ /module\s#{module_name}/, ], File.join(plugin, "lib", plugin, "cli_command.rb") => [ /module\sInspecPlugins::#{module_name}/, /\#\smakes\s`inspec\smy-command\s\.\.\.`\swork\./, /subcommand_desc\s'my_command\s\[COMMAND\]'/, /\#\sas\s`inspec\smy-command\sdo-something/, /\#\sin\s`inspec\shelp\smy-command`/, /\#\sruns\s`inspec\smy-command\sdo-something`./, %r{Edit\slib/#{plugin}/cli_command\.rb\sto\smake\sit\sdo}, ], File.join(plugin, "test", "helper.rb") => [], # No interpolation File.join(plugin, "test", "functional", "README.md") => [], # No interpolation File.join(plugin, "test", "functional", snake_case + "_test.rb") => [ # Whatever goes here ], File.join(plugin, "test", "unit", "plugin_def_test.rb") => [ %r{require\s'#{plugin}/plugin'}, /describe InspecPlugins::#{module_name}::Plugin\sdo/, /let\(:plugin_name\) \{ \:'#{plugin}\' \}/, ], File.join(plugin, "test", "unit", "cli_args_test.rb") => [ %r{require '#{plugin}/cli_command'}, /describe InspecPlugins::#{module_name}::CliCommand do/, /let\(\:cli_class\) \{ InspecPlugins::#{module_name}::CliCommand \}/, ], File.join(plugin, "test", "unit", "README.md") => [ /cli_args_test\.rb/, ], }.each do |path, regexen| full_path = File.join(dir, path) assert(File.exist?(full_path), "#{path} should have been generated") next if regexen.empty? contents = File.read(full_path) regexen.each do |re| assert_match re, contents, "#{path} should match #{re}" end end end end |