aruba 0.9.0.pre → 0.9.0.pre2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +8 -3
  3. data/History.md +61 -19
  4. data/README.md +10 -6
  5. data/TODO.md +6 -1
  6. data/cucumber.yml +10 -6
  7. data/features/.nav +72 -0
  8. data/features/announce.feature +203 -0
  9. data/features/api/command/extract_text.feature +10 -0
  10. data/features/api/command/run.feature +6 -6
  11. data/features/api/command/stop_all_commands.feature +53 -0
  12. data/features/api/command/terminate_all_commands.feature +53 -0
  13. data/features/api/command/unescape_text.feature +12 -0
  14. data/features/api/command/which.feature +3 -3
  15. data/features/api/core/expand_path.feature +4 -4
  16. data/features/api/environment/append_environment_variable.feature +18 -8
  17. data/features/api/environment/prepend_environment_variable.feature +18 -8
  18. data/features/api/environment/set_environment_variable.feature +33 -16
  19. data/features/api/filesystem/cd.feature +23 -13
  20. data/features/api/filesystem/create_directory.feature +2 -2
  21. data/features/api/filesystem/disk_usage.feature +7 -6
  22. data/features/api/filesystem/does_exist.feature +2 -2
  23. data/features/api/filesystem/is_absolute.feature +2 -2
  24. data/features/api/filesystem/is_directory.feature +2 -2
  25. data/features/api/filesystem/is_file.feature +2 -2
  26. data/features/api/filesystem/is_relative.feature +2 -2
  27. data/features/api/filesystem/move.feature +119 -0
  28. data/features/cli/console.feature +3 -3
  29. data/features/commands/debug_command.feature +93 -0
  30. data/features/commands/environment_variables.feature +64 -0
  31. data/features/commands/flushing.feature +74 -0
  32. data/features/commands/interactive.feature +90 -0
  33. data/features/commands/output/all_output.feature +445 -0
  34. data/features/commands/output/stdout.feature +66 -0
  35. data/features/configuration/exit_timeout.feature +5 -5
  36. data/features/configuration/fixtures_directories.feature +3 -3
  37. data/features/configuration/fixtures_path_prefix.feature +1 -1
  38. data/features/configuration/home_directory.feature +4 -4
  39. data/features/configuration/io_timeout.feature +2 -2
  40. data/features/configuration/keep_ansi.feature +2 -2
  41. data/features/configuration/log_level.feature +3 -3
  42. data/features/configuration/physical_block_size.feature +3 -3
  43. data/features/configuration/usage.feature +159 -0
  44. data/features/core/cleanup_aruba_directory.feature +52 -0
  45. data/features/development/build.feature +16 -0
  46. data/features/development/test.feature +24 -0
  47. data/features/file_system_commands.feature +12 -12
  48. data/features/getting_started/supported_programming_languages.feature +89 -0
  49. data/features/hooks/after/command.feature +1 -1
  50. data/features/hooks/before/command.feature +2 -2
  51. data/features/matchers/collection/include_an_object.feature +72 -0
  52. data/features/matchers/timeouts.feature +2 -2
  53. data/features/output.feature +60 -181
  54. data/features/step_definitions/aruba_dev_steps.rb +17 -10
  55. data/features/step_definitions/hooks.rb +11 -0
  56. data/features/steps/commands/exit_statuses.feature +3 -3
  57. data/features/steps/commands/run.feature +0 -15
  58. data/features/steps/filesystem/copy.feature +45 -0
  59. data/features/steps/filesystem/create_directory.feature +47 -0
  60. data/features/steps/filesystem/create_file.feature +53 -0
  61. data/features/steps/filesystem/file_content.feature +1 -1
  62. data/features/steps/filesystem/move.feature +45 -0
  63. data/features/steps/filesystem/overwrite_file.feature +72 -0
  64. data/features/steps/filesystem/use_fixture.feature +77 -0
  65. data/features/usage/install.feature +8 -0
  66. data/{features/fixtures → fixtures}/cli-app/.gitignore +0 -0
  67. data/{features/fixtures → fixtures}/cli-app/.rspec +0 -0
  68. data/{features/fixtures → fixtures}/cli-app/README.md +0 -0
  69. data/{features/fixtures → fixtures}/cli-app/Rakefile +0 -0
  70. data/{features/fixtures → fixtures}/cli-app/bin/cli +0 -0
  71. data/{features/fixtures → fixtures}/cli-app/cli-app.gemspec +0 -0
  72. data/{features/fixtures → fixtures}/cli-app/features/support/env.rb +0 -0
  73. data/{features/fixtures → fixtures}/cli-app/lib/cli/app.rb +0 -0
  74. data/fixtures/cli-app/lib/cli/app/suppress_simple_cov_output.rb +15 -0
  75. data/{features/fixtures → fixtures}/cli-app/lib/cli/app/version.rb +0 -0
  76. data/{features/fixtures/empty-app → fixtures/cli-app}/script/console +3 -3
  77. data/{features/fixtures → fixtures}/cli-app/spec/spec_helper.rb +0 -0
  78. data/{features/fixtures → fixtures}/cli-app/spec/support/aruba.rb +0 -0
  79. data/{features/fixtures → fixtures}/copy/file.txt +0 -0
  80. data/{features/fixtures → fixtures}/empty-app/.gitignore +0 -0
  81. data/{features/fixtures → fixtures}/empty-app/.rspec +0 -0
  82. data/{features/fixtures → fixtures}/empty-app/README.md +0 -0
  83. data/{features/fixtures → fixtures}/empty-app/Rakefile +0 -0
  84. data/{features/fixtures → fixtures}/empty-app/bin/cli +0 -0
  85. data/{features/fixtures → fixtures}/empty-app/cli-app.gemspec +0 -0
  86. data/{features/fixtures → fixtures}/empty-app/lib/cli/app.rb +0 -0
  87. data/{features/fixtures → fixtures}/empty-app/lib/cli/app/version.rb +0 -0
  88. data/{features/fixtures/cli-app → fixtures/empty-app}/script/console +3 -3
  89. data/{features/fixtures → fixtures}/empty-app/spec/spec_helper.rb +0 -0
  90. data/{features/fixtures → fixtures}/fixtures-app/test.txt +0 -0
  91. data/fixtures/getting-started-app/.gitignore +4 -0
  92. data/fixtures/getting-started-app/Gemfile +4 -0
  93. data/fixtures/getting-started-app/README.md +3 -0
  94. data/fixtures/getting-started-app/features/support/env.rb +1 -0
  95. data/{features/fixtures → fixtures}/spawn_process/stderr.sh +0 -0
  96. data/lib/aruba/announcer.rb +6 -2
  97. data/lib/aruba/api.rb +0 -16
  98. data/lib/aruba/api/command.rb +64 -266
  99. data/lib/aruba/api/core.rb +24 -26
  100. data/lib/aruba/api/deprecated.rb +370 -12
  101. data/lib/aruba/api/filesystem.rb +64 -15
  102. data/lib/aruba/aruba_path.rb +4 -0
  103. data/lib/aruba/config.rb +1 -1
  104. data/lib/aruba/cucumber.rb +5 -449
  105. data/lib/aruba/cucumber/command.rb +378 -0
  106. data/lib/aruba/cucumber/core.rb +29 -0
  107. data/lib/aruba/cucumber/environment.rb +30 -0
  108. data/lib/aruba/cucumber/file.rb +210 -0
  109. data/lib/aruba/cucumber/hooks.rb +11 -14
  110. data/lib/aruba/cucumber/rvm.rb +3 -0
  111. data/lib/aruba/matchers/base/base_matcher.rb +94 -0
  112. data/lib/aruba/matchers/collection.rb +1 -0
  113. data/lib/aruba/matchers/collection/all_objects.rb +2 -0
  114. data/lib/aruba/matchers/collection/include_an_object.rb +120 -0
  115. data/lib/aruba/matchers/command/be_successfully_executed.rb +3 -3
  116. data/lib/aruba/matchers/command/have_exit_status.rb +2 -11
  117. data/lib/aruba/matchers/command/have_finished_in_time.rb +5 -5
  118. data/lib/aruba/matchers/command/have_output.rb +46 -0
  119. data/lib/aruba/matchers/command/have_output_on_stderr.rb +42 -0
  120. data/lib/aruba/matchers/command/have_output_on_stdout.rb +42 -0
  121. data/lib/aruba/matchers/command/have_output_size.rb +28 -0
  122. data/lib/aruba/matchers/directory/be_an_existing_directory.rb +1 -1
  123. data/lib/aruba/matchers/file/be_an_existing_file.rb +1 -1
  124. data/lib/aruba/matchers/file/have_file_content.rb +1 -1
  125. data/lib/aruba/matchers/file/have_file_size.rb +2 -2
  126. data/lib/aruba/matchers/file/have_same_file_content.rb +1 -1
  127. data/lib/aruba/matchers/path/have_permissions.rb +1 -1
  128. data/lib/aruba/platforms/aruba_file_creator.rb +2 -3
  129. data/lib/aruba/platforms/aruba_fixed_size_file_creator.rb +2 -3
  130. data/lib/aruba/platforms/determine_disk_usage.rb +23 -0
  131. data/lib/aruba/platforms/determine_file_size.rb +13 -0
  132. data/lib/aruba/platforms/disk_usage_calculator.rb +11 -0
  133. data/lib/aruba/platforms/local_environment.rb +15 -0
  134. data/lib/aruba/platforms/unix_environment_variables.rb +1 -1
  135. data/lib/aruba/platforms/unix_platform.rb +35 -14
  136. data/lib/aruba/process_monitor.rb +53 -7
  137. data/lib/aruba/processes/basic_process.rb +25 -5
  138. data/lib/aruba/processes/debug_process.rb +27 -25
  139. data/lib/aruba/processes/in_process.rb +7 -22
  140. data/lib/aruba/processes/spawn_process.rb +74 -31
  141. data/lib/aruba/rspec.rb +1 -6
  142. data/lib/aruba/version.rb +1 -1
  143. data/script/console +0 -1
  144. data/spec/aruba/api/environment/restore_env_spec.rb +65 -0
  145. data/spec/aruba/api/environment/set_env_spec.rb +42 -0
  146. data/spec/aruba/api/filesystem/file_size_spec.rb +28 -0
  147. data/spec/aruba/api_spec.rb +10 -7
  148. data/spec/aruba/matchers/command/have_output_size_spec.rb +25 -0
  149. data/spec/aruba/matchers/command_spec.rb +135 -4
  150. data/spec/aruba/spawn_process_spec.rb +1 -1
  151. metadata +107 -65
  152. data/.nav +0 -12
  153. data/features/debug.feature +0 -15
  154. data/features/fixtures/cli-app/spec/cli/app_spec.rb +0 -7
  155. data/features/flushing.feature +0 -26
  156. data/features/interactive.feature +0 -66
  157. data/features/no_clobber.feature +0 -25
  158. data/lib/aruba/disk_usage_calculator.rb +0 -7
@@ -1,21 +1,11 @@
1
1
  require 'aruba/aruba_path'
2
2
  require 'aruba/api'
3
+ require 'aruba/platform'
3
4
  World(Aruba::Api)
4
5
 
5
6
  if Aruba::VERSION >= '1.0.0'
6
7
  Around do |_, block|
7
- begin
8
- if RUBY_VERSION < '1.9'
9
- old_env = ENV.to_hash.dup
10
- else
11
- old_env = ENV.to_h.dup
12
- end
13
-
14
- block.call
15
- ensure
16
- ENV.clear
17
- ENV.update old_env
18
- end
8
+ Aruba.platform.with_environment(&block)
19
9
  end
20
10
  end
21
11
 
@@ -30,7 +20,7 @@ end
30
20
 
31
21
  After do
32
22
  restore_env
33
- process_monitor.stop_processes!
23
+ terminate_all_commands
34
24
  process_monitor.clear
35
25
  end
36
26
 
@@ -52,6 +42,11 @@ Before('@announce-cmd') do
52
42
  announcer.activate :command
53
43
  end
54
44
 
45
+ Before('@announce-output') do
46
+ announcer.activate :stdout
47
+ announcer.activate :stderr
48
+ end
49
+
55
50
  Before('@announce-stdout') do
56
51
  announcer.activate :stdout
57
52
  end
@@ -114,7 +109,9 @@ end
114
109
  # end
115
110
 
116
111
  Before('@ansi') do
117
- Aruba.platform.deprecated('The use of "@ansi" is deprecated. Use "@keep-ansi-escape-sequences" instead')
112
+ # rubocop:disable Metrics/LineLength
113
+ Aruba::Platform.deprecated('The use of "@ansi" is deprecated. Use "@keep-ansi-escape-sequences" instead. But be aware, that this hook uses the aruba configuration and not an instance variable')
114
+ # rubocop:enable Metrics/LineLength
118
115
 
119
116
  aruba.config.remove_ansi_escape_sequences = false
120
117
  end
@@ -0,0 +1,3 @@
1
+ Given(/^I'm using a clean gemset "([^"]*)"$/) do |gemset|
2
+ use_clean_gemset(gemset)
3
+ end
@@ -0,0 +1,94 @@
1
+ require 'rspec/support/object_formatter'
2
+
3
+ module Aruba
4
+ module Matchers
5
+ # Base Matcher
6
+ class BaseMatcher
7
+ # @api private
8
+ # Used to detect when no arg is passed to `initialize`.
9
+ # `nil` cannot be used because it's a valid value to pass.
10
+ UNDEFINED = Object.new.freeze
11
+
12
+ # @private
13
+ attr_reader :actual, :expected, :rescued_exception
14
+
15
+ def initialize(expected = UNDEFINED)
16
+ @expected = expected unless UNDEFINED.equal?(expected)
17
+ end
18
+
19
+ # @api private
20
+ # Indicates if the match is successful. Delegates to `match`, which
21
+ # should be defined on a subclass. Takes care of consistently
22
+ # initializing the `actual` attribute.
23
+ def matches?(actual)
24
+ @actual = actual
25
+ match(expected, actual)
26
+ end
27
+
28
+ def iterable?
29
+ @actual.respond_to?(:each_with_index)
30
+ end
31
+
32
+ # @private
33
+ module HashFormatting
34
+ # `{ :a => 5, :b => 2 }.inspect` produces:
35
+ #
36
+ # {:a=>5, :b=>2}
37
+ #
38
+ # ...but it looks much better as:
39
+ #
40
+ # {:a => 5, :b => 2}
41
+ #
42
+ # This is idempotent and safe to run on a string multiple times.
43
+ def improve_hash_formatting(inspect_string)
44
+ inspect_string.gsub(/(\S)=>(\S)/, '\1 => \2')
45
+ end
46
+ module_function :improve_hash_formatting
47
+ end
48
+
49
+ include HashFormatting
50
+
51
+ # @api private
52
+ # Provides default implementations of failure messages, based on the `description`.
53
+ module DefaultFailureMessages
54
+ # @api private
55
+ # Provides a good generic failure message. Based on `description`.
56
+ # When subclassing, if you are not satisfied with this failure message
57
+ # you often only need to override `description`.
58
+ # @return [String]
59
+ def failure_message
60
+ "expected #{description_of @actual} to #{description}"
61
+ end
62
+
63
+ # @api private
64
+ # Provides a good generic negative failure message. Based on `description`.
65
+ # When subclassing, if you are not satisfied with this failure message
66
+ # you often only need to override `description`.
67
+ # @return [String]
68
+ def failure_message_when_negated
69
+ "expected #{description_of @actual} not to #{description}"
70
+ end
71
+
72
+ # @private
73
+ # rubocop:disable Style/PredicateName
74
+ def self.has_default_failure_messages?(matcher)
75
+ matcher.method(:failure_message).owner == self &&
76
+ matcher.method(:failure_message_when_negated).owner == self
77
+ rescue NameError
78
+ false
79
+ end
80
+ # rubocop:enable Style/PredicateName
81
+ end
82
+
83
+ include DefaultFailureMessages
84
+
85
+ # Returns the description of the given object in a way that is
86
+ # aware of composed matchers. If the object is a matcher with
87
+ # a `description` method, returns the description; otherwise
88
+ # returns `object.inspect`.
89
+ def description_of(object)
90
+ RSpec::Support::ObjectFormatter.format(object)
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1 @@
1
+ Aruba.platform.require_matching_files('../collection/**/*.rb', __FILE__)
@@ -0,0 +1,2 @@
1
+ # Let's alias :all to have a name which has no conflicts with other libraries
2
+ RSpec::Matchers.alias_matcher :all_objects, :all
@@ -0,0 +1,120 @@
1
+ require 'aruba/matchers/base/base_matcher'
2
+
3
+ module Aruba
4
+ module Matchers
5
+ # @api private
6
+ # Provides the implementation for `include_an_object`.
7
+ # Not intended to be instantiated directly.
8
+ class IncludeAnObject < BaseMatcher
9
+ protected
10
+
11
+ # @private
12
+ attr_reader :matcher, :failed_objects
13
+ # @private
14
+ attr_accessor :any_succeeded_object
15
+
16
+ public
17
+
18
+ def initialize(matcher)
19
+ @matcher = matcher
20
+ @failed_objects = {}
21
+ @any_succeeded_object = false
22
+ end
23
+
24
+ # @api private
25
+ # @return [String]
26
+ def failure_message
27
+ unless iterable?
28
+ return "#{improve_hash_formatting(super)}, but was not iterable"
29
+ end
30
+
31
+ all_messages = [improve_hash_formatting(super)]
32
+ failed_objects.each do |index, matcher_failure_message|
33
+ all_messages << failure_message_for_item(index, matcher_failure_message)
34
+ end
35
+ all_messages.join("\n\n")
36
+ end
37
+
38
+ # @api private
39
+ # @return [String]
40
+ def description
41
+ improve_hash_formatting "include an object #{description_of matcher}"
42
+ end
43
+
44
+ def does_not_match?(actual)
45
+ @actual = actual
46
+
47
+ return false unless iterable?
48
+
49
+ index_objects
50
+
51
+ any_succeeded_object == false
52
+ end
53
+
54
+ private
55
+
56
+ def match(expected, actual)
57
+ @actual = actual
58
+ @expected = expected
59
+
60
+ return false unless iterable?
61
+
62
+ index_objects
63
+
64
+ any_succeeded_object == true
65
+ end
66
+
67
+ def index_objects
68
+ actual.each_with_index do |actual_item, index|
69
+ cloned_matcher = matcher.clone
70
+ begin
71
+ matches = cloned_matcher.matches?(actual_item)
72
+ rescue StandardError
73
+ matches = nil
74
+ end
75
+
76
+ if matches
77
+ self.any_succeeded_object = true
78
+ break
79
+ else
80
+ failed_objects[index] = cloned_matcher.failure_message
81
+ end
82
+ end
83
+ end
84
+
85
+ def failure_message_for_item(index, failure_message)
86
+ failure_message = indent_multiline_message(add_new_line_if_needed(failure_message))
87
+ indent_multiline_message("object at index #{index} failed to match:#{failure_message}")
88
+ end
89
+
90
+ def add_new_line_if_needed(message)
91
+ message.start_with?("\n") ? message : "\n#{message}"
92
+ end
93
+
94
+ def indent_multiline_message(message)
95
+ message = message.sub(/\n+\z/, '')
96
+ message.lines.map do |line|
97
+ line =~ /\S/ ? ' ' + line : line
98
+ end.join
99
+ end
100
+ end
101
+ end
102
+ end
103
+
104
+ module RSpec
105
+ module Matchers
106
+ # Passes if the provided matcher passes when checked against any
107
+ # element of the collection.
108
+ #
109
+ # @example
110
+ # expect([1, 4, 5]).to include_an_object be_odd
111
+ #
112
+ # @note You can also use this with compound matchers as well.
113
+ #
114
+ # @example
115
+ # expect([1, 4, 'a']).to include_an_object( be_odd.and be_an(Integer) )
116
+ def include_an_object(expected)
117
+ ::Aruba::Matchers::IncludeAnObject.new(expected)
118
+ end
119
+ end
120
+ end
@@ -16,9 +16,9 @@ require 'aruba/matchers/command/have_finished_in_time'
16
16
  # @example Use matcher
17
17
  #
18
18
  # RSpec.describe do
19
- # it { expect(last_command).to be_successfully_executed }
20
- # it { expect(last_command).not_to be_successfully_executed }
21
- # it { expect(last_command).to have_failed_running }
19
+ # it { expect(last_command_started).to be_successfully_executed }
20
+ # it { expect(last_command_started).not_to be_successfully_executed }
21
+ # it { expect(last_command_started).to have_failed_running }
22
22
  # end
23
23
  RSpec::Matchers.define :be_successfully_executed do
24
24
  match do |actual|
@@ -14,22 +14,13 @@
14
14
  # @example Use matcher
15
15
  #
16
16
  # RSpec.describe do
17
- # it { expect(last_command).to have_exit_status(0) }
17
+ # it { expect(last_command_started).to have_exit_status(0) }
18
18
  # end
19
19
  RSpec::Matchers.define :have_exit_status do |expected|
20
20
  match do |actual|
21
21
  @old_actual = actual
22
22
 
23
- @announcer ||= Aruba::Announcer.new(
24
- self,
25
- :stdout => @announce_stdout,
26
- :stderr => @announce_stderr,
27
- :dir => @announce_dir,
28
- :cmd => @announce_cmd,
29
- :env => @announce_env
30
- )
31
-
32
- @old_actual.stop(@announcer) unless @old_actual.stopped?
23
+ @old_actual.stop(announcer) unless @old_actual.stopped?
33
24
  @actual = actual.exit_status
34
25
 
35
26
  next false unless @old_actual.respond_to? :exit_status
@@ -14,9 +14,9 @@ require 'rspec/expectations/version'
14
14
  # @example Use matcher
15
15
  #
16
16
  # RSpec.describe do
17
- # it { expect(last_command).to run_too_long }
18
- # it { expect(last_command).not_to run_too_long }
19
- # it { expect(last_command).to finish_its_run_in_time }
17
+ # it { expect(last_command_started).to run_too_long }
18
+ # it { expect(last_command_started).not_to run_too_long }
19
+ # it { expect(last_command_started).to finish_its_run_in_time }
20
20
  # end
21
21
  # RSpec::Matchers.define :run_too_long do
22
22
  RSpec::Matchers.define :have_finished_in_time do
@@ -24,6 +24,8 @@ RSpec::Matchers.define :have_finished_in_time do
24
24
  @old_actual = actual
25
25
  @actual = @old_actual.commandline
26
26
 
27
+ next false unless @old_actual.respond_to? :timed_out?
28
+
27
29
  @announcer ||= Aruba::Announcer.new(
28
30
  self,
29
31
  :stdout => @announce_stdout,
@@ -35,8 +37,6 @@ RSpec::Matchers.define :have_finished_in_time do
35
37
 
36
38
  @old_actual.stop(@announcer) unless @old_actual.stopped?
37
39
 
38
- next false unless @old_actual.respond_to? :timed_out?
39
-
40
40
  @old_actual.timed_out? == false
41
41
  end
42
42
  end
@@ -0,0 +1,46 @@
1
+ # @!method have_output
2
+ # This matchers checks if <command> has created output
3
+ #
4
+ # @return [TrueClass, FalseClass] The result
5
+ #
6
+ # false:
7
+ # * if command has not created output
8
+ # true:
9
+ # * if command created output
10
+ #
11
+ # @example Use matcher
12
+ #
13
+ # RSpec.describe do
14
+ # it { expect(last_command_started).to have_output }
15
+ # end
16
+ RSpec::Matchers.define :have_output do |expected|
17
+ match do |actual|
18
+ @old_actual = actual
19
+
20
+ next false unless @old_actual.respond_to? :output
21
+
22
+ @announcer ||= Aruba::Announcer.new(
23
+ self,
24
+ :stdout => @announce_stdout,
25
+ :stderr => @announce_stderr,
26
+ :dir => @announce_dir,
27
+ :cmd => @announce_cmd,
28
+ :env => @announce_env
29
+ )
30
+
31
+ @old_actual.stop(@announcer) unless @old_actual.stopped?
32
+
33
+ @actual = unescape_text(actual.output.chomp)
34
+ @actual = extract_text(@actual) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences
35
+
36
+ values_match?(expected, @actual)
37
+ end
38
+
39
+ diffable
40
+
41
+ description { "have output: #{description_of expected}" }
42
+ end
43
+
44
+ if RSpec::Expectations::Version::STRING >= '3.0'
45
+ RSpec::Matchers.alias_matcher :a_command_having_output, :have_output
46
+ end
@@ -0,0 +1,42 @@
1
+ # @!method have_output_on_stderr
2
+ # This matchers checks if <command> has created output on stderr
3
+ #
4
+ # @return [TrueClass, FalseClass] The result
5
+ #
6
+ # false:
7
+ # * if command has not created output on stderr
8
+ # true:
9
+ # * if command created output on stderr
10
+ #
11
+ # @example Use matcher
12
+ #
13
+ # RSpec.describe do
14
+ # it { expect(last_command_started).to have_output_on_stderr }
15
+ # end
16
+ RSpec::Matchers.define :have_output_on_stderr do |expected|
17
+ match do |actual|
18
+ @old_actual = actual
19
+
20
+ next false unless @old_actual.respond_to? :stderr
21
+
22
+ @announcer ||= Aruba::Announcer.new(
23
+ self,
24
+ :stdout => @announce_stdout,
25
+ :stderr => @announce_stderr,
26
+ :dir => @announce_dir,
27
+ :cmd => @announce_cmd,
28
+ :env => @announce_env
29
+ )
30
+
31
+ @old_actual.stop(@announcer) unless @old_actual.stopped?
32
+
33
+ @actual = unescape_text(actual.stderr.chomp)
34
+ @actual = extract_text(@actual) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences
35
+
36
+ values_match?(expected, @actual)
37
+ end
38
+
39
+ diffable
40
+
41
+ description { "have output on stderr: #{description_of expected}" }
42
+ end
@@ -0,0 +1,42 @@
1
+ # @!method have_output_on_stdout
2
+ # This matchers checks if <command> has created output on stdout
3
+ #
4
+ # @return [TrueClass, FalseClass] The result
5
+ #
6
+ # false:
7
+ # * if command has not created output on stdout
8
+ # true:
9
+ # * if command created output on stdout
10
+ #
11
+ # @example Use matcher
12
+ #
13
+ # RSpec.describe do
14
+ # it { expect(last_command_started).to have_output_on_stdout }
15
+ # end
16
+ RSpec::Matchers.define :have_output_on_stdout do |expected|
17
+ match do |actual|
18
+ @old_actual = actual
19
+
20
+ next false unless @old_actual.respond_to? :stdout
21
+
22
+ @announcer ||= Aruba::Announcer.new(
23
+ self,
24
+ :stdout => @announce_stdout,
25
+ :stderr => @announce_stderr,
26
+ :dir => @announce_dir,
27
+ :cmd => @announce_cmd,
28
+ :env => @announce_env
29
+ )
30
+
31
+ @old_actual.stop(@announcer) unless @old_actual.stopped?
32
+
33
+ @actual = unescape_text(actual.stdout.chomp)
34
+ @actual = extract_text(@actual) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences
35
+
36
+ values_match?(expected, @actual)
37
+ end
38
+
39
+ diffable
40
+
41
+ description { "have output on stdout: #{description_of expected}" }
42
+ end