Fix issue #877 (show-source -s doesn't work (when no method arg is
given))
This behaviour is shared between `show-source` and `show-doc`. So with
one fix I kill two bugs.
Add tests and rewrite some of the existing ones (related to the
`--super` switch).
Make sure that `show-doc` displays the comments of the original
definition by default. This test *must* fail with current state of
things. The goal is to eliminate the oddities in Pry across some Ruby
implementations.
For more information see:
d05233ecd3
This commit is rather interesting. Well, maybe not the commit, but the
issue it is aimed to fix. So what's the aim? The aim is to eliminate an
error in the test for the following Ruby implementations: rbx-18mode,
jruby-18mode, jruby-19mode.
See that build for details: https://travis-ci.org/pry/pry/builds/5478834
You may be wondering now: "Kyrylo, what is so interesting in it?".
Heh-heh, sit down right beside me, my covey.
I have a screenshot for you:
http://img-fotki.yandex.ru/get/4125/98991937.11/0_911d2_acdd6798_orig
The screenshot demonstrates the difference between `show-doc` finding
monkey-patches on different Ruby implementations (JRuby and MRI 1.9.3).
Take a closer look at the order of the candidates. It is different in
the abovementioned implementations. That is the reason why the test is
failing. Unfortunately, I couldn't figure out why that is happening.
The fix is simple and it doesn't ruin the idea of the test. However,
I'm leaving that order issue to the greater minds of our civilization.
Uh! Don't forget to check out the description of that commit, because it
is related to this topic:
e926d8c944
This commit fixes the failing test. Internally, Pry raises
`CommandError`, when cannot find a definition (this is the new
behaviour), so the test needs to be updated.
"The snake which cannot cast its skin has to die.
As well the minds which are prevented from changing
their opinions; they cease to be mind."
- Friedrich Nietzsche
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.
When performing show-source/show-doc on a class whose code
cannot be extracted we now fall-back to its first accessible superclass
and show its code together with a warning.
Example:
class Model < ActiveRecord::Base
end
show-source Model #=> shows ActiveRecord::Base code
Bug prevented lookup of Deeply::Nested::Class::Definitions.
Also properly differentiate when looking up docs/source for *commands* and for the class that represents the command, i.e:
show-doc show-source #=> displays show-source --help
show-doc Pry::Command::ShowSource #=> comments above class definition (as with any other class)
* removed most historicla junk from lib/pry/test/helper.rb
* relocated recalcitrant junk to the local spec/helper.rb (this isn't exposed to 3rd parties)