Skip to content

Commit 5104768

Browse files
nobueregon
authored andcommitted
Fix failures with LC_ALL=C
1 parent bf043cd commit 5104768

File tree

10 files changed

+43
-17
lines changed

10 files changed

+43
-17
lines changed

core/env/each_pair_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require_relative '../../spec_helper'
1+
require_relative 'spec_helper'
22
require_relative 'shared/each'
33

44
describe "ENV.each_pair" do

core/env/each_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require_relative '../../spec_helper'
1+
require_relative 'spec_helper'
22
require_relative 'shared/each'
33

44
describe "ENV.each" do

core/env/each_value_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require_relative '../../spec_helper'
1+
require_relative 'spec_helper'
22
require_relative '../enumerable/shared/enumeratorized'
33

44
describe "ENV.each_value" do
@@ -26,7 +26,7 @@
2626

2727
it "uses the locale encoding" do
2828
ENV.each_value do |value|
29-
value.encoding.should == Encoding.find('locale')
29+
value.should.be_locale_env
3030
end
3131
end
3232

core/env/shared/each.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@
3535
@internal = Encoding.default_internal
3636

3737
Encoding.default_external = Encoding::BINARY
38-
39-
@locale_encoding = Encoding.find "locale"
4038
end
4139

4240
after :each do
@@ -48,8 +46,8 @@
4846
Encoding.default_internal = nil
4947

5048
ENV.send(@method) do |key, value|
51-
key.encoding.should equal(@locale_encoding)
52-
value.encoding.should equal(@locale_encoding)
49+
key.should.be_locale_env
50+
value.should.be_locale_env
5351
end
5452
end
5553

core/env/shared/to_hash.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
end
1616

1717
it "uses the locale encoding for keys" do
18-
ENV.send(@method).keys.all? {|k| k.encoding == Encoding.find('locale') }.should be_true
18+
ENV.send(@method).keys.each {|k| k.should.be_locale_env }
1919
end
2020

2121
it "uses the locale encoding for values" do
22-
ENV.send(@method).values.all? {|v| v.encoding == Encoding.find('locale') }.should be_true
22+
ENV.send(@method).values.each {|k| k.should.be_locale_env }
2323
end
2424

2525
it "duplicates the ENV when converting to a Hash" do

core/env/spec_helper.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
require_relative '../../spec_helper'
2+
3+
class BeLocaleEnvEncodingString
4+
def initialize(name = 'locale')
5+
encoding = Encoding.find(name)
6+
@encodings = (encoding = Encoding::US_ASCII) ?
7+
[encoding, Encoding::ASCII_8BIT] : [encoding]
8+
end
9+
10+
def matches?(actual)
11+
@actual = actual = actual.encoding
12+
@encodings.include?(actual)
13+
end
14+
15+
def failure_message
16+
["Expected #{@actual} to be #{@encodings.join(' or ')}"]
17+
end
18+
19+
def negative_failure_message
20+
["Expected #{@actual} not to be #{@encodings.join(' or ')}"]
21+
end
22+
end
23+
24+
class String
25+
def be_locale_env(expected = 'locale')
26+
BeLocaleEnvEncodingString.new(expected)
27+
end
28+
end

core/env/to_a_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require_relative '../../spec_helper'
1+
require_relative 'spec_helper'
22

33
describe "ENV.to_a" do
44

@@ -11,8 +11,8 @@
1111

1212
it "returns the entries in the locale encoding" do
1313
ENV.to_a.each do |key, value|
14-
key.encoding.should == Encoding.find('locale')
15-
value.encoding.should == Encoding.find('locale')
14+
key.should.be_locale_env
15+
value.should.be_locale_env
1616
end
1717
end
1818
end

core/env/to_h_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require_relative '../../spec_helper'
1+
require_relative 'spec_helper'
22
require_relative 'shared/to_hash'
33

44
describe "ENV.to_h" do

core/env/to_hash_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require_relative '../../spec_helper'
1+
require_relative 'spec_helper'
22
require_relative 'shared/to_hash'
33

44
describe "ENV.to_hash" do

core/env/values_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require_relative '../../spec_helper'
1+
require_relative 'spec_helper'
22

33
describe "ENV.values" do
44

@@ -8,7 +8,7 @@
88

99
it "uses the locale encoding" do
1010
ENV.values.each do |value|
11-
value.encoding.should == Encoding.find('locale')
11+
value.should.be_locale_env
1212
end
1313
end
1414
end

0 commit comments

Comments
 (0)