1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

Fix failing tests on rbx

The failures were due to Rbx recovering more source than expected (compared to MRI)

For example, the following fails in MRI:
module M
end

module N
  include M
end

show-source N

but on rbx it succeeds and shows the source of N

How does rbx do it? It appears to create a secret method called __module_init__ on a module whenever you include another module.
This method has its source_location set to the `include` line.
This commit is contained in:
John Mair 2013-02-08 03:09:56 +01:00
parent 4ca59800f2
commit 8f4b11d70d
2 changed files with 322 additions and 317 deletions

View file

@ -200,286 +200,289 @@ if !PryTestHelpers.mri18_and_no_real_source_location?
def woof
end
end
RUBY
t.eval('show-doc TobinaMyDog').should =~ /hello tobina/
Object.remove_const :TobinaMyDog
end
end
end
it 'should lookup module name with respect to current context' do
constant_scope(:AlphaClass, :BetaClass) do
# top-level beta
class BetaClass
def alpha
RUBY
t.eval('show-doc TobinaMyDog').should =~ /hello tobina/
Object.remove_const :TobinaMyDog
end
end
end
class AlphaClass
# nested beta
it 'should lookup module name with respect to current context' do
constant_scope(:AlphaClass, :BetaClass) do
# top-level beta
class BetaClass
def alpha
end
end
class AlphaClass
# nested beta
class BetaClass
def beta
end
end
end
pry_eval(AlphaClass, "show-doc BetaClass").should =~ /nested beta/
end
end
it 'should look up nested modules' do
constant_scope(:AlphaClass) do
class AlphaClass
# nested beta
class BetaClass
def beta
end
end
end
pry_eval("show-doc AlphaClass::BetaClass").should =~
/nested beta/
end
end
describe "show-doc -a" do
it 'should show the docs for all monkeypatches defined in different files' do
# local monkeypatch
class TestClassForShowSource
def beta
end
end
result = pry_eval("show-doc TestClassForShowSource -a")
result.should =~ /used by/
result.should =~ /local monkeypatch/
end
end
describe "when no class/module arg is given" do
before do
module TestHost
# hello there froggy
module M
def d; end
def e; end
end
end
end
pry_eval(AlphaClass, "show-doc BetaClass").should =~ /nested beta/
end
end
after do
Object.remove_const(:TestHost)
end
it 'should look up nested modules' do
constant_scope(:AlphaClass) do
class AlphaClass
# nested beta
class BetaClass
def beta
it 'should return doc for current module' do
pry_eval(TestHost::M, "show-doc").should =~ /hello there froggy/
end
end
# FIXME: THis is nto a good spec anyway, because i dont think it
# SHOULD skip!
describe "should skip over broken modules" do
before do
module TestHost
# hello
module M
binding.eval("def a; end", "dummy.rb", 1)
binding.eval("def b; end", "dummy.rb", 2)
binding.eval("def c; end", "dummy.rb", 3)
end
# goodbye
module M
def d; end
def e; end
end
end
end
pry_eval("show-doc AlphaClass::BetaClass").should =~
/nested beta/
end
end
describe "show-doc -a" do
it 'should show the docs for all monkeypatches defined in different files' do
# local monkeypatch
class TestClassForShowSource
def beta
end
after do
Object.remove_const(:TestHost)
end
result = pry_eval("show-doc TestClassForShowSource -a")
result.should =~ /used by/
result.should =~ /local monkeypatch/
it 'should return doc for first valid module' do
result = pry_eval("show-doc TestHost::M")
result.should =~ /goodbye/
result.should.not =~ /hello/
end
end
end
describe "when no class/module arg is given" do
describe "on commands" do
# mostly copied & modified from test_help.rb
before do
module TestHost
# hello there froggy
module M
def d; end
def e; end
end
@oldset = Pry.config.commands
@set = Pry.config.commands = Pry::CommandSet.new do
import Pry::Commands
end
end
after do
Object.remove_const(:TestHost)
Pry.config.commands = @oldset
end
it 'should return doc for current module' do
pry_eval(TestHost::M, "show-doc").should =~ /hello there froggy/
it 'should display help for a specific command' do
pry_eval('show-doc ls').should =~ /Usage: ls/
end
end
# FIXME: THis is nto a good spec anyway, because i dont think it
# SHOULD skip!
describe "should skip over broken modules" do
before do
module TestHost
# hello
module M
binding.eval("def a; end", "dummy.rb", 1)
binding.eval("def b; end", "dummy.rb", 2)
binding.eval("def c; end", "dummy.rb", 3)
it 'should display help for a regex command with a "listing"' do
@set.command /bar(.*)/, "Test listing", :listing => "foo" do; end
pry_eval('show-doc foo').should =~ /Test listing/
end
it 'should display help for a command with a spaces in its name' do
@set.command "command with spaces", "description of a command with spaces" do; end
pry_eval('show-doc command with spaces').should =~ /description of a command with spaces/
end
describe "class commands" do
before do
# pretty pink pincers
class LobsterLady < Pry::ClassCommand
match "lobster-lady"
description "nada."
def process
"lobster"
end
end
# goodbye
module M
def d; end
def e; end
end
Pry.commands.add_command(LobsterLady)
end
after do
Object.remove_const(:LobsterLady)
end
it 'should display "help" when looking up by command name' do
pry_eval('show-doc lobster-lady').should =~ /nada/
Pry.commands.delete("lobster-lady")
end
it 'should display actual preceding comment for a class command, when class is used (rather than command name) when looking up' do
pry_eval('show-doc LobsterLady').should =~ /pretty pink pincers/
Pry.commands.delete("lobster-lady")
end
end
after do
Object.remove_const(:TestHost)
end
it 'should return doc for first valid module' do
result = pry_eval("show-doc TestHost::M")
result.should =~ /goodbye/
result.should.not =~ /hello/
end
end
end
describe "on commands" do
# mostly copied & modified from test_help.rb
before do
@oldset = Pry.config.commands
@set = Pry.config.commands = Pry::CommandSet.new do
import Pry::Commands
describe "should set _file_ and _dir_" do
it 'should set _file_ and _dir_ to file containing method source' do
t = pry_tester
t.process_command "show-doc TestClassForShowSource#alpha"
t.pry.last_file.should =~ /show_source_doc_examples/
t.pry.last_dir.should =~ /fixtures/
end
end
after do
Pry.config.commands = @oldset
end
unless Pry::Helpers::BaseHelpers.rbx?
describe "can't find class docs" do
describe "for classes" do
before do
module Jesus
class Brian; end
it 'should display help for a specific command' do
pry_eval('show-doc ls').should =~ /Usage: ls/
end
# doink-doc
class Jingle
def a; :doink; end
end
it 'should display help for a regex command with a "listing"' do
@set.command /bar(.*)/, "Test listing", :listing => "foo" do; end
pry_eval('show-doc foo').should =~ /Test listing/
end
class Jangle < Jingle; end
class Bangle < Jangle; end
end
end
it 'should display help for a command with a spaces in its name' do
@set.command "command with spaces", "description of a command with spaces" do; end
pry_eval('show-doc command with spaces').should =~ /description of a command with spaces/
end
after do
Object.remove_const(:Jesus)
end
describe "class commands" do
before do
# pretty pink pincers
class LobsterLady < Pry::ClassCommand
match "lobster-lady"
description "nada."
def process
"lobster"
it 'shows superclass doc' do
t = pry_tester
t.process_command "show-doc Jesus::Jangle"
t.last_output.should =~ /doink-doc/
end
it 'errors when class has no superclass to show' do
t = pry_tester
lambda { t.process_command "show-doc Jesus::Brian" }.should.raise(Pry::CommandError).message.
should =~ /Couldn't locate/
end
it 'shows warning when reverting to superclass docs' do
t = pry_tester
t.process_command "show-doc Jesus::Jangle"
t.last_output.should =~ /Warning.*?Cannot find.*?Jesus::Jangle.*Showing.*Jesus::Jingle instead/
end
it 'shows nth level superclass docs (when no intermediary superclasses have code either)' do
t = pry_tester
t.process_command "show-doc Jesus::Bangle"
t.last_output.should =~ /doink-doc/
end
it 'shows correct warning when reverting to nth level superclass' do
t = pry_tester
t.process_command "show-doc Jesus::Bangle"
t.last_output.should =~ /Warning.*?Cannot find.*?Jesus::Bangle.*Showing.*Jesus::Jingle instead/
end
end
Pry.commands.add_command(LobsterLady)
end
describe "for modules" do
before do
module Jesus
after do
Object.remove_const(:LobsterLady)
end
# alpha-doc
module Alpha
def alpha; :alpha; end
end
it 'should display "help" when looking up by command name' do
pry_eval('show-doc lobster-lady').should =~ /nada/
Pry.commands.delete("lobster-lady")
end
module Zeta; end
it 'should display actual preceding comment for a class command, when class is used (rather than command name) when looking up' do
pry_eval('show-doc LobsterLady').should =~ /pretty pink pincers/
Pry.commands.delete("lobster-lady")
end
end
end
module Beta
include Alpha
end
describe "should set _file_ and _dir_" do
it 'should set _file_ and _dir_ to file containing method source' do
t = pry_tester
t.process_command "show-doc TestClassForShowSource#alpha"
t.pry.last_file.should =~ /show_source_doc_examples/
t.pry.last_dir.should =~ /fixtures/
end
end
describe "can't find class docs" do
describe "for classes" do
before do
module Jesus
class Brian; end
# doink-doc
class Jingle
def a; :doink; end
module Gamma
include Beta
end
end
end
class Jangle < Jingle; end
class Bangle < Jangle; end
end
end
after do
Object.remove_const(:Jesus)
end
it 'shows superclass doc' do
t = pry_tester
t.process_command "show-doc Jesus::Jangle"
t.last_output.should =~ /doink-doc/
end
it 'errors when class has no superclass to show' do
t = pry_tester
lambda { t.process_command "show-doc Jesus::Brian" }.should.raise(Pry::CommandError).message.
should =~ /Couldn't locate/
end
it 'shows warning when reverting to superclass docs' do
t = pry_tester
t.process_command "show-doc Jesus::Jangle"
t.last_output.should =~ /Warning.*?Cannot find.*?Jesus::Jangle.*Showing.*Jesus::Jingle instead/
end
it 'shows nth level superclass docs (when no intermediary superclasses have code either)' do
t = pry_tester
t.process_command "show-doc Jesus::Bangle"
t.last_output.should =~ /doink-doc/
end
it 'shows correct warning when reverting to nth level superclass' do
t = pry_tester
t.process_command "show-doc Jesus::Bangle"
t.last_output.should =~ /Warning.*?Cannot find.*?Jesus::Bangle.*Showing.*Jesus::Jingle instead/
end
end
describe "for modules" do
before do
module Jesus
# alpha-doc
module Alpha
def alpha; :alpha; end
after do
Object.remove_const(:Jesus)
end
module Zeta; end
module Beta
include Alpha
it 'shows included module doc' do
t = pry_tester
t.process_command "show-doc Jesus::Beta"
t.last_output.should =~ /alpha-doc/
end
module Gamma
include Beta
it 'shows warning when reverting to included module doc' do
t = pry_tester
t.process_command "show-doc Jesus::Beta"
t.last_output.should =~ /Warning.*?Cannot find.*?Jesus::Beta.*Showing.*Jesus::Alpha instead/
end
it 'errors when module has no included module to show' do
t = pry_tester
lambda { t.process_command "show-source Jesus::Zeta" }.should.raise(Pry::CommandError).message.
should =~ /Couldn't locate/
end
it 'shows nth level included module doc (when no intermediary modules have code either)' do
t = pry_tester
t.process_command "show-doc Jesus::Gamma"
t.last_output.should =~ /alpha-doc/
end
it 'shows correct warning when reverting to nth level included module' do
t = pry_tester
t.process_command "show-source Jesus::Gamma"
t.last_output.should =~ /Warning.*?Cannot find.*?Jesus::Gamma.*Showing.*Jesus::Alpha instead/
end
end
end
after do
Object.remove_const(:Jesus)
end
it 'shows included module doc' do
t = pry_tester
t.process_command "show-doc Jesus::Beta"
t.last_output.should =~ /alpha-doc/
end
it 'shows warning when reverting to included module doc' do
t = pry_tester
t.process_command "show-doc Jesus::Beta"
t.last_output.should =~ /Warning.*?Cannot find.*?Jesus::Beta.*Showing.*Jesus::Alpha instead/
end
it 'errors when module has no included module to show' do
t = pry_tester
lambda { t.process_command "show-source Jesus::Zeta" }.should.raise(Pry::CommandError).message.
should =~ /Couldn't locate/
end
it 'shows nth level included module doc (when no intermediary modules have code either)' do
t = pry_tester
t.process_command "show-doc Jesus::Gamma"
t.last_output.should =~ /alpha-doc/
end
it 'shows correct warning when reverting to nth level included module' do
t = pry_tester
t.process_command "show-source Jesus::Gamma"
t.last_output.should =~ /Warning.*?Cannot find.*?Jesus::Gamma.*Showing.*Jesus::Alpha instead/
end
end
end
end
end

View file

@ -641,116 +641,118 @@ if !PryTestHelpers.mri18_and_no_real_source_location?
end
end
describe "can't find class/module code" do
describe "for classes" do
before do
module Jesus
module Pig
def lillybing; :lillybing; end
end
unless Pry::Helpers::BaseHelpers.rbx?
describe "can't find class/module code" do
describe "for classes" do
before do
module Jesus
module Pig
def lillybing; :lillybing; end
end
class Brian; end
class Jingle
def a; :doink; end
end
class Brian; end
class Jingle
def a; :doink; end
end
class Jangle < Jingle; include Pig; end
class Bangle < Jangle; end
class Jangle < Jingle; include Pig; end
class Bangle < Jangle; end
end
end
after do
Object.remove_const(:Jesus)
end
it 'shows superclass code' do
t = pry_tester
t.process_command "show-source Jesus::Jangle"
t.last_output.should =~ /doink/
end
it 'ignores included modules' do
t = pry_tester
t.process_command "show-source Jesus::Jangle"
t.last_output.should.not =~ /lillybing/
end
it 'errors when class has no superclass to show' do
t = pry_tester
lambda { t.process_command "show-source Jesus::Brian" }.should.raise(Pry::CommandError).message.
should =~ /Couldn't locate/
end
it 'shows warning when reverting to superclass code' do
t = pry_tester
t.process_command "show-source Jesus::Jangle"
t.last_output.should =~ /Warning.*?Cannot find.*?Jesus::Jangle.*Showing.*Jesus::Jingle instead/
end
it 'shows nth level superclass code (when no intermediary superclasses have code either)' do
t = pry_tester
t.process_command "show-source Jesus::Bangle"
t.last_output.should =~ /doink/
end
it 'shows correct warning when reverting to nth level superclass' do
t = pry_tester
t.process_command "show-source Jesus::Bangle"
t.last_output.should =~ /Warning.*?Cannot find.*?Jesus::Bangle.*Showing.*Jesus::Jingle instead/
end
end
after do
Object.remove_const(:Jesus)
end
describe "for modules" do
before do
module Jesus
module Alpha
def alpha; :alpha; end
end
it 'shows superclass code' do
t = pry_tester
t.process_command "show-source Jesus::Jangle"
t.last_output.should =~ /doink/
end
module Zeta; end
it 'ignores included modules' do
t = pry_tester
t.process_command "show-source Jesus::Jangle"
t.last_output.should.not =~ /lillybing/
end
module Beta
include Alpha
end
it 'errors when class has no superclass to show' do
t = pry_tester
lambda { t.process_command "show-source Jesus::Brian" }.should.raise(Pry::CommandError).message.
should =~ /Couldn't locate/
end
it 'shows warning when reverting to superclass code' do
t = pry_tester
t.process_command "show-source Jesus::Jangle"
t.last_output.should =~ /Warning.*?Cannot find.*?Jesus::Jangle.*Showing.*Jesus::Jingle instead/
end
it 'shows nth level superclass code (when no intermediary superclasses have code either)' do
t = pry_tester
t.process_command "show-source Jesus::Bangle"
t.last_output.should =~ /doink/
end
it 'shows correct warning when reverting to nth level superclass' do
t = pry_tester
t.process_command "show-source Jesus::Bangle"
t.last_output.should =~ /Warning.*?Cannot find.*?Jesus::Bangle.*Showing.*Jesus::Jingle instead/
end
end
describe "for modules" do
before do
module Jesus
module Alpha
def alpha; :alpha; end
end
module Zeta; end
module Beta
include Alpha
end
module Gamma
include Beta
module Gamma
include Beta
end
end
end
end
after do
Object.remove_const(:Jesus)
end
after do
Object.remove_const(:Jesus)
end
it 'shows included module code' do
t = pry_tester
t.process_command "show-source Jesus::Beta"
t.last_output.should =~ /alpha/
end
it 'shows included module code' do
t = pry_tester
t.process_command "show-source Jesus::Beta"
t.last_output.should =~ /alpha/
end
it 'shows warning when reverting to included module code' do
t = pry_tester
t.process_command "show-source Jesus::Beta"
t.last_output.should =~ /Warning.*?Cannot find.*?Jesus::Beta.*Showing.*Jesus::Alpha instead/
end
it 'shows warning when reverting to included module code' do
t = pry_tester
t.process_command "show-source Jesus::Beta"
t.last_output.should =~ /Warning.*?Cannot find.*?Jesus::Beta.*Showing.*Jesus::Alpha instead/
end
it 'errors when module has no included module to show' do
t = pry_tester
lambda { t.process_command "show-source Jesus::Zeta" }.should.raise(Pry::CommandError).message.
should =~ /Couldn't locate/
end
it 'errors when module has no included module to show' do
t = pry_tester
lambda { t.process_command "show-source Jesus::Zeta" }.should.raise(Pry::CommandError).message.
should =~ /Couldn't locate/
end
it 'shows nth level included module code (when no intermediary modules have code either)' do
t = pry_tester
t.process_command "show-source Jesus::Gamma"
t.last_output.should =~ /alpha/
end
it 'shows nth level included module code (when no intermediary modules have code either)' do
t = pry_tester
t.process_command "show-source Jesus::Gamma"
t.last_output.should =~ /alpha/
end
it 'shows correct warning when reverting to nth level included module' do
t = pry_tester
t.process_command "show-source Jesus::Gamma"
t.last_output.should =~ /Warning.*?Cannot find.*?Jesus::Gamma.*Showing.*Jesus::Alpha instead/
it 'shows correct warning when reverting to nth level included module' do
t = pry_tester
t.process_command "show-source Jesus::Gamma"
t.last_output.should =~ /Warning.*?Cannot find.*?Jesus::Gamma.*Showing.*Jesus::Alpha instead/
end
end
end
end