Skip to content

Commit

Permalink
Updated CI specs to RubySpec ae7f25f8.
Browse files Browse the repository at this point in the history
  • Loading branch information
brixen committed Apr 8, 2014
1 parent 7051e61 commit 024874c
Show file tree
Hide file tree
Showing 151 changed files with 1,981 additions and 3,641 deletions.
4 changes: 3 additions & 1 deletion spec/ruby/core/basicobject/method_missing_spec.rb
@@ -1,7 +1,9 @@
require File.expand_path('../../../shared/kernel/method_missing', __FILE__)

describe "BasicObject#method_missing" do
it_behaves_like :method_missing, nil, BasicObject
it "is a private method" do
BasicObject.should have_private_instance_method(:method_missing)
end
end

describe "BasicObject#method_missing" do
Expand Down
108 changes: 0 additions & 108 deletions spec/ruby/core/kernel/caller_spec.rb
@@ -1,115 +1,7 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)

# DO NOT PUT ANYTHING ABOVE THIS
describe "Kernel#caller" do
before :each do
def a(skip)
caller(skip)
end
def b(skip)
a(skip)
end
def c(skip)
b(skip)
end
end

it "is a private method" do
Kernel.should have_private_instance_method(:caller)
end

it "returns the current call stack" do
stack = c 0
stack[0].should =~ /caller_spec.rb.*?8.*?`a'/
stack[1].should =~ /caller_spec.rb.*?11.*?`b'/
stack[2].should =~ /caller_spec.rb.*?14.*?`c'/
end

it "omits a number of frames corresponding to the parameter" do
c(0)[1..-1].should == c(1)
c(0)[2..-1].should == c(2)
c(0)[3..-1].should == c(3)
end

it "defaults to omitting one frame" do
caller.should == caller(1)
end

# The contents of the array returned by #caller depends on whether
# the call is made from an instance_eval block or a <block>#call.
# We purposely do not spec what happens if you request to omit
# more entries than exist in the array returned.
end

describe "Kernel#caller in a Proc or eval" do
it "returns the definition trace of a block when evaluated in a Proc binding" do
stack = CallerFixture.caller_of(CallerFixture.block)
stack[0].should =~ /caller_fixture1\.rb:4:in `<top \(required\)>'/
stack[1].should =~ /caller_fixture2\.rb:18:in `eval'/
stack[2].should =~ /caller_fixture2\.rb:18:in `caller_of'/
stack[3].should =~ /caller_spec\.rb:95:in `block \(3 levels\) in <top \(required\)>'/
end

it "returns the definition trace of a Proc" do
stack = CallerFixture.caller_of(CallerFixture.example_proc)
stack[0].should =~ /caller_fixture1\.rb:14:in `example_proc'/
stack[1].should =~ /caller_fixture2\.rb:18:in `eval'/
stack[2].should =~ /caller_fixture2\.rb:18:in `caller_of'/
stack[3].should =~ /caller_spec\.rb:103:in `block \(3 levels\) in <top \(required\)>'/
end

it "returns the correct caller line from a called Proc" do
stack = CallerFixture.entry_point.call
stack[0].should =~ /caller_fixture1\.rb:31:in `block in third'/
stack[1].should =~ /caller_spec\.rb:111:in `call'/
stack[2].should =~ /caller_spec\.rb:111:in `block \(3 levels\) in <top \(required\)>'/
end

# On 1.8 this expectation is marred by bug #146. I don't understand 1.9's
# output to ascertain whether the same bug occurs here, and if so what is
# the correct behaviour
it "returns the correct definition line for a complex Proc trace" do
stack = CallerFixture.caller_of(CallerFixture.entry_point)
stack[0].should =~ /caller_fixture1\.rb:29:in `third'/
stack[1].should =~ /caller_fixture2\.rb:18:in `eval'/
stack[2].should =~ /caller_fixture2\.rb:18:in `caller_of'/
stack[3].should =~ /caller_spec.rb:121:in `block \(3 levels\) in <top \(required\)>'/
end

it "begins with (eval) for caller(0) in eval" do
stack = CallerFixture.eval_caller(0)
stack[0].should == "(eval):1:in `eval_caller'"
stack[1].should =~ /caller_fixture2\.rb:23:in `eval'/
stack[2].should =~ /caller_fixture2\.rb:23:in `eval_caller'/
stack[3].should =~ /caller_spec\.rb:129:in `block \(3 levels\) in <top \(required\)>'/
end

it "shows the current line in the calling block twice when evaled" do
stack = CallerFixture.eval_caller(0); line = __LINE__
stack[0].should == "(eval):1:in `eval_caller'"
stack[1].should =~/caller_fixture2\.rb:23:in `eval'/
stack[2].should =~/caller_fixture2\.rb:23:in `eval_caller'/
stack[3].should =~/caller_spec\.rb:#{line}:in `block \(3 levels\) in <top \(required\)>/
end

it "begins with the eval's sender's sender for caller(4) in eval" do
stack = CallerFixture.eval_caller(4)
stack[0].should =~ /\.rb:\d+:in `instance_eval'/ # mspec.rb
end

it "returns one frame for new and one frame for initialize when creating objects" do
stack = CallerFixture::InitializeRecorder.new(0).caller_on_initialize
stack[0].should =~ /initialize/
stack[1].should =~ /new/
end
end

describe "Kernel.caller" do
# redmine:3011
it "returns one entry per call, even for recursive methods" do
two = CallerSpecs::recurse(2)
three = CallerSpecs::recurse(3)
(three.size - two.size).should == 1
end
end
42 changes: 0 additions & 42 deletions spec/ruby/core/kernel/fixtures/caller_fixture1.rb

This file was deleted.

33 changes: 0 additions & 33 deletions spec/ruby/core/kernel/fixtures/caller_fixture2.rb

This file was deleted.

9 changes: 0 additions & 9 deletions spec/ruby/core/kernel/fixtures/classes.rb
@@ -1,5 +1,3 @@
require File.expand_path('../caller_fixture1', __FILE__)

module KernelSpecs
def self.Array_function(arg)
Array(arg)
Expand Down Expand Up @@ -439,13 +437,6 @@ def self.call_eval
end
end

module CallerSpecs
def self.recurse(n)
return caller if n <= 0
recurse(n-1)
end
end

# for Kernel#sleep to have Channel in it's specs
# TODO: switch directly to queue for both Kernel#sleep and Thread specs?
unless defined? Channel
Expand Down
4 changes: 0 additions & 4 deletions spec/ruby/core/kernel/method_missing_spec.rb
@@ -1,9 +1,5 @@
require File.expand_path('../../../shared/kernel/method_missing', __FILE__)

describe "Kernel#method_missing" do
it_behaves_like :method_missing, nil, Kernel
end

describe "Kernel#method_missing" do
it_behaves_like :method_missing_defined_module, nil, KernelSpecs::ModuleMM
end
Expand Down
6 changes: 2 additions & 4 deletions spec/ruby/core/kernel/to_enum_spec.rb
@@ -1,7 +1,5 @@
require File.expand_path('../../../spec_helper', __FILE__)

ruby_version_is "1.9" do
describe "Kernel#to_enum" do
it "needs to be reviewed for spec completeness"
end
describe "Kernel#to_enum" do
it "needs to be reviewed for spec completeness"
end
12 changes: 2 additions & 10 deletions spec/ruby/core/main/define_method_spec.rb
Expand Up @@ -22,15 +22,7 @@
Object.should have_method :boom
end

ruby_version_is '2.0'...'2.1' do
it 'returns a Proc' do
eval(@code, TOPLEVEL_BINDING).is_a?(Proc).should be_true
end
end

ruby_version_is '2.1' do
it 'returns the method name as symbol' do
eval(@code, TOPLEVEL_BINDING).should equal :boom
end
it 'returns the method name as symbol' do
eval(@code, TOPLEVEL_BINDING).should equal :boom
end
end
33 changes: 8 additions & 25 deletions spec/ruby/core/matchdata/begin_spec.rb
Expand Up @@ -14,32 +14,15 @@
match_data.begin(1).should be_nil
end

ruby_version_is ""..."1.9" do
it "returns the offset for multi byte strings" do
match_data = /(.)(.)(\d+)(\d)/.match("TñX1138.")
match_data.begin(0).should == 2
match_data.begin(2).should == 3
end

it "returns the offset for multi byte strings with unicode regexp" do
match_data = /(.)(.)(\d+)(\d)/u.match("TñX1138.")
match_data.begin(0).should == 1
match_data.begin(2).should == 3
end
it "returns the offset for multi byte strings" do
match_data = /(.)(.)(\d+)(\d)/.match("TñX1138.")
match_data.begin(0).should == 1
match_data.begin(2).should == 2
end

ruby_version_is "1.9" do
it "returns the offset for multi byte strings" do
match_data = /(.)(.)(\d+)(\d)/.match("TñX1138.")
match_data.begin(0).should == 1
match_data.begin(2).should == 2
end

it "returns the offset for multi byte strings with unicode regexp" do
match_data = /(.)(.)(\d+)(\d)/u.match("TñX1138.")
match_data.begin(0).should == 1
match_data.begin(2).should == 2
end
it "returns the offset for multi byte strings with unicode regexp" do
match_data = /(.)(.)(\d+)(\d)/u.match("TñX1138.")
match_data.begin(0).should == 1
match_data.begin(2).should == 2
end

end
64 changes: 62 additions & 2 deletions spec/ruby/core/matchdata/element_reference_spec.rb
Expand Up @@ -17,6 +17,66 @@
end
end

ruby_version_is "1.9" do
require File.expand_path("../versions/element_reference_1.9", __FILE__)
describe "MatchData#[Symbol]" do
it "returns the corresponding named match when given a Symbol" do
md = 'haystack'.match(/(?<t>t(?<a>ack))/)
md[:a].should == 'ack'
md[:t].should == 'tack'
end

it "returns the corresponding named match when given a String" do
md = 'haystack'.match(/(?<t>t(?<a>ack))/)
md['a'].should == 'ack'
md['t'].should == 'tack'
end

it "returns the matching version of multiple corresponding named match" do
regexp = /(?:
A(?<word>\w+)
|
B(?<word>\w+)
)/x
md_a = regexp.match("Afoo")
md_b = regexp.match("Bfoo")

md_a[:word].should == "foo"
md_b[:word].should == "foo"

md_a['word'].should == "foo"
md_b['word'].should == "foo"
end

it "returns the last match when multiple named matches exist with the same name" do
md = /(?<word>hay)(?<word>stack)/.match('haystack')
md[:word].should == "stack"
md['word'].should == "stack"
end

it "returns nil on non-matching named matches" do
regexp = /(?<foo>foo )?(?<bar>bar)/
full_match = regexp.match("foo bar")
partial_match = regexp.match("bar")

full_match[:foo].should == "foo "
partial_match[:foo].should == nil

full_match['foo'].should == "foo "
partial_match['foo'].should == nil
end

it "raises an IndexError if there is no named match corresponding to the Symbol" do
md = 'haystack'.match(/(?<t>t(?<a>ack))/)
lambda { md[:baz] }.should raise_error(IndexError, /baz/)
end

it "raises an IndexError if there is no named match corresponding to the String" do
md = 'haystack'.match(/(?<t>t(?<a>ack))/)
lambda { md['baz'] }.should raise_error(IndexError, /baz/)
end

it "returns matches in the String's encoding" do
rex = /(?<t>t(?<a>ack))/u
md = 'haystack'.force_encoding('euc-jp').match(rex)
md[:t].encoding.should == Encoding::EUC_JP
end
end

0 comments on commit 024874c

Please sign in to comment.