@@ -56,6 +56,7 @@ def to_str
5656
5757Aruba . configure do |config |
5858 config . exit_timeout = 60
59+ config . remove_ansi_escape_sequences = false
5960end
6061
6162Before do
@@ -82,4 +83,105 @@ def to_str
8283
8384After ( '@client_failures' ) do
8485 @cluster . restart
85- end
86+ end
87+
88+ ##############################################################################################################
89+ # The following matchers and aruba SpawnProcess monkey-patch cause aruba to write command output to file
90+ # with binmode to avoid encoding / translation issues. The matchers take the "binary" output and re-interpret
91+ # as utf8. This works around (resolves?) a behavior difference in jruby9k where cukes were failing when output
92+ # included non-ascii characters. RUBY-167
93+ ##############################################################################################################
94+
95+ RSpec ::Matchers . define :include_output_string do |expected |
96+ match do |actual |
97+ actual . force_encoding ( "UTF-8" )
98+ @expected = Regexp . new ( Regexp . escape ( sanitize_text ( expected . to_s ) ) , Regexp ::MULTILINE )
99+ @actual = sanitize_text ( actual )
100+
101+ values_match? @expected , @actual
102+ end
103+
104+ diffable
105+
106+ description { "string includes: #{ description_of expected } " }
107+ end
108+
109+ RSpec ::Matchers . define :match_output_string do |expected |
110+ match do |actual |
111+ actual . force_encoding ( "UTF-8" )
112+ @expected = Regexp . new ( unescape_text ( expected ) , Regexp ::MULTILINE )
113+ @actual = sanitize_text ( actual )
114+
115+ values_match? @expected , @actual
116+ end
117+
118+ diffable
119+
120+ description { "output string matches: #{ description_of expected } " }
121+ end
122+
123+ RSpec ::Matchers . define :output_string_eq do |expected |
124+ match do |actual |
125+ actual . force_encoding ( "UTF-8" )
126+ @expected = sanitize_text ( expected . to_s )
127+ @actual = sanitize_text ( actual . to_s )
128+
129+ values_match? @expected , @actual
130+ end
131+
132+ diffable
133+
134+ description { "output string is eq: #{ description_of expected } " }
135+ end
136+
137+ module Aruba
138+ module Processes
139+ class SpawnProcess
140+ def start
141+ # rubocop:disable Metrics/LineLength
142+ fail CommandAlreadyStartedError , %(Command "#{ commandline } " has already been started. Please `#stop` the command first and `#start` it again. Alternatively use `#restart`.\n #{ caller . join ( "\n " ) } ) if started?
143+ # rubocop:enable Metrics/LineLength
144+
145+ @started = true
146+
147+ @process = ChildProcess . build ( *[ command_string . to_a , arguments ] . flatten )
148+ @stdout_file = Tempfile . new ( 'aruba-stdout-' )
149+ @stderr_file = Tempfile . new ( 'aruba-stderr-' )
150+
151+
152+ @stdout_file . sync = true
153+ @stderr_file . sync = true
154+
155+ @stdout_file . binmode
156+ @stderr_file . binmode
157+
158+ @exit_status = nil
159+ @duplex = true
160+
161+ before_run
162+
163+ @process . leader = true
164+ @process . io . stdout = @stdout_file
165+ @process . io . stderr = @stderr_file
166+ @process . duplex = @duplex
167+ @process . cwd = @working_directory
168+
169+ @process . environment . update ( environment )
170+
171+ begin
172+ Aruba . platform . with_environment ( environment ) do
173+ @process . start
174+ sleep startup_wait_time
175+ end
176+ rescue ChildProcess ::LaunchError => e
177+ raise LaunchError , "It tried to start #{ cmd } . " + e . message
178+ end
179+
180+ after_run
181+
182+ yield self if block_given?
183+ end
184+ end
185+ end
186+ end
187+
0 commit comments