Permalink
Browse files

added tests for new show-source/show-doc behaviour

  • Loading branch information...
banister committed Apr 18, 2012
1 parent 5993c45 commit 011365f9df00601ae425934f1bfb94049a507179
Showing with 435 additions and 0 deletions.
  1. +19 −0 test/helper.rb
  2. +115 −0 test/test_default_commands/test_documentation.rb
  3. +301 −0 test/test_default_commands/test_show_source.rb
View
@@ -24,6 +24,25 @@ def inject_var(name, value, b)
Thread.current[:__pry_local__] = nil
end
+def constant_scope(*names)
+ names.each do |name|
+ Object.remove_const name if Object.const_defined?(name)
+ end
+
+ yield
+ensure
+ names.each do |name|
+ Object.remove_const name if Object.const_defined?(name)
+ end
+end
+
+# **DO NOT CHANGE THIS COMMENT, IT IS USED IN TESTS**
+# used by test_show_source.rb and test_documentation.rb
+class TestClassForShowSource
+ def alpha
+ end
+end
+
# in case the tests call reset_defaults, ensure we reset them to
# amended (test friendly) values
class << Pry
@@ -63,4 +63,119 @@ def o.initialize; end
mock_pry(binding, "show-doc --super o.initialize -ss").should == mock_pry("show-doc Object#initialize")
end
end
+
+ describe "on modules" do
+ before do
+ # god this is boring1
+ class ShowSourceTestClass
+ def alpha
+ end
+ end
+
+ # god this is boring2
+ module ShowSourceTestModule
+ def alpha
+ end
+ end
+
+ # god this is boring3
+ ShowSourceTestClassWeirdSyntax = Class.new do
+ def beta
+ end
+ end
+
+ # god this is boring4
+ ShowSourceTestModuleWeirdSyntax = Module.new do
+ def beta
+ end
+ end
+ end
+
+ after do
+ Object.remove_const :ShowSourceTestClass
+ Object.remove_const :ShowSourceTestClassWeirdSyntax
+ Object.remove_const :ShowSourceTestModule
+ Object.remove_const :ShowSourceTestModuleWeirdSyntax
+ end
+
+ describe "basic functionality, should show docs for top-level module definitions" do
+ it 'should show docs for a class' do
+ mock_pry("show-doc ShowSourceTestClass").should =~ /god this is boring1/
+ end
+
+ it 'should show docs for a module' do
+ mock_pry("show-doc ShowSourceTestModule").should =~ /god this is boring2/
+ end
+
+ it 'should show docs for a class when Const = Class.new syntax is used' do
+ mock_pry("show-doc ShowSourceTestClassWeirdSyntax").should =~ /god this is boring3/
+ end
+
+ it 'should show docs for a module when Const = Module.new syntax is used' do
+ mock_pry("show-doc ShowSourceTestModuleWeirdSyntax").should =~ /god this is boring4/
+ end
+ end
+
+ describe "in REPL" do
+ it 'should find class defined in repl' do
+ mock_pry("# hello tobina", "class TobinaMyDog", "def woof", "end", "end", "show-doc TobinaMyDog").should =~ /hello tobina/
+ Object.remove_const :TobinaMyDog
+ 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
+ end
+ end
+
+ class AlphaClass
+
+ # nested beta
+ class BetaClass
+ def beta
+ end
+ end
+ end
+
+ redirect_pry_io(InputTester.new("show-doc BetaClass", "exit-all"), out=StringIO.new) do
+ AlphaClass.pry
+ end
+
+ out.string.should =~ /nested beta/
+ end
+ end
+
+ it 'should lookup nested modules' do
+ constant_scope(:AlphaClass) do
+ class AlphaClass
+
+ # nested beta
+ class BetaClass
+ def beta
+ end
+ end
+ end
+
+ mock_pry("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
+
+ mock_pry("show-doc TestClassForShowSource -a").should =~ /used by.*?local monkeypatch/m
+ end
+ end
+
+ end
end
Oops, something went wrong.

0 comments on commit 011365f

Please sign in to comment.