pry 0.9.7.4-i386-mswin32 → 0.9.8-i386-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. data/.gitignore +2 -3
  2. data/CHANGELOG +43 -0
  3. data/README.markdown +3 -1
  4. data/Rakefile +51 -32
  5. data/bin/pry +2 -80
  6. data/lib/pry.rb +33 -26
  7. data/lib/pry/cli.rb +152 -0
  8. data/lib/pry/code.rb +351 -0
  9. data/lib/pry/command.rb +422 -0
  10. data/lib/pry/command_set.rb +259 -129
  11. data/lib/pry/commands.rb +0 -1
  12. data/lib/pry/config.rb +43 -9
  13. data/lib/pry/default_commands/context.rb +109 -92
  14. data/lib/pry/default_commands/documentation.rb +174 -63
  15. data/lib/pry/default_commands/easter_eggs.rb +26 -2
  16. data/lib/pry/default_commands/gems.rb +65 -37
  17. data/lib/pry/default_commands/input.rb +175 -243
  18. data/lib/pry/default_commands/introspection.rb +173 -112
  19. data/lib/pry/default_commands/ls.rb +96 -114
  20. data/lib/pry/default_commands/shell.rb +175 -70
  21. data/lib/pry/helpers/base_helpers.rb +7 -2
  22. data/lib/pry/helpers/command_helpers.rb +71 -77
  23. data/lib/pry/helpers/options_helpers.rb +10 -41
  24. data/lib/pry/helpers/text.rb +24 -4
  25. data/lib/pry/history.rb +55 -17
  26. data/lib/pry/history_array.rb +2 -0
  27. data/lib/pry/hooks.rb +252 -0
  28. data/lib/pry/indent.rb +9 -5
  29. data/lib/pry/method.rb +149 -50
  30. data/lib/pry/plugins.rb +12 -4
  31. data/lib/pry/pry_class.rb +69 -26
  32. data/lib/pry/pry_instance.rb +187 -115
  33. data/lib/pry/version.rb +1 -1
  34. data/lib/pry/wrapped_module.rb +73 -0
  35. data/man/pry.1 +195 -0
  36. data/man/pry.1.html +204 -0
  37. data/man/pry.1.ronn +141 -0
  38. data/pry.gemspec +29 -32
  39. data/test/helper.rb +32 -36
  40. data/test/test_cli.rb +78 -0
  41. data/test/test_code.rb +201 -0
  42. data/test/test_command.rb +327 -0
  43. data/test/test_command_integration.rb +512 -0
  44. data/test/test_command_set.rb +338 -12
  45. data/test/test_completion.rb +1 -1
  46. data/test/test_default_commands.rb +1 -2
  47. data/test/test_default_commands/test_context.rb +27 -5
  48. data/test/test_default_commands/test_documentation.rb +20 -8
  49. data/test/test_default_commands/test_input.rb +84 -45
  50. data/test/test_default_commands/test_introspection.rb +74 -17
  51. data/test/test_default_commands/test_ls.rb +9 -36
  52. data/test/test_default_commands/test_shell.rb +240 -13
  53. data/test/test_hooks.rb +490 -0
  54. data/test/test_indent.rb +2 -0
  55. data/test/test_method.rb +60 -0
  56. data/test/test_pry.rb +29 -904
  57. data/test/test_pry_defaults.rb +380 -0
  58. data/test/test_pry_history.rb +24 -24
  59. data/test/test_syntax_checking.rb +63 -0
  60. data/test/test_wrapped_module.rb +71 -0
  61. metadata +50 -39
  62. data/lib/pry/command_context.rb +0 -53
  63. data/lib/pry/command_processor.rb +0 -181
  64. data/lib/pry/extended_commands/user_command_api.rb +0 -65
  65. data/test/test_command_processor.rb +0 -176
data/man/pry.1.ronn ADDED
@@ -0,0 +1,141 @@
1
+ PRY(1) -- A Reference to the PRY repl.
2
+ ======================================
3
+
4
+ ##Synopsis
5
+
6
+
7
+ `pry` [`--version`] [`--exec`] [`--no-pager`] [`--no-history`] [`--no-color`] [`-f`] [`--no-plugins`] [`--installed-plugins`] [`--simple-prompt`] [`--require` _file_] [`-I`] [`--context`] [`--help`]
8
+
9
+ ## DESCRIPTION
10
+
11
+
12
+ Pry is a powerful alternative to the standard IRB shell for Ruby. It is written from scratch to provide a number of advanced features.
13
+
14
+ ## HOMEPAGE
15
+
16
+
17
+ http://pry.github.com/
18
+
19
+ ##OPTIONS
20
+
21
+
22
+ * `-v --version`:
23
+ Prints the version of Pry.
24
+
25
+ * `-e --exec`:
26
+ Executes argument in context before the session starts.
27
+
28
+ * `--no-pager`:
29
+ Disable pager for long output.
30
+
31
+ * `--no-history`:
32
+ Disable history loading.
33
+
34
+ * `--no-color`:
35
+ Disable syntax highlighting for session.
36
+
37
+ * `-f`:
38
+ Prevent loading of ~/.pryrc for session.
39
+
40
+ * `--no-plugins`:
41
+ Supress loading of plugins.
42
+
43
+ * `--installed-plugins`:
44
+ List installed plugins.
45
+
46
+ * `--simple-prompt`:
47
+ Enable simple prompt mode (eg, >>).
48
+
49
+ * `-r --require`:
50
+ Require a ruby script at startup.
51
+
52
+ * `-I`:
53
+ Add a path to the $LOAD_PATH
54
+
55
+ * `-c --context`:
56
+ Start the session in the specified context. Equivalent to `context.pry` in a session.
57
+
58
+ ##FILES
59
+
60
+
61
+ ~/.pryrc Personal pry initialization
62
+
63
+ ##EXAMPLES
64
+
65
+ ###Basic Usage
66
+
67
+
68
+ $ pry
69
+ [1] pry(main)>4 + 5
70
+ => 9
71
+ [2] pry(main)> def hello_world
72
+ [2] pry(main)* puts "Hello, World!"
73
+ [2] pry(main)* end
74
+ => nil
75
+ [3] pry(main)> hello_world
76
+ Hello, World!
77
+ => nil
78
+
79
+ ###Command Line Interaction
80
+
81
+
82
+ Prefix any command you want your shell to execute with a period and pry will return the results from your shell.
83
+
84
+ [1] pry(main)> .date
85
+ Fri Nov 11 09:52:07 EST 2011
86
+
87
+ On the command line enter `shell-mode` to incorporate the current working directory into the Pry prompt.
88
+
89
+ pry(main)> shell-mode
90
+ pry main:/Users/john/ruby/projects/pry $ .cd ..
91
+ pry main:/Users/john/ruby/projects $ .cd ~
92
+ pry main:/Users/john $ .pwd
93
+ /Users/john
94
+ pry main:/Users/john $ shell-mode
95
+ pry(main)>
96
+
97
+ ###State Navigation
98
+
99
+
100
+ The cd command is used to move into a new object (or scope) inside a Pry session. When inside the new scope it becomes the self for the session and all commands and methods will operate on this new self.
101
+
102
+ pry(main)> self
103
+ => main
104
+ pry(main)> cd Pry
105
+ pry(Pry):1> self
106
+ => Pry
107
+ pry(Pry):1> cd ..
108
+ pry(main)>
109
+
110
+ The ls command is essentially a unified wrapper to a number of Ruby's introspection mechanisms, including (but not limited to) the following methods: methods, instance\_variables, constants, local\_variables, instance\_methods, class_variables and all the various permutations thereof.
111
+
112
+ By default typing ls will return a list of just the local and instance variables available in the current context.
113
+
114
+ * The -M option selects public instance methods (if available).
115
+ * The -m option selects public methods.
116
+ * The -c option selects constants.
117
+ * The -i option select just instance variables.
118
+ * The -l option selects just local variables.
119
+ * The -s option modifies the -c and -m and -M options to go up the superclass chain (excluding Object).
120
+ * The --grep REGEX prunes the list to items that match the regex.
121
+
122
+ ###Source Browsing
123
+
124
+
125
+ Simply typing show-method method_name will pull the source for the method and display it with syntax highlighting. You can also look up the source for multiple methods at the same time, by typing show-method method1 method2. As a convenience, Pry looks up both instance methods and class methods using this syntax, with priority given to instance methods.
126
+
127
+ pry(Pry):1> show-method rep
128
+
129
+ From: /Users/john/ruby/projects/pry/lib/pry/pry_instance.rb @ line 191:
130
+ Number of lines: 6
131
+
132
+ def rep(target=TOPLEVEL_BINDING)
133
+ target = Pry.binding_for(target)
134
+ result = re(target)
135
+
136
+ show_result(result) if should_print?
137
+ end
138
+
139
+ ##AUTHORS
140
+
141
+ Pry is primarily the work of John Mair (banisterfiend)
data/pry.gemspec CHANGED
@@ -1,49 +1,46 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
3
  Gem::Specification.new do |s|
4
- s.name = "pry"
5
- s.version = "0.9.7.4"
4
+ s.name = %q{pry}
5
+ s.version = "0.9.8pre7"
6
6
 
7
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["John Mair (banisterfiend)"]
9
- s.date = "2011-11-05"
10
- s.description = "An IRB alternative and runtime developer console"
11
- s.email = "jrmair@gmail.com"
12
- s.executables = ["pry"]
13
- s.files = [".document", ".gemtest", ".gitignore", ".travis.yml", ".yardopts", "CHANGELOG", "CONTRIBUTORS", "Gemfile", "LICENSE", "README.markdown", "Rakefile", "TODO", "bin/pry", "examples/example_basic.rb", "examples/example_command_override.rb", "examples/example_commands.rb", "examples/example_hooks.rb", "examples/example_image_edit.rb", "examples/example_input.rb", "examples/example_input2.rb", "examples/example_output.rb", "examples/example_print.rb", "examples/example_prompt.rb", "examples/helper.rb", "lib/pry.rb", "lib/pry/command_context.rb", "lib/pry/command_processor.rb", "lib/pry/command_set.rb", "lib/pry/commands.rb", "lib/pry/completion.rb", "lib/pry/config.rb", "lib/pry/core_extensions.rb", "lib/pry/custom_completions.rb", "lib/pry/default_commands/basic.rb", "lib/pry/default_commands/context.rb", "lib/pry/default_commands/documentation.rb", "lib/pry/default_commands/easter_eggs.rb", "lib/pry/default_commands/gems.rb", "lib/pry/default_commands/input.rb", "lib/pry/default_commands/introspection.rb", "lib/pry/default_commands/ls.rb", "lib/pry/default_commands/shell.rb", "lib/pry/extended_commands/experimental.rb", "lib/pry/extended_commands/user_command_api.rb", "lib/pry/helpers.rb", "lib/pry/helpers/base_helpers.rb", "lib/pry/helpers/command_helpers.rb", "lib/pry/helpers/options_helpers.rb", "lib/pry/helpers/text.rb", "lib/pry/history.rb", "lib/pry/history_array.rb", "lib/pry/indent.rb", "lib/pry/method.rb", "lib/pry/plugins.rb", "lib/pry/pry_class.rb", "lib/pry/pry_instance.rb", "lib/pry/rbx_method.rb", "lib/pry/rbx_path.rb", "lib/pry/version.rb", "pry.gemspec", "test/helper.rb", "test/test_command_helpers.rb", "test/test_command_processor.rb", "test/test_command_set.rb", "test/test_completion.rb", "test/test_default_commands.rb", "test/test_default_commands/test_context.rb", "test/test_default_commands/test_documentation.rb", "test/test_default_commands/test_gems.rb", "test/test_default_commands/test_input.rb", "test/test_default_commands/test_introspection.rb", "test/test_default_commands/test_ls.rb", "test/test_default_commands/test_shell.rb", "test/test_exception_whitelist.rb", "test/test_history_array.rb", "test/test_indent.rb", "test/test_input_stack.rb", "test/test_method.rb", "test/test_pry.rb", "test/test_pry_history.rb", "test/test_pry_output.rb", "test/test_special_locals.rb", "test/testrc", "test/testrcbad", "wiki/Customizing-pry.md", "wiki/Home.md"]
14
- s.homepage = "http://pry.github.com"
15
- s.require_paths = ["lib"]
16
- s.rubygems_version = "1.8.11"
17
- s.summary = "An IRB alternative and runtime developer console"
18
- s.test_files = ["test/helper.rb", "test/test_command_helpers.rb", "test/test_command_processor.rb", "test/test_command_set.rb", "test/test_completion.rb", "test/test_default_commands.rb", "test/test_default_commands/test_context.rb", "test/test_default_commands/test_documentation.rb", "test/test_default_commands/test_gems.rb", "test/test_default_commands/test_input.rb", "test/test_default_commands/test_introspection.rb", "test/test_default_commands/test_ls.rb", "test/test_default_commands/test_shell.rb", "test/test_exception_whitelist.rb", "test/test_history_array.rb", "test/test_indent.rb", "test/test_input_stack.rb", "test/test_method.rb", "test/test_pry.rb", "test/test_pry_history.rb", "test/test_pry_output.rb", "test/test_special_locals.rb", "test/testrc", "test/testrcbad"]
7
+ s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
8
+ s.authors = [%q{John Mair (banisterfiend)}]
9
+ s.date = %q{2012-01-20}
10
+ s.description = %q{An IRB alternative and runtime developer console}
11
+ s.email = %q{jrmair@gmail.com}
12
+ s.executables = [%q{pry}]
13
+ s.files = [%q{.document}, %q{.gemtest}, %q{.gitignore}, %q{.travis.yml}, %q{.yardopts}, %q{CHANGELOG}, %q{CONTRIBUTORS}, %q{Gemfile}, %q{LICENSE}, %q{README.markdown}, %q{Rakefile}, %q{TODO}, %q{bin/pry}, %q{examples/example_basic.rb}, %q{examples/example_command_override.rb}, %q{examples/example_commands.rb}, %q{examples/example_hooks.rb}, %q{examples/example_image_edit.rb}, %q{examples/example_input.rb}, %q{examples/example_input2.rb}, %q{examples/example_output.rb}, %q{examples/example_print.rb}, %q{examples/example_prompt.rb}, %q{examples/helper.rb}, %q{lib/pry.rb}, %q{lib/pry/cli.rb}, %q{lib/pry/code.rb}, %q{lib/pry/command.rb}, %q{lib/pry/command_set.rb}, %q{lib/pry/commands.rb}, %q{lib/pry/completion.rb}, %q{lib/pry/config.rb}, %q{lib/pry/core_extensions.rb}, %q{lib/pry/custom_completions.rb}, %q{lib/pry/default_commands/basic.rb}, %q{lib/pry/default_commands/context.rb}, %q{lib/pry/default_commands/documentation.rb}, %q{lib/pry/default_commands/easter_eggs.rb}, %q{lib/pry/default_commands/gems.rb}, %q{lib/pry/default_commands/input.rb}, %q{lib/pry/default_commands/introspection.rb}, %q{lib/pry/default_commands/ls.rb}, %q{lib/pry/default_commands/shell.rb}, %q{lib/pry/extended_commands/experimental.rb}, %q{lib/pry/helpers.rb}, %q{lib/pry/helpers/base_helpers.rb}, %q{lib/pry/helpers/command_helpers.rb}, %q{lib/pry/helpers/options_helpers.rb}, %q{lib/pry/helpers/text.rb}, %q{lib/pry/history.rb}, %q{lib/pry/history_array.rb}, %q{lib/pry/hooks.rb}, %q{lib/pry/indent.rb}, %q{lib/pry/method.rb}, %q{lib/pry/plugins.rb}, %q{lib/pry/pry_class.rb}, %q{lib/pry/pry_instance.rb}, %q{lib/pry/rbx_method.rb}, %q{lib/pry/rbx_path.rb}, %q{lib/pry/version.rb}, %q{lib/pry/wrapped_module.rb}, %q{man/pry.1}, %q{man/pry.1.html}, %q{man/pry.1.ronn}, %q{pry.gemspec}, %q{test/helper.rb}, %q{test/test_cli.rb}, %q{test/test_code.rb}, %q{test/test_command.rb}, %q{test/test_command_helpers.rb}, %q{test/test_command_integration.rb}, %q{test/test_command_set.rb}, %q{test/test_completion.rb}, %q{test/test_default_commands.rb}, %q{test/test_default_commands/test_context.rb}, %q{test/test_default_commands/test_documentation.rb}, %q{test/test_default_commands/test_gems.rb}, %q{test/test_default_commands/test_input.rb}, %q{test/test_default_commands/test_introspection.rb}, %q{test/test_default_commands/test_ls.rb}, %q{test/test_default_commands/test_shell.rb}, %q{test/test_exception_whitelist.rb}, %q{test/test_history_array.rb}, %q{test/test_hooks.rb}, %q{test/test_indent.rb}, %q{test/test_input_stack.rb}, %q{test/test_method.rb}, %q{test/test_pry.rb}, %q{test/test_pry_defaults.rb}, %q{test/test_pry_history.rb}, %q{test/test_pry_output.rb}, %q{test/test_special_locals.rb}, %q{test/test_syntax_checking.rb}, %q{test/test_wrapped_module.rb}, %q{test/testrc}, %q{test/testrcbad}, %q{wiki/Customizing-pry.md}, %q{wiki/Home.md}]
14
+ s.homepage = %q{http://pry.github.com}
15
+ s.require_paths = [%q{lib}]
16
+ s.rubygems_version = %q{1.8.6}
17
+ s.summary = %q{An IRB alternative and runtime developer console}
18
+ s.test_files = [%q{test/helper.rb}, %q{test/test_cli.rb}, %q{test/test_code.rb}, %q{test/test_command.rb}, %q{test/test_command_helpers.rb}, %q{test/test_command_integration.rb}, %q{test/test_command_set.rb}, %q{test/test_completion.rb}, %q{test/test_default_commands.rb}, %q{test/test_default_commands/test_context.rb}, %q{test/test_default_commands/test_documentation.rb}, %q{test/test_default_commands/test_gems.rb}, %q{test/test_default_commands/test_input.rb}, %q{test/test_default_commands/test_introspection.rb}, %q{test/test_default_commands/test_ls.rb}, %q{test/test_default_commands/test_shell.rb}, %q{test/test_exception_whitelist.rb}, %q{test/test_history_array.rb}, %q{test/test_hooks.rb}, %q{test/test_indent.rb}, %q{test/test_input_stack.rb}, %q{test/test_method.rb}, %q{test/test_pry.rb}, %q{test/test_pry_defaults.rb}, %q{test/test_pry_history.rb}, %q{test/test_pry_output.rb}, %q{test/test_special_locals.rb}, %q{test/test_syntax_checking.rb}, %q{test/test_wrapped_module.rb}, %q{test/testrc}, %q{test/testrcbad}]
19
19
 
20
20
  if s.respond_to? :specification_version then
21
21
  s.specification_version = 3
22
22
 
23
23
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
24
- s.add_runtime_dependency(%q<ruby_parser>, [">= 2.3.1"])
25
- s.add_runtime_dependency(%q<coderay>, ["~> 0.9.8"])
26
- s.add_runtime_dependency(%q<slop>, ["~> 2.1.0"])
27
- s.add_runtime_dependency(%q<method_source>, ["~> 0.6.7"])
28
- s.add_development_dependency(%q<bacon>, ["~> 1.1.0"])
29
- s.add_development_dependency(%q<open4>, ["~> 1.0.1"])
24
+ s.add_runtime_dependency(%q<coderay>, ["~> 1.0.5"])
25
+ s.add_runtime_dependency(%q<slop>, ["< 3", ">= 2.4.3"])
26
+ s.add_runtime_dependency(%q<method_source>, ["~> 0.7"])
27
+ s.add_development_dependency(%q<bacon>, ["~> 1.1"])
28
+ s.add_development_dependency(%q<open4>, ["~> 1.3"])
30
29
  s.add_development_dependency(%q<rake>, ["~> 0.9"])
31
30
  else
32
- s.add_dependency(%q<ruby_parser>, [">= 2.3.1"])
33
- s.add_dependency(%q<coderay>, ["~> 0.9.8"])
34
- s.add_dependency(%q<slop>, ["~> 2.1.0"])
35
- s.add_dependency(%q<method_source>, ["~> 0.6.7"])
36
- s.add_dependency(%q<bacon>, ["~> 1.1.0"])
37
- s.add_dependency(%q<open4>, ["~> 1.0.1"])
31
+ s.add_dependency(%q<coderay>, ["~> 1.0.5"])
32
+ s.add_dependency(%q<slop>, ["< 3", ">= 2.4.3"])
33
+ s.add_dependency(%q<method_source>, ["~> 0.7"])
34
+ s.add_dependency(%q<bacon>, ["~> 1.1"])
35
+ s.add_dependency(%q<open4>, ["~> 1.3"])
38
36
  s.add_dependency(%q<rake>, ["~> 0.9"])
39
37
  end
40
38
  else
41
- s.add_dependency(%q<ruby_parser>, [">= 2.3.1"])
42
- s.add_dependency(%q<coderay>, ["~> 0.9.8"])
43
- s.add_dependency(%q<slop>, ["~> 2.1.0"])
44
- s.add_dependency(%q<method_source>, ["~> 0.6.7"])
45
- s.add_dependency(%q<bacon>, ["~> 1.1.0"])
46
- s.add_dependency(%q<open4>, ["~> 1.0.1"])
39
+ s.add_dependency(%q<coderay>, ["~> 1.0.5"])
40
+ s.add_dependency(%q<slop>, ["< 3", ">= 2.4.3"])
41
+ s.add_dependency(%q<method_source>, ["~> 0.7"])
42
+ s.add_dependency(%q<bacon>, ["~> 1.1"])
43
+ s.add_dependency(%q<open4>, ["~> 1.3"])
47
44
  s.add_dependency(%q<rake>, ["~> 0.9"])
48
45
  end
49
46
  end
data/test/helper.rb CHANGED
@@ -3,11 +3,16 @@ unless Object.const_defined? 'Pry'
3
3
  require 'pry'
4
4
  end
5
5
 
6
- puts "Ruby v#{RUBY_VERSION} (#{defined?(RUBY_ENGINE) ? RUBY_ENGINE : "ruby"}), Pry v#{Pry::VERSION}, method_source v#{MethodSource::VERSION}, CodeRay v#{CodeRay::VERSION}"
6
+ puts "Ruby v#{RUBY_VERSION} (#{defined?(RUBY_ENGINE) ? RUBY_ENGINE : "ruby"}), Pry v#{Pry::VERSION}, method_source v#{MethodSource::VERSION}, CodeRay v#{CodeRay::VERSION}, Slop v#{Slop::VERSION}"
7
7
 
8
8
  require 'bacon'
9
9
  require 'open4'
10
10
 
11
+
12
+ # turn warnings off (esp for Pry::Hooks which will generate warnings
13
+ # in tests)
14
+ $VERBOSE = nil
15
+
11
16
  # Ensure we do not execute any rc files
12
17
  Pry::RC_FILES.clear
13
18
 
@@ -21,41 +26,21 @@ class << Pry
21
26
  Pry.color = false
22
27
  Pry.pager = false
23
28
  Pry.config.should_load_rc = false
24
- Pry.config.plugins.enabled = false
29
+ Pry.config.should_load_plugins = false
25
30
  Pry.config.history.should_load = false
26
31
  Pry.config.history.should_save = false
27
32
  Pry.config.auto_indent = false
28
- Pry.config.hooks = { }
33
+ Pry.config.hooks = Pry::Hooks.new
34
+ Pry.config.collision_warning = false
29
35
  end
30
36
  end
31
37
 
32
- class MockPryException
33
- attr_accessor :bt_index
34
- attr_accessor :backtrace
35
-
36
- def initialize(*backtrace)
37
- @backtrace = backtrace
38
- @bt_index = 0
39
- end
40
-
41
- def message
42
- "mock exception"
38
+ def mock_exception(*mock_backtrace)
39
+ e = StandardError.new("mock exception")
40
+ (class << e; self; end).class_eval do
41
+ define_method(:backtrace) { mock_backtrace }
43
42
  end
44
-
45
- def bt_source_location_for(index)
46
- backtrace[index] =~ /(.*):(\d+)/
47
- [$1, $2.to_i]
48
- end
49
- end
50
-
51
- # are we on Jruby platform?
52
- def jruby?
53
- defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /jruby/
54
- end
55
-
56
- # are we on rbx platform?
57
- def rbx?
58
- defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /rbx/
43
+ e
59
44
  end
60
45
 
61
46
  Pry.reset_defaults
@@ -107,6 +92,12 @@ def mock_pry(*args)
107
92
  output.string
108
93
  end
109
94
 
95
+ def mock_command(cmd, args=[], opts={})
96
+ output = StringIO.new
97
+ ret = cmd.new(opts.merge(:output => output)).call_safely(*args)
98
+ Struct.new(:output, :return).new(output.string, ret)
99
+ end
100
+
110
101
  def redirect_global_pry_input(new_io)
111
102
  old_io = Pry.input
112
103
  Pry.input = new_io
@@ -135,15 +126,12 @@ end
135
126
 
136
127
  class InputTester
137
128
  def initialize(*actions)
138
- if actions.last.is_a?(Hash) && actions.last.keys == [:history]
139
- @hist = actions.pop[:history]
140
- end
141
129
  @orig_actions = actions.dup
142
130
  @actions = actions
143
131
  end
144
132
 
145
133
  def readline(*)
146
- @actions.shift.tap{ |line| @hist << line if @hist }
134
+ @actions.shift
147
135
  end
148
136
 
149
137
  def rewind
@@ -162,11 +150,11 @@ end
162
150
 
163
151
  # Open a temp file and yield it to the block, closing it after
164
152
  # @return [String] The path of the temp file
165
- def temp_file
166
- file = Tempfile.new("tmp")
153
+ def temp_file(ext='.rb')
154
+ file = Tempfile.new(['pry', ext])
167
155
  yield file
168
156
  ensure
169
- file.close
157
+ file.close(true) if file
170
158
  end
171
159
 
172
160
 
@@ -179,3 +167,11 @@ CommandTester = Pry::CommandSet.new do
179
167
  output.puts arg
180
168
  end
181
169
  end
170
+
171
+ # to help with tracking down bugs that cause an infinite loop in the test suite
172
+ if ENV["SET_TRACE_FUNC"]
173
+ require 'set_trace' if Pry::Helpers::BaseHelpers.rbx?
174
+ set_trace_func proc { |event, file, line, id, binding, classname|
175
+ STDERR.printf "%8s %s:%-2d %10s %8s\n", event, file, line, id, classname
176
+ }
177
+ end
data/test/test_cli.rb ADDED
@@ -0,0 +1,78 @@
1
+ require 'helper'
2
+
3
+ describe Pry::Hooks do
4
+ before do
5
+ Pry::CLI.reset
6
+ end
7
+
8
+ describe "parsing options" do
9
+ it 'should raise if no options defined' do
10
+ lambda { Pry::CLI.parse_options(["--nothing"]) }.should.raise Pry::CLI::NoOptionsError
11
+ end
12
+ end
13
+
14
+ describe "adding options" do
15
+ it "should be able to add an option" do
16
+ run = false
17
+
18
+ Pry::CLI.add_options do
19
+ on :optiontest, "A test option" do
20
+ run = true
21
+ end
22
+ end.parse_options(["--optiontest"])
23
+
24
+ run.should == true
25
+ end
26
+
27
+ it "should be able to add multiple options" do
28
+ run = false
29
+ run2 = false
30
+
31
+ Pry::CLI.add_options do
32
+ on :optiontest, "A test option" do
33
+ run = true
34
+ end
35
+ end.add_options do
36
+ on :optiontest2, "Another test option" do
37
+ run2 = true
38
+ end
39
+ end.parse_options(["--optiontest", "--optiontest2"])
40
+
41
+ run.should == true
42
+ run2.should == true
43
+ end
44
+
45
+ end
46
+
47
+ describe "processing options" do
48
+ it "should be able to process an option" do
49
+ run = false
50
+
51
+ Pry::CLI.add_options do
52
+ on :optiontest, "A test option"
53
+ end.process_options do |opts|
54
+ run = true if opts.present?(:optiontest)
55
+ end.parse_options(["--optiontest"])
56
+
57
+ run.should == true
58
+ end
59
+
60
+ it "should be able to process multiple options" do
61
+ run = false
62
+ run2 = false
63
+
64
+ Pry::CLI.add_options do
65
+ on :optiontest, "A test option"
66
+ on :optiontest2, "Another test option"
67
+ end.process_options do |opts|
68
+ run = true if opts.present?(:optiontest)
69
+ end.process_options do |opts|
70
+ run2 = true if opts.present?(:optiontest2)
71
+ end.parse_options(["--optiontest", "--optiontest2"])
72
+
73
+ run.should == true
74
+ run2.should == true
75
+ end
76
+
77
+ end
78
+ end
data/test/test_code.rb ADDED
@@ -0,0 +1,201 @@
1
+ require 'helper'
2
+
3
+ describe Pry::Code do
4
+ describe '.from_file' do
5
+ should 'read lines from a file on disk' do
6
+ Pry::Code.from_file('lib/pry.rb').length.should > 0
7
+ end
8
+
9
+ should 'read lines from Pry\'s line buffer' do
10
+ mock_pry(':hay_guys')
11
+ Pry::Code.from_file('(pry)').grep(/:hay_guys/).length.should == 1
12
+ end
13
+
14
+ should 'default to Ruby' do
15
+ temp_file('') do |f|
16
+ Pry::Code.from_file(f.path).code_type.should == :ruby
17
+ end
18
+ end
19
+
20
+ should 'check the extension' do
21
+ temp_file('.c') do |f|
22
+ Pry::Code.from_file(f.path).code_type.should == :c
23
+ end
24
+ end
25
+
26
+ should 'raise an error if the file doesn\'t exist' do
27
+ proc do
28
+ Pry::Code.from_file('/knalkjsdnalsd/alkjdlkq')
29
+ end.should.raise(Pry::CommandError)
30
+ end
31
+ end
32
+
33
+ describe '.from_method' do
34
+ should 'read lines from a method\'s definition' do
35
+ m = Pry::Method.from_obj(Pry, :load_history)
36
+ Pry::Code.from_method(m).length.should > 0
37
+ end
38
+ end
39
+
40
+ describe '#initialize' do
41
+ before do
42
+ @str = Pry::Helpers::CommandHelpers.unindent <<-CODE
43
+ def hay
44
+ :guys
45
+ end
46
+ CODE
47
+
48
+ @array = ['def hay', ' :guys', 'end']
49
+ end
50
+
51
+ should 'break a string into lines' do
52
+ Pry::Code.new(@str).length.should == 3
53
+ end
54
+
55
+ should 'accept an array' do
56
+ Pry::Code.new(@array).length.should == 3
57
+ end
58
+
59
+ it 'an array or string should produce an equivalent object' do
60
+ Pry::Code.new(@str).should == Pry::Code.new(@array)
61
+ end
62
+ end
63
+
64
+ describe 'filters and formatters' do
65
+ before do
66
+ @code = Pry::Code(Pry::Helpers::CommandHelpers.unindent <<-STR)
67
+ class MyProgram
68
+ def self.main
69
+ puts 'Hello, world!'
70
+ end
71
+ end
72
+ STR
73
+ end
74
+
75
+ describe 'filters' do
76
+ describe '#between' do
77
+ should 'work with an inclusive range' do
78
+ @code = @code.between(1..3)
79
+ @code.length.should == 3
80
+ @code.should =~ /\Aclass MyProgram/
81
+ @code.should =~ /world!'\Z/
82
+ end
83
+
84
+ should 'default to an inclusive range' do
85
+ @code = @code.between(3, 5)
86
+ @code.length.should == 3
87
+ end
88
+
89
+ should 'work with an exclusive range' do
90
+ @code = @code.between(2...4)
91
+ @code.length.should == 2
92
+ @code.should =~ /\A def self/
93
+ @code.should =~ /world!'\Z/
94
+ end
95
+
96
+ should 'use real line numbers for positive indices' do
97
+ @code = @code.after(3, 3)
98
+ @code = @code.between(4, 4)
99
+ @code.length.should == 1
100
+ @code.should =~ /\A end\Z/
101
+ end
102
+ end
103
+
104
+ describe '#before' do
105
+ should 'work' do
106
+ @code = @code.before(3, 1)
107
+ @code.should =~ /\A def self\.main\Z/
108
+ end
109
+ end
110
+
111
+ describe '#around' do
112
+ should 'work' do
113
+ @code = @code.around(3, 1)
114
+ @code.length.should == 3
115
+ @code.should =~ /\A def self/
116
+ @code.should =~ / end\Z/
117
+ end
118
+ end
119
+
120
+ describe '#after' do
121
+ should 'work' do
122
+ @code = @code.after(3, 1)
123
+ @code.should =~ /\A end\Z/
124
+ end
125
+ end
126
+
127
+ describe '#grep' do
128
+ should 'work' do
129
+ @code = @code.grep(/end/)
130
+ @code.length.should == 2
131
+ end
132
+ end
133
+ end
134
+
135
+ describe 'formatters' do
136
+ describe '#with_line_numbers' do
137
+ should 'show line numbers' do
138
+ @code = @code.with_line_numbers
139
+ @code.should =~ /1:/
140
+ end
141
+
142
+ should 'disable line numbers when falsy' do
143
+ @code = @code.with_line_numbers
144
+ @code = @code.with_line_numbers(false)
145
+ @code.should.not =~ /1:/
146
+ end
147
+ end
148
+
149
+ describe '#with_marker' do
150
+ should 'show a marker in the right place' do
151
+ @code = @code.with_marker(2)
152
+ @code.should =~ /^ => def self/
153
+ end
154
+
155
+ should 'disable the marker when falsy' do
156
+ @code = @code.with_marker(2)
157
+ @code = @code.with_marker(false)
158
+ @code.should =~ /^ def self/
159
+ end
160
+ end
161
+
162
+ describe '#with_indentation' do
163
+ should 'indent the text' do
164
+ @code = @code.with_indentation(2)
165
+ @code.should =~ /^ def self/
166
+ end
167
+
168
+ should 'disable the indentation when falsy' do
169
+ @code = @code.with_indentation(2)
170
+ @code = @code.with_indentation(false)
171
+ @code.should =~ /^ def self/
172
+ end
173
+ end
174
+ end
175
+
176
+ describe 'composition' do
177
+ describe 'grep and with_line_numbers' do
178
+ should 'work' do
179
+ @code = @code.grep(/end/).with_line_numbers
180
+ @code.should =~ /\A4: end/
181
+ @code.should =~ /5: end\Z/
182
+ end
183
+ end
184
+
185
+ describe 'grep and before and with_line_numbers' do
186
+ should 'work' do
187
+ @code = @code.grep(/e/).before(5, 5).with_line_numbers
188
+ @code.should =~ /\A2: def self.main\n3:/
189
+ @code.should =~ /4: end\Z/
190
+ end
191
+ end
192
+
193
+ describe 'before and after' do
194
+ should 'work' do
195
+ @code = @code.before(4, 2).after(2)
196
+ @code.should == " puts 'Hello, world!'"
197
+ end
198
+ end
199
+ end
200
+ end
201
+ end