Skip to content

Commit 7bc3159

Browse files
committed
Fix specs for Env#keys and Env#each_key on Windows
1 parent 6c0826b commit 7bc3159

3 files changed

Lines changed: 51 additions & 13 deletions

File tree

core/env/each_key_spec.rb

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
require_relative '../../spec_helper'
22
require_relative '../enumerable/shared/enumeratorized'
3-
require_relative 'fixtures/common'
43

54
describe "ENV.each_key" do
65

@@ -25,9 +24,30 @@
2524
enum.to_a.should == ENV.keys
2625
end
2726

28-
it "returns keys in the locale encoding" do
29-
ENV.each_key do |key|
30-
key.encoding.should == ENVSpecs.encoding
27+
platform_is_not :windows do
28+
it "returns keys in the locale encoding" do
29+
ENV.each_key do |key|
30+
key.encoding.should == Encoding.find('locale')
31+
end
32+
end
33+
end
34+
35+
# https://bugs.ruby-lang.org/issues/20958
36+
platform_is :windows do
37+
ruby_version_is ""..."4.1" do
38+
it "returns keys in the locale encoding" do
39+
ENV.each_key do |key|
40+
key.encoding.should == Encoding.find('locale')
41+
end
42+
end
43+
end
44+
45+
ruby_version_is "4.1" do
46+
it "returns the keys in UTF-8" do
47+
ENV.each_key do |key|
48+
key.encoding.should == Encoding::UTF_8
49+
end
50+
end
3151
end
3252
end
3353

core/env/fixtures/common.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
module ENVSpecs
22
def self.encoding
3-
locale = Encoding.find('locale')
4-
if ruby_version_is '3' and platform_is :windows
5-
locale = Encoding::UTF_8
6-
end
7-
locale
3+
return Encoding::UTF_8 if platform_is :windows
4+
5+
Encoding.find('locale')
86
end
97
end

core/env/keys_spec.rb

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,35 @@
11
require_relative '../../spec_helper'
2-
require_relative 'fixtures/common'
32

43
describe "ENV.keys" do
54

65
it "returns an array of the keys" do
76
ENV.keys.should == ENV.to_hash.keys
87
end
98

10-
it "returns the keys in the locale encoding" do
11-
ENV.keys.each do |key|
12-
key.encoding.should == ENVSpecs.encoding
9+
platform_is_not :windows do
10+
it "returns the keys in the locale encoding" do
11+
ENV.keys.each do |key|
12+
key.encoding.should == Encoding.find('locale')
13+
end
14+
end
15+
end
16+
17+
# https://bugs.ruby-lang.org/issues/20958
18+
platform_is :windows do
19+
ruby_version_is ""..."4.1" do
20+
it "returns the keys in the locale encoding" do
21+
ENV.keys.each do |key|
22+
key.encoding.should == Encoding.find('locale')
23+
end
24+
end
25+
end
26+
27+
ruby_version_is "4.1" do
28+
it "returns the keys in UTF-8" do
29+
ENV.keys.each do |key|
30+
key.encoding.should == Encoding::UTF_8
31+
end
32+
end
1333
end
1434
end
1535
end

0 commit comments

Comments
 (0)