summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--spec/ruby/.rubocop.yml25
-rw-r--r--spec/ruby/.rubocop_todo.yml42
-rw-r--r--spec/ruby/language/block_spec.rb2
-rw-r--r--spec/ruby/language/method_spec.rb13
-rw-r--r--spec/ruby/optional/capi/README2
-rw-r--r--spec/ruby/optional/capi/spec_helper.rb23
6 files changed, 51 insertions, 56 deletions
diff --git a/spec/ruby/.rubocop.yml b/spec/ruby/.rubocop.yml
index c544fa5fd08..58529f15b29 100644
--- a/spec/ruby/.rubocop.yml
+++ b/spec/ruby/.rubocop.yml
@@ -37,6 +37,9 @@ Lint/LiteralAsCondition:
Lint/UnneededRequireStatement:
Enabled: false
+Lint/UnneededSplatExpansion:
+ Enabled: false
+
Lint/UnifiedInteger:
Enabled: false
@@ -52,7 +55,6 @@ Lint/UselessAssignment:
Lint/UselessComparison:
Enabled: false
-# The cop registers too many false positives to `.should == something`
Lint/Void:
Enabled: false
@@ -65,11 +67,32 @@ Lint/EmptyWhen:
- language/case_spec.rb
- optional/capi/spec_helper.rb
+Lint/FormatParameterMismatch:
+ Exclude:
+ - 'core/kernel/shared/sprintf.rb'
+ - 'core/string/modulo_spec.rb'
+
Lint/NestedMethodDefinition:
Exclude:
- language/def_spec.rb
- language/fixtures/def.rb
+Lint/UnreachableCode:
+ Exclude:
+ - 'core/enumerator/lazy/fixtures/classes.rb'
+ - 'core/kernel/catch_spec.rb'
+ - 'core/kernel/throw_spec.rb'
+ - 'language/break_spec.rb'
+ - 'language/fixtures/break.rb'
+ - 'language/fixtures/break_lambda_toplevel.rb'
+ - 'language/fixtures/break_lambda_toplevel_block.rb'
+ - 'language/fixtures/break_lambda_toplevel_method.rb'
+ - 'language/fixtures/return.rb'
+ - 'language/next_spec.rb'
+ - 'language/return_spec.rb'
+ - 'optional/capi/kernel_spec.rb'
+ - 'shared/kernel/raise.rb'
+
Lint/UriRegexp:
Exclude:
- 'library/uri/regexp_spec.rb'
diff --git a/spec/ruby/.rubocop_todo.yml b/spec/ruby/.rubocop_todo.yml
index 289471dde64..181e4003a40 100644
--- a/spec/ruby/.rubocop_todo.yml
+++ b/spec/ruby/.rubocop_todo.yml
@@ -32,12 +32,6 @@ Lint/FloatOutOfRange:
Exclude:
- 'core/string/modulo_spec.rb'
-# Offense count: 107
-Lint/FormatParameterMismatch:
- Exclude:
- - 'core/kernel/shared/sprintf.rb'
- - 'core/string/modulo_spec.rb'
-
# Offense count: 29
Lint/HandleExceptions:
Enabled: false
@@ -148,42 +142,6 @@ Lint/UnderscorePrefixedVariableName:
- 'core/io/popen_spec.rb'
- 'language/block_spec.rb'
-# Offense count: 90
-# Cop supports --auto-correct.
-Lint/UnneededSplatExpansion:
- Exclude:
- - 'core/array/element_reference_spec.rb'
- - 'core/enumerable/fixtures/classes.rb'
- - 'core/enumerable/max_by_spec.rb'
- - 'core/enumerable/min_by_spec.rb'
- - 'core/enumerable/minmax_by_spec.rb'
- - 'core/enumerator/lazy/fixtures/classes.rb'
- - 'core/file/basename_spec.rb'
- - 'core/kernel/p_spec.rb'
- - 'language/array_spec.rb'
- - 'language/break_spec.rb'
- - 'language/case_spec.rb'
- - 'language/next_spec.rb'
- - 'language/send_spec.rb'
- - 'language/variables_spec.rb'
-
-# Offense count: 54
-Lint/UnreachableCode:
- Exclude:
- - 'core/enumerator/lazy/fixtures/classes.rb'
- - 'core/kernel/catch_spec.rb'
- - 'core/kernel/throw_spec.rb'
- - 'language/break_spec.rb'
- - 'language/fixtures/break.rb'
- - 'language/fixtures/break_lambda_toplevel.rb'
- - 'language/fixtures/break_lambda_toplevel_block.rb'
- - 'language/fixtures/break_lambda_toplevel_method.rb'
- - 'language/fixtures/return.rb'
- - 'language/next_spec.rb'
- - 'language/return_spec.rb'
- - 'optional/capi/kernel_spec.rb'
- - 'shared/kernel/raise.rb'
-
# Offense count: 7
# Configuration parameters: ContextCreatingMethods, MethodCreatingMethods.
Lint/UselessAccessModifier:
diff --git a/spec/ruby/language/block_spec.rb b/spec/ruby/language/block_spec.rb
index f674c1d0e41..e35b0ed767e 100644
--- a/spec/ruby/language/block_spec.rb
+++ b/spec/ruby/language/block_spec.rb
@@ -57,7 +57,7 @@ describe "A block yielded a single" do
result.should == [{"a" => 1, "b" => 2}, {}]
end
- describe("when non-symbol keys are in a keyword arguments Hash") do
+ describe "when non-symbol keys are in a keyword arguments Hash" do
ruby_version_is ""..."2.6" do
it "separates non-symbol keys and symbol keys" do
result = m(["a" => 10, b: 2]) { |a=nil, **b| [a, b] }
diff --git a/spec/ruby/language/method_spec.rb b/spec/ruby/language/method_spec.rb
index 96abbc649d4..54f0c6ccf8c 100644
--- a/spec/ruby/language/method_spec.rb
+++ b/spec/ruby/language/method_spec.rb
@@ -512,6 +512,15 @@ describe "A method" do
end
evaluate <<-ruby do
+ def m() end
+ ruby
+
+ m().should be_nil
+ m(*[]).should be_nil
+ m(**{}).should be_nil
+ end
+
+ evaluate <<-ruby do
def m(*) end
ruby
@@ -527,6 +536,8 @@ describe "A method" do
m().should == []
m(1).should == [1]
m(1, 2, 3).should == [1, 2, 3]
+ m(*[]).should == []
+ m(**{}).should == []
end
evaluate <<-ruby do
@@ -561,6 +572,8 @@ describe "A method" do
m().should == {}
m(a: 1, b: 2).should == { a: 1, b: 2 }
+ m(*[]).should == {}
+ m(**{}).should == {}
lambda { m(2) }.should raise_error(ArgumentError)
end
diff --git a/spec/ruby/optional/capi/README b/spec/ruby/optional/capi/README
index efbfb09dcb4..57b0c51f01a 100644
--- a/spec/ruby/optional/capi/README
+++ b/spec/ruby/optional/capi/README
@@ -13,4 +13,4 @@ specs:
5. Name the C functions 'array_spec_rb_ary_new'.
6. Wrap the code in the optional/capi/ext/array_spec.c in
'#ifdef HAVE_RB_ARY_NEW'
-6. Attach the C function to the class using the name 'rb_ary_new'
+7. Attach the C function to the class using the name 'rb_ary_new'
diff --git a/spec/ruby/optional/capi/spec_helper.rb b/spec/ruby/optional/capi/spec_helper.rb
index d5ac1408a1d..e5d1d54daad 100644
--- a/spec/ruby/optional/capi/spec_helper.rb
+++ b/spec/ruby/optional/capi/spec_helper.rb
@@ -1,4 +1,4 @@
-require_relative '../../spec_helper'
+# Require the main spec_helper.rb at the end to let `ruby ...spec.rb` work
# MRI magic to use built but not installed ruby
$extmk = false
@@ -6,13 +6,9 @@ $extmk = false
require 'rbconfig'
OBJDIR ||= File.expand_path("../../../ext/#{RUBY_ENGINE}/#{RUBY_VERSION}", __FILE__)
-mkdir_p(OBJDIR)
-
-def extension_path
- File.expand_path("../ext", __FILE__)
-end
def object_path
+ mkdir_p(OBJDIR)
OBJDIR
end
@@ -20,6 +16,7 @@ def compile_extension(name)
debug = false
run_mkmf_in_process = RUBY_ENGINE == 'truffleruby'
+ ext_dir = File.expand_path("../ext", __FILE__)
ext = "#{name}_spec"
lib = "#{object_path}/#{ext}.#{RbConfig::CONFIG['DLEXT']}"
ruby_header = "#{RbConfig::CONFIG['rubyhdrdir']}/ruby.h"
@@ -31,8 +28,8 @@ def compile_extension(name)
# not found, then compile
else
case # if lib is older than headers, source or libruby, then recompile
- when mtime <= File.mtime("#{extension_path}/rubyspec.h")
- when mtime <= File.mtime("#{extension_path}/#{ext}.c")
+ when mtime <= File.mtime("#{ext_dir}/rubyspec.h")
+ when mtime <= File.mtime("#{ext_dir}/#{ext}.c")
when mtime <= File.mtime(ruby_header)
when libruby_so && mtime <= File.mtime("#{RbConfig::CONFIG['libdir']}/#{libruby_so}")
else
@@ -45,7 +42,7 @@ def compile_extension(name)
Dir.mkdir(tmpdir)
begin
["rubyspec.h", "#{ext}.c"].each do |file|
- cp "#{extension_path}/#{file}", "#{tmpdir}/#{file}"
+ cp "#{ext_dir}/#{file}", "#{tmpdir}/#{file}"
end
Dir.chdir(tmpdir) do
@@ -108,8 +105,8 @@ end
def load_extension(name)
require compile_extension(name)
-rescue LoadError
- if %r{/usr/sbin/execerror ruby "\(ld 3 1 main ([/a-zA-Z0-9_\-.]+_spec\.so)"} =~ $!.message
+rescue LoadError => e
+ if %r{/usr/sbin/execerror ruby "\(ld 3 1 main ([/a-zA-Z0-9_\-.]+_spec\.so)"} =~ e.message
system('/usr/sbin/execerror', "#{RbConfig::CONFIG["bindir"]}/ruby", "(ld 3 1 main #{$1}")
end
raise
@@ -117,3 +114,7 @@ end
# Constants
CAPI_SIZEOF_LONG = [0].pack('l!').size
+
+# Require the main spec_helper.rb only here so load_extension() is defined
+# when running specs with `ruby ...spec.rb`
+require_relative '../../spec_helper'