aruba 1.0.0.pre.alpha.2 → 1.0.0.pre.alpha.3

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 (113) hide show
  1. checksums.yaml +5 -5
  2. data/.github/PULL_REQUEST_TEMPLATE.md +2 -1
  3. data/.rubocop.yml +6 -181
  4. data/.rubocop_todo.yml +364 -0
  5. data/.travis.yml +63 -34
  6. data/.yardopts +3 -0
  7. data/CHANGELOG.md +1121 -0
  8. data/CONTRIBUTING.md +179 -78
  9. data/Gemfile +29 -44
  10. data/README.md +41 -11
  11. data/Rakefile +35 -35
  12. data/appveyor.yml +6 -5
  13. data/aruba.gemspec +14 -16
  14. data/bin/console +2 -11
  15. data/cucumber.yml +0 -7
  16. data/fixtures/cli-app/README.md +1 -1
  17. data/fixtures/cli-app/Rakefile +1 -1
  18. data/fixtures/cli-app/cli-app.gemspec +1 -0
  19. data/fixtures/cli-app/lib/cli/app/suppress_simple_cov_output.rb +3 -3
  20. data/fixtures/cli-app/lib/cli/app/version.rb +1 -1
  21. data/fixtures/empty-app/Rakefile +1 -1
  22. data/fixtures/empty-app/cli-app.gemspec +1 -0
  23. data/fixtures/empty-app/lib/cli/app/version.rb +1 -1
  24. data/fixtures/getting-started-app/Gemfile +1 -1
  25. data/lib/aruba/api.rb +3 -10
  26. data/lib/aruba/api/bundler.rb +16 -0
  27. data/lib/aruba/api/commands.rb +249 -0
  28. data/lib/aruba/api/core.rb +24 -10
  29. data/lib/aruba/api/environment.rb +12 -7
  30. data/lib/aruba/api/filesystem.rb +22 -20
  31. data/lib/aruba/api/text.rb +3 -9
  32. data/lib/aruba/aruba_path.rb +3 -18
  33. data/lib/aruba/basic_configuration.rb +3 -19
  34. data/lib/aruba/cli.rb +1 -1
  35. data/lib/aruba/colorizer.rb +33 -33
  36. data/lib/aruba/command.rb +4 -0
  37. data/lib/aruba/config_wrapper.rb +1 -1
  38. data/lib/aruba/configuration.rb +78 -0
  39. data/lib/aruba/console.rb +5 -5
  40. data/lib/aruba/console/help.rb +1 -1
  41. data/lib/aruba/cucumber.rb +0 -1
  42. data/lib/aruba/cucumber/command.rb +55 -115
  43. data/lib/aruba/cucumber/environment.rb +1 -1
  44. data/lib/aruba/cucumber/file.rb +9 -21
  45. data/lib/aruba/cucumber/hooks.rb +6 -62
  46. data/lib/aruba/event_bus/name_resolver.rb +1 -2
  47. data/lib/aruba/hooks.rb +1 -1
  48. data/lib/aruba/initializer.rb +3 -3
  49. data/lib/aruba/matchers/base/base_matcher.rb +2 -2
  50. data/lib/aruba/matchers/base/message_indenter.rb +19 -0
  51. data/lib/aruba/matchers/base/object_formatter.rb +2 -2
  52. data/lib/aruba/matchers/collection/include_an_object.rb +7 -9
  53. data/lib/aruba/matchers/command/be_successfully_executed.rb +2 -4
  54. data/lib/aruba/matchers/command/have_exit_status.rb +1 -1
  55. data/lib/aruba/matchers/command/have_finished_in_time.rb +2 -4
  56. data/lib/aruba/matchers/command/have_output.rb +9 -4
  57. data/lib/aruba/matchers/command/have_output_on_stderr.rb +1 -1
  58. data/lib/aruba/matchers/command/have_output_on_stdout.rb +1 -1
  59. data/lib/aruba/matchers/command/have_output_size.rb +1 -1
  60. data/lib/aruba/matchers/directory/be_an_existing_directory.rb +4 -6
  61. data/lib/aruba/matchers/directory/have_sub_directory.rb +4 -6
  62. data/lib/aruba/matchers/file/be_a_command_found_in_path.rb +2 -4
  63. data/lib/aruba/matchers/file/be_an_existing_executable.rb +4 -6
  64. data/lib/aruba/matchers/file/be_an_existing_file.rb +4 -6
  65. data/lib/aruba/matchers/file/have_file_content.rb +4 -4
  66. data/lib/aruba/matchers/file/have_file_size.rb +6 -8
  67. data/lib/aruba/matchers/file/have_same_file_content.rb +9 -12
  68. data/lib/aruba/matchers/path/a_path_matching_pattern.rb +2 -4
  69. data/lib/aruba/matchers/path/be_an_absolute_path.rb +3 -5
  70. data/lib/aruba/matchers/path/be_an_existing_path.rb +4 -6
  71. data/lib/aruba/matchers/path/have_permissions.rb +6 -8
  72. data/lib/aruba/matchers/string/include_output_string.rb +8 -10
  73. data/lib/aruba/matchers/string/match_output_string.rb +9 -11
  74. data/lib/aruba/matchers/string/output_string_eq.rb +7 -9
  75. data/lib/aruba/platform.rb +0 -1
  76. data/lib/aruba/platforms/announcer.rb +26 -70
  77. data/lib/aruba/platforms/aruba_file_creator.rb +1 -1
  78. data/lib/aruba/platforms/aruba_fixed_size_file_creator.rb +2 -2
  79. data/lib/aruba/platforms/aruba_logger.rb +22 -2
  80. data/lib/aruba/platforms/command_monitor.rb +2 -125
  81. data/lib/aruba/platforms/filesystem_status.rb +9 -9
  82. data/lib/aruba/platforms/local_environment.rb +2 -2
  83. data/lib/aruba/platforms/simple_table.rb +3 -3
  84. data/lib/aruba/platforms/unix_command_string.rb +7 -4
  85. data/lib/aruba/platforms/unix_environment_variables.rb +9 -13
  86. data/lib/aruba/platforms/unix_platform.rb +2 -27
  87. data/lib/aruba/platforms/unix_which.rb +2 -1
  88. data/lib/aruba/platforms/windows_command_string.rb +20 -7
  89. data/lib/aruba/platforms/windows_environment_variables.rb +35 -30
  90. data/lib/aruba/platforms/windows_which.rb +4 -3
  91. data/lib/aruba/processes/basic_process.rb +11 -15
  92. data/lib/aruba/processes/debug_process.rb +5 -0
  93. data/lib/aruba/processes/in_process.rb +17 -8
  94. data/lib/aruba/processes/spawn_process.rb +35 -23
  95. data/lib/aruba/rspec.rb +9 -22
  96. data/lib/aruba/runtime.rb +7 -5
  97. data/lib/aruba/setup.rb +6 -4
  98. data/lib/aruba/tasks/docker_helpers.rb +1 -1
  99. data/lib/aruba/version.rb +1 -1
  100. metadata +37 -57
  101. data/History.md +0 -612
  102. data/bin/bootstrap +0 -34
  103. data/fixtures/spawn_process/stderr.sh +0 -3
  104. data/lib/aruba/api/command.rb +0 -309
  105. data/lib/aruba/api/deprecated.rb +0 -895
  106. data/lib/aruba/api/rvm.rb +0 -44
  107. data/lib/aruba/config.rb +0 -101
  108. data/lib/aruba/cucumber/rvm.rb +0 -3
  109. data/lib/aruba/in_process.rb +0 -14
  110. data/lib/aruba/jruby.rb +0 -4
  111. data/lib/aruba/matchers/path/match_path_pattern.rb +0 -41
  112. data/lib/aruba/matchers/rspec_matcher_include_regexp.rb +0 -25
  113. data/lib/aruba/spawn_process.rb +0 -11
@@ -4,7 +4,7 @@ require 'shellwords'
4
4
  # @!method be_an_existing_executable
5
5
  # This matchers checks if <file> exists in filesystem
6
6
  #
7
- # @return [TrueClass, FalseClass] The result
7
+ # @return [Boolean] The result
8
8
  #
9
9
  # false:
10
10
  # * if file does not exist
@@ -24,14 +24,12 @@ RSpec::Matchers.define :be_an_existing_executable do |_|
24
24
  end
25
25
 
26
26
  failure_message do |actual|
27
- format("expected that executable \"%s\" exists", actual)
27
+ format('expected that executable "%s" exists', actual)
28
28
  end
29
29
 
30
30
  failure_message_when_negated do |actual|
31
- format("expected that executable \"%s\" does not exist", actual)
31
+ format('expected that executable "%s" does not exist', actual)
32
32
  end
33
33
  end
34
34
 
35
- if RSpec::Expectations::Version::STRING >= '3.0'
36
- RSpec::Matchers.alias_matcher :an_existing_executable, :be_an_existing_executable
37
- end
35
+ RSpec::Matchers.alias_matcher :an_existing_executable, :be_an_existing_executable
@@ -3,7 +3,7 @@ require 'rspec/expectations/version'
3
3
  # @!method be_an_existing_file
4
4
  # This matchers checks if <file> exists in filesystem
5
5
  #
6
- # @return [TrueClass, FalseClass] The result
6
+ # @return [Boolean] The result
7
7
  #
8
8
  # false:
9
9
  # * if file does not exist
@@ -25,14 +25,12 @@ RSpec::Matchers.define :be_an_existing_file do |_|
25
25
  end
26
26
 
27
27
  failure_message do |actual|
28
- format("expected that file \"%s\" exists", actual)
28
+ format('expected that file "%s" exists', actual)
29
29
  end
30
30
 
31
31
  failure_message_when_negated do |actual|
32
- format("expected that file \"%s\" does not exist", actual)
32
+ format('expected that file "%s" does not exist', actual)
33
33
  end
34
34
  end
35
35
 
36
- if RSpec::Expectations::Version::STRING >= '3.0'
37
- RSpec::Matchers.alias_matcher :an_existing_file, :be_an_existing_file
38
- end
36
+ RSpec::Matchers.alias_matcher :an_existing_file, :be_an_existing_file
@@ -7,7 +7,7 @@ require 'rspec/expectations/version'
7
7
  # @param [String, Regexp, Matcher] content
8
8
  # Specifies the content of the file
9
9
  #
10
- # @return [TrueClass, FalseClass] The result
10
+ # @return [Boolean] The result
11
11
  #
12
12
  # false:
13
13
  # * if file does not exist
@@ -54,9 +54,9 @@ RSpec::Matchers.define :have_file_content do |expected|
54
54
  values_match?(@expected, @actual)
55
55
  end
56
56
 
57
+ diffable if expected.is_a? String
58
+
57
59
  description { "have file content: #{description_of expected}" }
58
60
  end
59
61
 
60
- if RSpec::Expectations::Version::STRING >= '3.0'
61
- RSpec::Matchers.alias_matcher :a_file_having_content, :have_file_content
62
- end
62
+ RSpec::Matchers.alias_matcher :a_file_having_content, :have_file_content
@@ -6,7 +6,7 @@ require 'rspec/expectations/version'
6
6
  # @param [Fixnum] size
7
7
  # The size to check
8
8
  #
9
- # @return [TrueClass, FalseClass] The result
9
+ # @return [Boolean] The result
10
10
  #
11
11
  # false:
12
12
  # * if path does not have size
@@ -33,15 +33,13 @@ RSpec::Matchers.define :have_file_size do |expected|
33
33
  values_match?(@expected, @actual)
34
34
  end
35
35
 
36
- failure_message do |actual|
37
- format("expected that file \"%s\" has size \"%s\", but has \"%s\"", @old_actual, @actual, @expected)
36
+ failure_message do |_actual|
37
+ format('expected that file "%s" has size "%s", but has "%s"', @old_actual, @actual, @expected)
38
38
  end
39
39
 
40
- failure_message_when_negated do |actual|
41
- format("expected that file \"%s\" does not have size \"%s\", but has \"%s\"", @old_actual, @actual, @expected)
40
+ failure_message_when_negated do |_actual|
41
+ format('expected that file "%s" does not have size "%s", but has "%s"', @old_actual, @actual, @expected)
42
42
  end
43
43
  end
44
44
 
45
- if RSpec::Expectations::Version::STRING >= '3.0'
46
- RSpec::Matchers.alias_matcher :a_file_of_size, :have_file_size
47
- end
45
+ RSpec::Matchers.alias_matcher :a_file_of_size, :have_file_size
@@ -1,15 +1,14 @@
1
1
  require 'rspec/expectations/version'
2
-
3
2
  require 'fileutils'
4
3
 
5
- # @!method have_same_file_content_like(file_name)
4
+ # @!method have_same_file_content_as(file_name)
6
5
  # This matchers checks if <file1> has the same content like <file2>
7
6
  #
8
7
  # @param [String] file_name
9
8
  # The name of the file which should be compared with the file in the
10
9
  # `expect()`-call.
11
10
  #
12
- # @return [TrueClass, FalseClass] The result
11
+ # @return [Boolean] The result
13
12
  #
14
13
  # false:
15
14
  # * if file1 is not equal file2
@@ -19,10 +18,10 @@ require 'fileutils'
19
18
  # @example Use matcher
20
19
  #
21
20
  # RSpec.describe do
22
- # it { expect(file1).to have_same_file_content_like(file2) }
23
- # it { expect(files).to include a_file_with_same_content_like(file2) }
21
+ # it { expect(file1).to have_same_file_content_as(file2) }
22
+ # it { expect(files).to include a_file_with_same_content_as(file2) }
24
23
  # end
25
- RSpec::Matchers.define :have_same_file_content_like do |expected|
24
+ RSpec::Matchers.define :have_same_file_content_as do |expected|
26
25
  match do |actual|
27
26
  stop_all_commands
28
27
 
@@ -31,18 +30,16 @@ RSpec::Matchers.define :have_same_file_content_like do |expected|
31
30
  @actual = expand_path(actual)
32
31
  @expected = expand_path(expected)
33
32
 
34
- FileUtils.compare_file(@actual,@expected)
33
+ FileUtils.compare_file(@actual, @expected)
35
34
  end
36
35
 
37
36
  failure_message do |actual|
38
- format("expected that file \"%s\" is the same as file \"%s\".", actual, expected)
37
+ format('expected that file "%s" is the same as file "%s".', actual, expected)
39
38
  end
40
39
 
41
40
  failure_message_when_negated do |actual|
42
- format("expected that file \"%s\" differs from file \"%s\".", actual, expected)
41
+ format('expected that file "%s" differs from file "%s".', actual, expected)
43
42
  end
44
43
  end
45
44
 
46
- if RSpec::Expectations::Version::STRING >= '3.0'
47
- RSpec::Matchers.alias_matcher :a_file_with_same_content_like, :have_same_file_content_like
48
- end
45
+ RSpec::Matchers.alias_matcher :a_file_with_same_content_as, :have_same_file_content_as
@@ -7,7 +7,7 @@ require 'rspec/expectations/version'
7
7
  # @param [String, Regexp, Matcher] pattern
8
8
  # Specifies the pattern
9
9
  #
10
- # @return [TrueClass, FalseClass] The result
10
+ # @return [Boolean] The result
11
11
  #
12
12
  # false:
13
13
  # * if pattern does not match
@@ -20,6 +20,4 @@ require 'rspec/expectations/version'
20
20
  # RSpec.describe do
21
21
  # it { expect(files).to include a_path_matching_pattern /asdf/ }
22
22
  # end
23
- if RSpec::Expectations::Version::STRING >= '3.0'
24
- RSpec::Matchers.alias_matcher :a_path_matching_pattern, :match
25
- end
23
+ RSpec::Matchers.alias_matcher :a_path_matching_pattern, :match
@@ -3,7 +3,7 @@ require 'rspec/expectations/version'
3
3
  # @!method be_an_absolute_path
4
4
  # This matchers checks if <path> exists in filesystem
5
5
  #
6
- # @return [TrueClass, FalseClass] The result
6
+ # @return [Boolean] The result
7
7
  #
8
8
  # false:
9
9
  # * if path is not absolute
@@ -27,10 +27,8 @@ RSpec::Matchers.define :be_an_absolute_path do |_|
27
27
  end
28
28
 
29
29
  failure_message_when_negated do |actual|
30
- format("expected that path \"%s\" is not absolute, but it is", actual)
30
+ format('expected that path "%s" is not absolute, but it is', actual)
31
31
  end
32
32
  end
33
33
 
34
- if RSpec::Expectations::Version::STRING >= '3.0'
35
- RSpec::Matchers.alias_matcher :an_absolute_path, :be_an_absolute_path
36
- end
34
+ RSpec::Matchers.alias_matcher :an_absolute_path, :be_an_absolute_path
@@ -3,7 +3,7 @@ require 'rspec/expectations/version'
3
3
  # @!method be_an_existing_path
4
4
  # This matchers checks if <path> exists in filesystem
5
5
  #
6
- # @return [TrueClass, FalseClass] The result
6
+ # @return [Boolean] The result
7
7
  #
8
8
  # false:
9
9
  # * if path does not exist
@@ -24,14 +24,12 @@ RSpec::Matchers.define :be_an_existing_path do |_|
24
24
  end
25
25
 
26
26
  failure_message do |actual|
27
- format("expected that path \"%s\" exists", actual)
27
+ format('expected that path "%s" exists', actual)
28
28
  end
29
29
 
30
30
  failure_message_when_negated do |actual|
31
- format("expected that path \"%s\" does not exist", actual)
31
+ format('expected that path "%s" does not exist', actual)
32
32
  end
33
33
  end
34
34
 
35
- if RSpec::Expectations::Version::STRING >= '3.0'
36
- RSpec::Matchers.alias_matcher :an_existing_path, :be_an_existing_path
37
- end
35
+ RSpec::Matchers.alias_matcher :an_existing_path, :be_an_existing_path
@@ -6,7 +6,7 @@ require 'rspec/expectations/version'
6
6
  # @param [Fixnum, String] permissions
7
7
  # The permissions as octal number, e.g. `0700`, or String, e.g. `'0700'`
8
8
  #
9
- # @return [TrueClass, FalseClass] The result
9
+ # @return [Boolean] The result
10
10
  #
11
11
  # false:
12
12
  # * if file has permissions
@@ -50,15 +50,13 @@ RSpec::Matchers.define :have_permissions do |expected|
50
50
  values_match? @expected, @actual
51
51
  end
52
52
 
53
- failure_message do |actual|
54
- format("expected that path \"%s\" has permissions \"%s\", but has \"%s\".", @old_actual, @expected, @actual)
53
+ failure_message do |_actual|
54
+ format('expected that path "%s" has permissions "%s", but has "%s".', @old_actual, @expected, @actual)
55
55
  end
56
56
 
57
- failure_message_when_negated do |actual|
58
- format("expected that path \"%s\" does not have permissions \"%s\", but has \"%s\".", @old_actual, @expected, @actual)
57
+ failure_message_when_negated do |_actual|
58
+ format('expected that path "%s" does not have permissions "%s", but has "%s".', @old_actual, @expected, @actual)
59
59
  end
60
60
  end
61
61
 
62
- if RSpec::Expectations::Version::STRING >= '3.0'
63
- RSpec::Matchers.alias_matcher :a_path_having_permissions, :have_permissions
64
- end
62
+ RSpec::Matchers.alias_matcher :a_path_having_permissions, :have_permissions
@@ -1,24 +1,24 @@
1
1
  # @!method include_output_string(string)
2
2
  # This matchers checks if the output string of a command includes string.
3
3
  #
4
- # @param [Integer] status
5
- # The value of the exit status
4
+ # @param [String] string
5
+ # The value of the output string
6
6
  #
7
- # @return [TrueClass, FalseClass] The result
7
+ # @return [Boolean] The result
8
8
  #
9
- # false:
9
+ # False:
10
10
  # * if the output string does not include string
11
- # true:
11
+ # True:
12
12
  # * if the output string includes string
13
13
  #
14
14
  # @example Use matcher
15
- #
16
15
  # RSpec.describe do
17
16
  # it { expect(last_command_started).to have_output an_output_string_including string) }
18
17
  # it { expect(last_command_started).to have_output include_output_string string) }
19
18
  # end
20
19
  RSpec::Matchers.define :include_output_string do |expected|
21
20
  match do |actual|
21
+ actual.force_encoding('UTF-8')
22
22
  @expected = Regexp.new(Regexp.escape(sanitize_text(expected.to_s)), Regexp::MULTILINE)
23
23
  @actual = sanitize_text(actual)
24
24
 
@@ -30,7 +30,5 @@ RSpec::Matchers.define :include_output_string do |expected|
30
30
  description { "string includes: #{description_of expected}" }
31
31
  end
32
32
 
33
- if RSpec::Expectations::Version::STRING >= '3.0'
34
- RSpec::Matchers.alias_matcher :an_output_string_including, :include_output_string
35
- RSpec::Matchers.alias_matcher :file_content_including, :include_output_string
36
- end
33
+ RSpec::Matchers.alias_matcher :an_output_string_including, :include_output_string
34
+ RSpec::Matchers.alias_matcher :file_content_including, :include_output_string
@@ -1,24 +1,24 @@
1
1
  # @!method match_output_string(string)
2
2
  # This matchers checks if the output string of a command matches regular expression.
3
3
  #
4
- # @param [Integer] status
5
- # The value of the exit status
4
+ # @param [String] string
5
+ # The value of the output string
6
6
  #
7
- # @return [TrueClass, FalseClass] The result
7
+ # @return [Boolean] The result
8
8
  #
9
- # false:
9
+ # False:
10
10
  # * if the output string does not match regex
11
- # true:
11
+ # True:
12
12
  # * if the output string matches regex
13
13
  #
14
14
  # @example Use matcher
15
- #
16
15
  # RSpec.describe do
17
16
  # it { expect(last_command_started).to have_output an_output_string_matching regex) }
18
17
  # it { expect(last_command_started).to have_output match_output_string regex) }
19
18
  # end
20
19
  RSpec::Matchers.define :match_output_string do |expected|
21
20
  match do |actual|
21
+ actual.force_encoding('UTF-8')
22
22
  @expected = Regexp.new(unescape_text(expected), Regexp::MULTILINE)
23
23
  @actual = sanitize_text(actual)
24
24
 
@@ -30,8 +30,6 @@ RSpec::Matchers.define :match_output_string do |expected|
30
30
  description { "output string matches: #{description_of expected}" }
31
31
  end
32
32
 
33
- if RSpec::Expectations::Version::STRING >= '3.0'
34
- RSpec::Matchers.alias_matcher :an_output_string_matching, :match_output_string
35
- RSpec::Matchers.alias_matcher :a_file_name_matching, :match_output_string
36
- RSpec::Matchers.alias_matcher :file_content_matching, :match_output_string
37
- end
33
+ RSpec::Matchers.alias_matcher :an_output_string_matching, :match_output_string
34
+ RSpec::Matchers.alias_matcher :a_file_name_matching, :match_output_string
35
+ RSpec::Matchers.alias_matcher :file_content_matching, :match_output_string
@@ -1,24 +1,24 @@
1
1
  # @!method output_string_eq(string)
2
2
  # This matchers checks if the output string of a command includes string.
3
3
  #
4
- # @param [Integer] status
5
- # The value of the exit status
4
+ # @param [String] string
5
+ # The value of the output string
6
6
  #
7
- # @return [TrueClass, FalseClass] The result
7
+ # @return [Boolean]
8
8
  #
9
- # false:
9
+ # False:
10
10
  # * if the output string does not include string
11
- # true:
11
+ # True:
12
12
  # * if the output string includes string
13
13
  #
14
14
  # @example Use matcher
15
- #
16
15
  # RSpec.describe do
17
16
  # it { expect(last_command_started).to have_output output_string_eq string) }
18
17
  # it { expect(last_command_started).to have_output an_output_string_begin_eq string) }
19
18
  # end
20
19
  RSpec::Matchers.define :output_string_eq do |expected|
21
20
  match do |actual|
21
+ actual.force_encoding('UTF-8')
22
22
  @expected = sanitize_text(expected.to_s)
23
23
  @actual = sanitize_text(actual.to_s)
24
24
 
@@ -30,6 +30,4 @@ RSpec::Matchers.define :output_string_eq do |expected|
30
30
  description { "output string is eq: #{description_of expected}" }
31
31
  end
32
32
 
33
- if RSpec::Expectations::Version::STRING >= '3.0'
34
- RSpec::Matchers.alias_matcher :an_output_string_being_eq, :output_string_eq
35
- end
33
+ RSpec::Matchers.alias_matcher :an_output_string_being_eq, :output_string_eq
@@ -1,4 +1,3 @@
1
- require 'thread'
2
1
  require 'aruba/platforms/unix_platform'
3
2
  require 'aruba/platforms/windows_platform'
4
3
 
@@ -1,7 +1,7 @@
1
1
  require 'shellwords'
2
2
  require 'aruba/colorizer'
3
3
 
4
- Aruba::AnsiColor.coloring = false if !STDOUT.tty? && !ENV.key?("AUTOTEST")
4
+ Aruba::AnsiColor.coloring = false if !STDOUT.tty? && !ENV.key?('AUTOTEST')
5
5
 
6
6
  # Aruba
7
7
  module Aruba
@@ -27,25 +27,32 @@ module Aruba
27
27
  # Aruba.announcer.announce(:my_channel, 'my message')
28
28
  #
29
29
  class Announcer
30
+ # Base Announcer class
31
+ class BaseAnnouncer
32
+ def mode?(m)
33
+ mode == m
34
+ end
35
+ end
36
+
30
37
  # Announcer using Kernel.puts
31
- class KernelPutsAnnouncer
38
+ class KernelPutsAnnouncer < BaseAnnouncer
32
39
  def announce(message)
33
40
  Kernel.puts message
34
41
  end
35
42
 
36
- def mode?(m)
37
- :kernel_puts == m
43
+ def mode
44
+ :kernel_puts
38
45
  end
39
46
  end
40
47
 
41
48
  # Announcer using Main#puts
42
- class PutsAnnouncer
49
+ class PutsAnnouncer < BaseAnnouncer
43
50
  def announce(message)
44
51
  puts message
45
52
  end
46
53
 
47
- def mode?(m)
48
- :puts == m
54
+ def mode
55
+ :puts
49
56
  end
50
57
  end
51
58
 
@@ -55,7 +62,7 @@ module Aruba
55
62
 
56
63
  public
57
64
 
58
- def initialize(*args)
65
+ def initialize
59
66
  @announcers = []
60
67
  @announcers << PutsAnnouncer.new
61
68
  @announcers << KernelPutsAnnouncer.new
@@ -66,14 +73,11 @@ module Aruba
66
73
  @channels = {}
67
74
  @output_formats = {}
68
75
 
69
- @options = args[1] || {}
70
-
71
76
  after_init
72
77
  end
73
78
 
74
79
  private
75
80
 
76
- # rubocop:disable Metrics/MethodLength
77
81
  def after_init
78
82
  output_format :changed_configuration, proc { |n, v| format('# %s = %s', n, v) }
79
83
  output_format :changed_environment, proc { |n, v| format('$ export %s=%s', n, Shellwords.escape(v)) }
@@ -89,33 +93,9 @@ module Aruba
89
93
  output_format :timeout, '# %s-timeout: %s seconds'
90
94
  output_format :wait_time, '# %s: %s seconds'
91
95
  # rubocop:disable Metrics/LineLength
92
- output_format :command_filesystem_status, proc { |status| format("<<-COMMAND FILESYSTEM STATUS\n%s\nCOMMAND FILESYSTEM STATUS", Aruba.platform.simple_table(status.to_h, :sort => false)) }
93
- # rubocop:enable Metrics/LineLength
94
-
95
- # rubocop:disable Metrics/LineLength
96
- if @options[:stdout]
97
- warn('The use of "@announce_stdout-instance" variable and "options[:stdout] = true" for Announcer.new is deprecated. Please use "announcer.activate(:stdout)" instead.')
98
- activate :stdout
99
- end
100
- if @options[:stderr]
101
- warn('The use of "@announce_stderr-instance" variable and "options[:stderr] = true" for Announcer.new is deprecated. Please use "announcer.activate(:stderr)" instead.')
102
- activate :stderr
103
- end
104
- if @options[:dir]
105
- warn('The use of "@announce_dir-instance" variable and "options[:dir] = true" for Announcer.new is deprecated. Please use "announcer.activate(:directory)" instead.')
106
- activate :directory
107
- end
108
- if @options[:cmd]
109
- warn('The use of "@announce_cmd-instance" variable and "options[:cmd] = true" for Announcer.new is deprecated. Please use "announcer.activate(:command)" instead.')
110
- activate :command
111
- end
112
- if @options[:env]
113
- warn('The use of "@announce_env-instance" variable and "options[:env] = true" for Announcer.new is deprecated. Please use "announcer.activate(:modified_environment)" instead.')
114
- activate :modified_enviroment
115
- end
96
+ output_format :command_filesystem_status, proc { |status| format("<<-COMMAND FILESYSTEM STATUS\n%s\nCOMMAND FILESYSTEM STATUS", Aruba.platform.simple_table(status.to_h, sort: false)) }
116
97
  # rubocop:enable Metrics/LineLength
117
98
  end
118
- # rubocop:enable Metrics/MethodLength
119
99
 
120
100
  def output_format(channel, string = '%s', &block)
121
101
  output_formats[channel.to_sym] = if block_given?
@@ -139,11 +119,18 @@ module Aruba
139
119
  # @param [Symbol] m
140
120
  # The mode to set
141
121
  def mode=(m)
142
- @announcer = @announcers.find { |a| f.mode? m.to_sym }
122
+ @announcer = @announcers.find { |a| a.mode? m.to_sym }
143
123
 
144
124
  self
145
125
  end
146
126
 
127
+ # Fecth mode of announcer
128
+ #
129
+ # @return [Symbol] The current announcer mode
130
+ def mode
131
+ @announcer.mode
132
+ end
133
+
147
134
  # Check if channel is activated
148
135
  #
149
136
  # @param [Symbol] channel
@@ -154,7 +141,7 @@ module Aruba
154
141
 
155
142
  # Activate a channel
156
143
  #
157
- # @param [Symbol] channel
144
+ # @param [Symbol] chns
158
145
  # The name of the channel to activate
159
146
  def activate(*chns)
160
147
  chns.flatten.each { |c| channels[c.to_sym] = true }
@@ -173,7 +160,7 @@ module Aruba
173
160
  # @yield
174
161
  # If block is given, that one is called and the return value is used as
175
162
  # message to be announced.
176
- def announce(channel, *args, &block)
163
+ def announce(channel, *args)
177
164
  channel = channel.to_sym
178
165
 
179
166
  the_output_format = if output_formats.key? channel
@@ -196,37 +183,6 @@ module Aruba
196
183
 
197
184
  nil
198
185
  end
199
-
200
- # @deprecated
201
- def stdout(content)
202
- warn('The announcer now has a new api to activate channels. Please use this one: announce(:stdout, message)')
203
- announce :stdout, content
204
- end
205
-
206
- # @deprecated
207
- def stderr(content)
208
- warn('The announcer now has a new api to activate channels. Please use this one: announce(:stderr, message)')
209
- announce :stderr, content
210
- end
211
-
212
- # @deprecated
213
- def dir(dir)
214
- warn('The announcer now has a new api to activate channels. Please use this one announce(:directory, message)')
215
- announce :directory, dir
216
- end
217
-
218
- # @deprecated
219
- def cmd(cmd)
220
- warn('The announcer now has a new api to activate channels. Please use this one announce(:command, message)')
221
- announce :command, cmd
222
- end
223
-
224
- # @deprecated
225
- def env(name, value)
226
- warn('The announcer now has a new api to activate channels. Please use this one: announce(:changed_environment, key, value)')
227
-
228
- announce :changed_environment, name, value
229
- end
230
186
  end
231
187
  end
232
188
  end