-
-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add minitest integration and unit tests generation for subcommands
- Loading branch information
1 parent
36b57ce
commit af7431d
Showing
6 changed files
with
158 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,23 @@ | ||
require 'test_helper' | ||
require '<%= cmd_path %>' | ||
|
||
class <%= cmd_object_parts.join('::') %>Test < Minitest::Test | ||
def test_executes_<%= cmd_name_underscored %>_command_successfully | ||
output = `<%= app_name_underscored %> <%= cmd_name_underscored %>` | ||
assert_equal nil, output | ||
class <%= (cmd_object_parts - [subcmd_name_constantinized]).join('::') %>Test < Minitest::Test | ||
def test_executes_<%= "#{app_name_underscored}_help_#{cmd_name_underscored}" %>_command_successfully | ||
output = `<%= app_name_underscored %> help <%= cmd_name_underscored %>` | ||
expected_output = <<-OUT | ||
<%- if subcmd_name_underscored.to_s.empty? -%> | ||
Usage: | ||
<%= app_name_underscored + ' ' + cmd_name_underscored + cmd_desc_args %> | ||
|
||
Options: | ||
-h, [--help], [--no-help] # Display usage information | ||
|
||
<%= cmd_desc %> | ||
<%- else -%> | ||
Commands: | ||
<%- end -%> | ||
OUT | ||
|
||
assert_equal expected_output, output | ||
end | ||
end |
19 changes: 19 additions & 0 deletions
19
lib/tty/templates/add/test/integration/sub_command_test.rb.tt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require 'test_helper' | ||
require '<%= subcmd_path %>' | ||
|
||
class <%= cmd_object_parts.join('::') %>Test < Minitest::Test | ||
def test_executes_<%= "#{app_name_underscored}_#{cmd_name_underscored}_help_#{subcmd_name_underscored}" %>_command_successfully | ||
output = `<%= "#{app_name_underscored} #{cmd_name_underscored} help #{subcmd_name_underscored}" %>` | ||
expect_output = <<-OUT | ||
Usage: | ||
<%= app_name_underscored + ' ' + subcmd_name_underscored + cmd_desc_args %> | ||
|
||
Options: | ||
-h, [--help], [--no-help] # Display usage information | ||
|
||
<%= cmd_desc %> | ||
OUT | ||
|
||
assert_equal expected_output, output | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
require 'test_helper' | ||
require '<%= subcmd_path %>' | ||
|
||
class <%= object = cmd_object_parts.join('::') %>Test < Minitest::Test | ||
def test_executes_<%= "#{cmd_name_underscored}_#{subcmd_name_underscored}" %>_command_successfully | ||
output = StringIO.new | ||
<%- cmd_options.each do |option| -%> | ||
<%= option %> = <%= option == 'options' ? {} : 'nil' %> | ||
<%- end -%> | ||
command = <%= object %>.new(<%= cmd_options.join(', ') %>) | ||
|
||
command.execute(output: output) | ||
|
||
assert_equal "OK\n", output.string | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters