mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Update to ruby/spec@6f38a82
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63293 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
b864bd05bf
commit
4fbb9aa3cb
145 changed files with 2847 additions and 2596 deletions
39
spec/ruby/core/exception/backtrace_locations_spec.rb
Normal file
39
spec/ruby/core/exception/backtrace_locations_spec.rb
Normal file
|
@ -0,0 +1,39 @@
|
|||
require_relative '../../spec_helper'
|
||||
require_relative 'fixtures/common'
|
||||
|
||||
describe "Exception#backtrace_locations" do
|
||||
before :each do
|
||||
@backtrace = ExceptionSpecs::Backtrace.backtrace_locations
|
||||
end
|
||||
|
||||
it "returns nil if no backtrace was set" do
|
||||
Exception.new.backtrace_locations.should be_nil
|
||||
end
|
||||
|
||||
it "returns an Array" do
|
||||
@backtrace.should be_an_instance_of(Array)
|
||||
end
|
||||
|
||||
it "sets each element to a Thread::Backtrace::Location" do
|
||||
@backtrace.each {|l| l.should be_an_instance_of(Thread::Backtrace::Location)}
|
||||
end
|
||||
|
||||
it "produces a backtrace for an exception captured using $!" do
|
||||
exception = begin
|
||||
raise
|
||||
rescue RuntimeError
|
||||
$!
|
||||
end
|
||||
|
||||
exception.backtrace_locations.first.path.should =~ /backtrace_locations_spec/
|
||||
end
|
||||
|
||||
it "returns an Array that can be updated" do
|
||||
begin
|
||||
raise
|
||||
rescue RuntimeError => e
|
||||
e.backtrace_locations.unshift "backtrace first"
|
||||
e.backtrace_locations[0].should == "backtrace first"
|
||||
end
|
||||
end
|
||||
end
|
|
@ -4,11 +4,19 @@ module ExceptionSpecs
|
|||
class Backtrace
|
||||
def self.backtrace
|
||||
begin
|
||||
raise # Do not move this line or update backtrace_spec.rb
|
||||
raise # If you move this line, update backtrace_spec.rb
|
||||
rescue RuntimeError => e
|
||||
e.backtrace
|
||||
end
|
||||
end
|
||||
|
||||
def self.backtrace_locations
|
||||
begin
|
||||
raise
|
||||
rescue RuntimeError => e
|
||||
e.backtrace_locations
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class UnExceptional < Exception
|
||||
|
|
38
spec/ruby/core/exception/full_message_spec.rb
Normal file
38
spec/ruby/core/exception/full_message_spec.rb
Normal file
|
@ -0,0 +1,38 @@
|
|||
require_relative '../../spec_helper'
|
||||
|
||||
ruby_version_is "2.5" do
|
||||
describe "Exception#full_message" do
|
||||
it "returns formatted string of exception using the same format that is used to print an uncaught exceptions to stderr" do
|
||||
e = RuntimeError.new("Some runtime error")
|
||||
e.set_backtrace(["a.rb:1", "b.rb:2"])
|
||||
|
||||
full_message = e.full_message
|
||||
full_message.should include "RuntimeError"
|
||||
full_message.should include "Some runtime error"
|
||||
full_message.should include "a.rb:1"
|
||||
full_message.should include "b.rb:2"
|
||||
end
|
||||
|
||||
ruby_version_is "2.5.1" do
|
||||
it "supports :highlight option and adds escape sequences to highlight some strings" do
|
||||
e = RuntimeError.new("Some runtime error")
|
||||
|
||||
full_message = e.full_message(highlight: true, order: :bottom)
|
||||
full_message.should include "\e[1mTraceback\e[m (most recent call last)"
|
||||
full_message.should include "\e[1mSome runtime error (\e[1;4mRuntimeError\e[m\e[1m)"
|
||||
|
||||
full_message = e.full_message(highlight: false, order: :bottom)
|
||||
full_message.should include "Traceback (most recent call last)"
|
||||
full_message.should include "Some runtime error (RuntimeError)"
|
||||
end
|
||||
|
||||
it "supports :order option and places the error message and the backtrace at the top or the bottom" do
|
||||
e = RuntimeError.new("Some runtime error")
|
||||
e.set_backtrace(["a.rb:1", "b.rb:2"])
|
||||
|
||||
e.full_message(order: :top, highlight: false).should =~ /a.rb:1.*b.rb:2/m
|
||||
e.full_message(order: :bottom, highlight: false).should =~ /b.rb:2.*a.rb:1/m
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -27,35 +27,19 @@ describe "NameError#name" do
|
|||
}.should raise_error(NameError) { |e| e.name.should == :@@doesnt_exist }
|
||||
end
|
||||
|
||||
ruby_version_is ""..."2.3" do
|
||||
it "always returns a symbol when a NameError is raised from #instance_variable_get" do
|
||||
-> {
|
||||
Object.new.instance_variable_get("invalid_ivar_name")
|
||||
}.should raise_error(NameError) { |e| e.name.should == :invalid_ivar_name }
|
||||
end
|
||||
it "returns the first argument passed to the method when a NameError is raised from #instance_variable_get" do
|
||||
invalid_ivar_name = "invalid_ivar_name"
|
||||
|
||||
it "always returns a symbol when a NameError is raised from #class_variable_get" do
|
||||
-> {
|
||||
Object.class_variable_get("invalid_cvar_name")
|
||||
}.should raise_error(NameError) { |e| e.name.should == :invalid_cvar_name }
|
||||
end
|
||||
-> {
|
||||
Object.new.instance_variable_get(invalid_ivar_name)
|
||||
}.should raise_error(NameError) {|e| e.name.should equal(invalid_ivar_name) }
|
||||
end
|
||||
|
||||
ruby_version_is "2.3" do
|
||||
it "returns the first argument passed to the method when a NameError is raised from #instance_variable_get" do
|
||||
invalid_ivar_name = "invalid_ivar_name"
|
||||
it "returns the first argument passed to the method when a NameError is raised from #class_variable_get" do
|
||||
invalid_cvar_name = "invalid_cvar_name"
|
||||
|
||||
-> {
|
||||
Object.new.instance_variable_get(invalid_ivar_name)
|
||||
}.should raise_error(NameError) {|e| e.name.should equal(invalid_ivar_name) }
|
||||
end
|
||||
|
||||
it "returns the first argument passed to the method when a NameError is raised from #class_variable_get" do
|
||||
invalid_cvar_name = "invalid_cvar_name"
|
||||
|
||||
-> {
|
||||
Object.class_variable_get(invalid_cvar_name)
|
||||
}.should raise_error(NameError) {|e| e.name.should equal(invalid_cvar_name) }
|
||||
end
|
||||
-> {
|
||||
Object.class_variable_get(invalid_cvar_name)
|
||||
}.should raise_error(NameError) {|e| e.name.should equal(invalid_cvar_name) }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,62 +1,60 @@
|
|||
require_relative '../../spec_helper'
|
||||
require_relative 'fixtures/common'
|
||||
|
||||
ruby_version_is "2.3" do
|
||||
describe "NameError#receiver" do
|
||||
class ::ReceiverClass
|
||||
def call_undefined_class_variable; @@doesnt_exist end
|
||||
end
|
||||
describe "NameError#receiver" do
|
||||
class ::ReceiverClass
|
||||
def call_undefined_class_variable; @@doesnt_exist end
|
||||
end
|
||||
|
||||
it "returns the object that raised the exception" do
|
||||
receiver = Object.new
|
||||
it "returns the object that raised the exception" do
|
||||
receiver = Object.new
|
||||
|
||||
-> {
|
||||
receiver.doesnt_exist
|
||||
}.should raise_error(NameError) {|e| e.receiver.should equal(receiver) }
|
||||
end
|
||||
|
||||
it "returns the Object class when an undefined constant is called without namespace" do
|
||||
-> {
|
||||
DoesntExist
|
||||
}.should raise_error(NameError) {|e| e.receiver.should equal(Object) }
|
||||
end
|
||||
|
||||
it "returns a class when an undefined constant is called" do
|
||||
-> {
|
||||
NameErrorSpecs::ReceiverClass::DoesntExist
|
||||
}.should raise_error(NameError) {|e| e.receiver.should equal(NameErrorSpecs::ReceiverClass) }
|
||||
end
|
||||
|
||||
it "returns the Object class when an undefined class variable is called" do
|
||||
-> {
|
||||
-> {
|
||||
receiver.doesnt_exist
|
||||
}.should raise_error(NameError) {|e| e.receiver.should equal(receiver) }
|
||||
end
|
||||
@@doesnt_exist
|
||||
}.should complain(/class variable access from toplevel/)
|
||||
}.should raise_error(NameError) {|e| e.receiver.should equal(Object) }
|
||||
end
|
||||
|
||||
it "returns the Object class when an undefined constant is called without namespace" do
|
||||
-> {
|
||||
DoesntExist
|
||||
}.should raise_error(NameError) {|e| e.receiver.should equal(Object) }
|
||||
end
|
||||
it "returns a class when an undefined class variable is called in a subclass' namespace" do
|
||||
-> {
|
||||
NameErrorSpecs::ReceiverClass.new.call_undefined_class_variable
|
||||
}.should raise_error(NameError) {|e| e.receiver.should equal(NameErrorSpecs::ReceiverClass) }
|
||||
end
|
||||
|
||||
it "returns a class when an undefined constant is called" do
|
||||
-> {
|
||||
NameErrorSpecs::ReceiverClass::DoesntExist
|
||||
}.should raise_error(NameError) {|e| e.receiver.should equal(NameErrorSpecs::ReceiverClass) }
|
||||
end
|
||||
it "returns the receiver when raised from #instance_variable_get" do
|
||||
receiver = Object.new
|
||||
|
||||
it "returns the Object class when an undefined class variable is called" do
|
||||
-> {
|
||||
-> {
|
||||
@@doesnt_exist
|
||||
}.should complain(/class variable access from toplevel/)
|
||||
}.should raise_error(NameError) {|e| e.receiver.should equal(Object) }
|
||||
end
|
||||
-> {
|
||||
receiver.instance_variable_get("invalid_ivar_name")
|
||||
}.should raise_error(NameError) {|e| e.receiver.should equal(receiver) }
|
||||
end
|
||||
|
||||
it "returns a class when an undefined class variable is called in a subclass' namespace" do
|
||||
-> {
|
||||
NameErrorSpecs::ReceiverClass.new.call_undefined_class_variable
|
||||
}.should raise_error(NameError) {|e| e.receiver.should equal(NameErrorSpecs::ReceiverClass) }
|
||||
end
|
||||
it "returns the receiver when raised from #class_variable_get" do
|
||||
-> {
|
||||
Object.class_variable_get("invalid_cvar_name")
|
||||
}.should raise_error(NameError) {|e| e.receiver.should equal(Object) }
|
||||
end
|
||||
|
||||
it "returns the receiver when raised from #instance_variable_get" do
|
||||
receiver = Object.new
|
||||
|
||||
-> {
|
||||
receiver.instance_variable_get("invalid_ivar_name")
|
||||
}.should raise_error(NameError) {|e| e.receiver.should equal(receiver) }
|
||||
end
|
||||
|
||||
it "returns the receiver when raised from #class_variable_get" do
|
||||
-> {
|
||||
Object.class_variable_get("invalid_cvar_name")
|
||||
}.should raise_error(NameError) {|e| e.receiver.should equal(Object) }
|
||||
end
|
||||
|
||||
it "raises an ArgumentError when the receiver is none" do
|
||||
-> { NameError.new.receiver }.should raise_error(ArgumentError)
|
||||
end
|
||||
it "raises an ArgumentError when the receiver is none" do
|
||||
-> { NameError.new.receiver }.should raise_error(ArgumentError)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue