Skip to content

Commit db2c3a4

Browse files
committed
Ensure and assert tests run with UTF-8 external encoding
Some tests fail if the external/locale/filesystem encoding is ISO-8859-1 Rather than debugging environmental issues, we can control them per Ruby docs by running our CI specs via `ruby -E UTF-8 -S $spec_command`. See https://github.com/ruby/ruby/blob/ca24e581ba/encoding.c#L1674 Alternatively, we could control them via the environmental variables LANG, LC_ALL, LC_CTYPE in the .travis.yml or appveyor.yml with e.g. env: - LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 (which is the default on Travis) ( http://docs.travis-ci.com/user/ci-environment/#Environment-variables ) but I'm not sure how windows-compatible that is and it appears more reliable to be explicit in the runner, so that running script/run_build uses the correct encoding, and one doesn't need to, for example, gem install wwtd && wwtd --local to get the CI behavior Also, see see https://github.com/rubyspec/rubyspec/blob/91ce9f6549/core/encoding/find_spec.rb#L57
1 parent 8aa73ae commit db2c3a4

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

script/functions.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function run_specs_and_record_done {
2626
fi;
2727

2828
echo "${PWD}/bin/rspec"
29-
$rspec_bin spec --backtrace --format progress --profile --format progress --out $SPECS_HAVE_RUN_FILE
29+
ruby -E UTF-8:UTF-8 -S $rspec_bin spec --backtrace --format progress --profile --format progress --out $SPECS_HAVE_RUN_FILE
3030
}
3131

3232
function run_cukes {
@@ -50,7 +50,7 @@ function run_cukes {
5050
# and PATH for those that are using `rspec` or `rake`.
5151
RUBYOPT="-I${PWD}/../bundle -rbundler/setup" \
5252
PATH="${PWD}/bin:$PATH" \
53-
bin/cucumber --strict
53+
ruby -E UTF-8:UTF-8 -S bin/cucumber --strict
5454
fi
5555
fi
5656
}
@@ -59,7 +59,7 @@ function run_specs_one_by_one {
5959
echo "Running each spec file, one-by-one..."
6060

6161
for file in `find spec -iname '*_spec.rb'`; do
62-
bin/rspec $file -b --format progress
62+
ruby -E UTF-8:UTF-8 -S bin/rspec $file -b --format progress
6363
done
6464
}
6565

@@ -112,7 +112,7 @@ function check_documentation_coverage {
112112
}
113113

114114
function check_style_and_lint {
115-
echo "bin/rubucop lib"
115+
echo "bin/rubocop lib"
116116
bin/rubocop lib
117117
}
118118

spec/rspec/support/encoded_string_spec.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,40 @@ module RSpec::Support
1616

1717
if String.method_defined?(:encoding)
1818

19+
# see https://github.com/rubyspec/rubyspec/blob/91ce9f6549/core/encoding/find_spec.rb#L57
20+
describe 'Ensure tests are running with utf-8 encoding' do
21+
22+
it 'default_internal' do
23+
if Encoding.default_external == Encoding.find('locale')
24+
expected_encoding = ''
25+
else
26+
expected_encoding = utf8_encoding
27+
end
28+
expect(Encoding.default_internal.to_s).to eq(expected_encoding)
29+
end
30+
31+
it 'default_external' do
32+
expect(Encoding.default_external.to_s).to eq(utf8_encoding)
33+
end
34+
35+
it 'locale' do
36+
skip "Not sure how to determine locale (#{Encoding.find('locale')})"\
37+
"from LC_ALL or on windows"
38+
end
39+
40+
it 'filesystem' do
41+
encoding = Encoding.find('filesystem').to_s
42+
if OS.windows?
43+
skip "Not sure how to tell filesystem encoding is #{encoding}"
44+
expect(encoding).to eq(utf8_encoding)
45+
end
46+
end
47+
48+
it 'current script (file)' do
49+
expect(__ENCODING__.to_s).to eq(utf8_encoding)
50+
end
51+
end
52+
1953
describe '#pick_encoding' do
2054
if String.method_defined?(:encoding)
2155
it "picks a compatible encoding, falling back to default_external" do

0 commit comments

Comments
 (0)