Skip to content
This repository has been archived by the owner on Nov 30, 2024. It is now read-only.

Commit

Permalink
Ensure and assert tests run with UTF-8 external encoding
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bf4 committed Jan 6, 2015
1 parent a51874c commit aba646a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
8 changes: 4 additions & 4 deletions script/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function run_specs_and_record_done {
fi;

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

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

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

Expand Down Expand Up @@ -112,7 +112,7 @@ function check_documentation_coverage {
}

function check_style_and_lint {
echo "bin/rubucop lib"
echo "bin/rubocop lib"
bin/rubocop lib
}

Expand Down
34 changes: 34 additions & 0 deletions spec/rspec/support/encoded_string_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,40 @@ module RSpec::Support

if String.method_defined?(:encoding)

# see https://github.com/rubyspec/rubyspec/blob/91ce9f6549/core/encoding/find_spec.rb#L57
describe 'Ensure tests are running with utf-8 encoding' do

it 'default_internal' do
if Encoding.default_external == Encoding.find('locale')
expected_encoding = ''
else
expected_encoding = utf8_encoding
end
expect(Encoding.default_internal.to_s).to eq(expected_encoding)
end

it 'default_external' do
expect(Encoding.default_external.to_s).to eq(utf8_encoding)
end

it 'locale' do
skip "Not sure how to determine locale (#{Encoding.find('locale')})"\
"from LC_ALL or on windows"
end

it 'filesystem' do
encoding = Encoding.find('filesystem').to_s
if OS.windows?
skip "Not sure how to tell filesystem encoding is #{encoding}"
expect(encoding).to eq(utf8_encoding)
end
end

it 'current script (file)' do
expect(__ENCODING__.to_s).to eq(utf8_encoding)
end
end

describe '#pick_encoding' do
if String.method_defined?(:encoding)
it "picks a compatible encoding, falling back to default_external" do
Expand Down

0 comments on commit aba646a

Please sign in to comment.