1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/spec] Fix failures with LC_ALL=C

https://github.com/ruby/spec/commit/51047687c0
https://github.com/ruby/spec/commit/2b87b467cc
This commit is contained in:
Nobuyoshi Nakada 2019-12-01 21:14:58 +09:00
parent 4e03a7298b
commit ab516e263c
No known key found for this signature in database
GPG key ID: 4BC7D6DF58D8DF60
10 changed files with 41 additions and 17 deletions

View file

@ -1,4 +1,4 @@
require_relative '../../spec_helper'
require_relative 'spec_helper'
require_relative 'shared/each'
describe "ENV.each_pair" do

View file

@ -1,4 +1,4 @@
require_relative '../../spec_helper'
require_relative 'spec_helper'
require_relative 'shared/each'
describe "ENV.each" do

View file

@ -1,4 +1,4 @@
require_relative '../../spec_helper'
require_relative 'spec_helper'
require_relative '../enumerable/shared/enumeratorized'
describe "ENV.each_value" do
@ -26,7 +26,7 @@ describe "ENV.each_value" do
it "uses the locale encoding" do
ENV.each_value do |value|
value.encoding.should == Encoding.find('locale')
value.should.be_locale_env
end
end

View file

@ -35,8 +35,6 @@ describe :env_each, shared: true do
@internal = Encoding.default_internal
Encoding.default_external = Encoding::BINARY
@locale_encoding = Encoding.find "locale"
end
after :each do
@ -48,8 +46,8 @@ describe :env_each, shared: true do
Encoding.default_internal = nil
ENV.send(@method) do |key, value|
key.encoding.should equal(@locale_encoding)
value.encoding.should equal(@locale_encoding)
key.should.be_locale_env
value.should.be_locale_env
end
end

View file

@ -15,11 +15,11 @@ describe :env_to_hash, shared: true do
end
it "uses the locale encoding for keys" do
ENV.send(@method).keys.all? {|k| k.encoding == Encoding.find('locale') }.should be_true
ENV.send(@method).keys.each {|k| k.should.be_locale_env }
end
it "uses the locale encoding for values" do
ENV.send(@method).values.all? {|v| v.encoding == Encoding.find('locale') }.should be_true
ENV.send(@method).values.each {|k| k.should.be_locale_env }
end
it "duplicates the ENV when converting to a Hash" do

26
spec/ruby/core/env/spec_helper.rb vendored Normal file
View file

@ -0,0 +1,26 @@
require_relative '../../spec_helper'
locale_env_matcher = Class.new do
def initialize(name = 'locale')
encoding = Encoding.find(name)
@encodings = (encoding = Encoding::US_ASCII) ?
[encoding, Encoding::ASCII_8BIT] : [encoding]
end
def matches?(actual)
@actual = actual = actual.encoding
@encodings.include?(actual)
end
def failure_message
["Expected #{@actual} to be #{@encodings.join(' or ')}"]
end
def negative_failure_message
["Expected #{@actual} not to be #{@encodings.join(' or ')}"]
end
end
String.__send__(:define_method, :be_locale_env) do |expected = 'locale'|
locale_env_matcher.new(expected)
end

View file

@ -1,4 +1,4 @@
require_relative '../../spec_helper'
require_relative 'spec_helper'
describe "ENV.to_a" do
@ -11,8 +11,8 @@ describe "ENV.to_a" do
it "returns the entries in the locale encoding" do
ENV.to_a.each do |key, value|
key.encoding.should == Encoding.find('locale')
value.encoding.should == Encoding.find('locale')
key.should.be_locale_env
value.should.be_locale_env
end
end
end

View file

@ -1,4 +1,4 @@
require_relative '../../spec_helper'
require_relative 'spec_helper'
require_relative 'shared/to_hash'
describe "ENV.to_h" do

View file

@ -1,4 +1,4 @@
require_relative '../../spec_helper'
require_relative 'spec_helper'
require_relative 'shared/to_hash'
describe "ENV.to_hash" do

View file

@ -1,4 +1,4 @@
require_relative '../../spec_helper'
require_relative 'spec_helper'
describe "ENV.values" do
@ -8,7 +8,7 @@ describe "ENV.values" do
it "uses the locale encoding" do
ENV.values.each do |value|
value.encoding.should == Encoding.find('locale')
value.should.be_locale_env
end
end
end