ruby-changes:59021
From: Nobuyoshi <ko1@a...>
Date: Sun, 1 Dec 2019 21:56:45 +0900 (JST)
Subject: [ruby-changes:59021] ab516e263c (master): [ruby/spec] Fix failures with LC_ALL=C
https://git.ruby-lang.org/ruby.git/commit/?id=ab516e263c From ab516e263c06fbd755d4805ad529c32b1b8292b5 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Sun, 1 Dec 2019 21:14:58 +0900 Subject: [ruby/spec] Fix failures with LC_ALL=C https://github.com/ruby/spec/commit/51047687c0 https://github.com/ruby/spec/commit/2b87b467cc diff --git a/spec/ruby/core/env/each_pair_spec.rb b/spec/ruby/core/env/each_pair_spec.rb index 01082dd..2d7ed5f 100644 --- a/spec/ruby/core/env/each_pair_spec.rb +++ b/spec/ruby/core/env/each_pair_spec.rb @@ -1,4 +1,4 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/env/each_pair_spec.rb#L1 -require_relative '../../spec_helper' +require_relative 'spec_helper' require_relative 'shared/each' describe "ENV.each_pair" do diff --git a/spec/ruby/core/env/each_spec.rb b/spec/ruby/core/env/each_spec.rb index 06d8be3..d1e06f5 100644 --- a/spec/ruby/core/env/each_spec.rb +++ b/spec/ruby/core/env/each_spec.rb @@ -1,4 +1,4 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/env/each_spec.rb#L1 -require_relative '../../spec_helper' +require_relative 'spec_helper' require_relative 'shared/each' describe "ENV.each" do diff --git a/spec/ruby/core/env/each_value_spec.rb b/spec/ruby/core/env/each_value_spec.rb index 60d9f60..cc3c9eb 100644 --- a/spec/ruby/core/env/each_value_spec.rb +++ b/spec/ruby/core/env/each_value_spec.rb @@ -1,4 +1,4 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/env/each_value_spec.rb#L1 -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 https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/env/each_value_spec.rb#L26 it "uses the locale encoding" do ENV.each_value do |value| - value.encoding.should == Encoding.find('locale') + value.should.be_locale_env end end diff --git a/spec/ruby/core/env/shared/each.rb b/spec/ruby/core/env/shared/each.rb index eb37504..d901b85 100644 --- a/spec/ruby/core/env/shared/each.rb +++ b/spec/ruby/core/env/shared/each.rb @@ -35,8 +35,6 @@ describe :env_each, shared: true do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/env/shared/each.rb#L35 @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 https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/env/shared/each.rb#L46 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 diff --git a/spec/ruby/core/env/shared/to_hash.rb b/spec/ruby/core/env/shared/to_hash.rb index bfa5699..a0d4d7c 100644 --- a/spec/ruby/core/env/shared/to_hash.rb +++ b/spec/ruby/core/env/shared/to_hash.rb @@ -15,11 +15,11 @@ describe :env_to_hash, shared: true do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/env/shared/to_hash.rb#L15 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 diff --git a/spec/ruby/core/env/spec_helper.rb b/spec/ruby/core/env/spec_helper.rb new file mode 100644 index 0000000..470ffa5 --- /dev/null +++ b/spec/ruby/core/env/spec_helper.rb @@ -0,0 +1,26 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/env/spec_helper.rb#L1 +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 diff --git a/spec/ruby/core/env/to_a_spec.rb b/spec/ruby/core/env/to_a_spec.rb index 25441eb..39e3877 100644 --- a/spec/ruby/core/env/to_a_spec.rb +++ b/spec/ruby/core/env/to_a_spec.rb @@ -1,4 +1,4 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/env/to_a_spec.rb#L1 -require_relative '../../spec_helper' +require_relative 'spec_helper' describe "ENV.to_a" do @@ -11,8 +11,8 @@ describe "ENV.to_a" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/env/to_a_spec.rb#L11 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 diff --git a/spec/ruby/core/env/to_h_spec.rb b/spec/ruby/core/env/to_h_spec.rb index 822167a..65cdb59 100644 --- a/spec/ruby/core/env/to_h_spec.rb +++ b/spec/ruby/core/env/to_h_spec.rb @@ -1,4 +1,4 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/env/to_h_spec.rb#L1 -require_relative '../../spec_helper' +require_relative 'spec_helper' require_relative 'shared/to_hash' describe "ENV.to_h" do diff --git a/spec/ruby/core/env/to_hash_spec.rb b/spec/ruby/core/env/to_hash_spec.rb index 4de0e07..306572c 100644 --- a/spec/ruby/core/env/to_hash_spec.rb +++ b/spec/ruby/core/env/to_hash_spec.rb @@ -1,4 +1,4 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/env/to_hash_spec.rb#L1 -require_relative '../../spec_helper' +require_relative 'spec_helper' require_relative 'shared/to_hash' describe "ENV.to_hash" do diff --git a/spec/ruby/core/env/values_spec.rb b/spec/ruby/core/env/values_spec.rb index 919d7ff..71bc877 100644 --- a/spec/ruby/core/env/values_spec.rb +++ b/spec/ruby/core/env/values_spec.rb @@ -1,4 +1,4 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/env/values_spec.rb#L1 -require_relative '../../spec_helper' +require_relative 'spec_helper' describe "ENV.values" do @@ -8,7 +8,7 @@ describe "ENV.values" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/env/values_spec.rb#L8 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 -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/