Skip to content

Commit f7ebc74

Browse files
committed
RUBY-163 - Cucumber tests fail in JRuby9k after encountering non-English characters.
1 parent 809b7ad commit f7ebc74

File tree

2 files changed

+104
-5
lines changed

2 files changed

+104
-5
lines changed

build.yaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@ schedules:
33
schedule: per_commit
44
matrix:
55
exclude:
6-
- ruby: ['2.2', 'jruby9k']
6+
- ruby: ['2.2']
77
- cassandra: ['2.0', '2.2', '3.0']
88
nightly:
99
schedule: nightly
1010
branches:
1111
include: [master]
12-
matrix:
13-
exclude:
14-
- ruby: jruby9k
1512

1613
ruby:
1714
- 2.2

features/support/env.rb

Lines changed: 103 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def to_str
5656

5757
Aruba.configure do |config|
5858
config.exit_timeout = 60
59+
config.remove_ansi_escape_sequences = false
5960
end
6061

6162
Before do
@@ -82,4 +83,105 @@ def to_str
8283

8384
After('@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

Comments
 (0)