pry 0.9.7.4 → 0.9.8pre2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/.gitignore +1 -3
  2. data/README.markdown +3 -1
  3. data/Rakefile +48 -31
  4. data/bin/pry +2 -80
  5. data/lib/pry.rb +17 -20
  6. data/lib/pry/cli.rb +152 -0
  7. data/lib/pry/command_processor.rb +13 -0
  8. data/lib/pry/command_set.rb +102 -9
  9. data/lib/pry/config.rb +28 -6
  10. data/lib/pry/default_commands/context.rb +9 -8
  11. data/lib/pry/default_commands/documentation.rb +55 -13
  12. data/lib/pry/default_commands/easter_eggs.rb +1 -1
  13. data/lib/pry/default_commands/input.rb +25 -25
  14. data/lib/pry/default_commands/introspection.rb +19 -18
  15. data/lib/pry/default_commands/ls.rb +23 -38
  16. data/lib/pry/default_commands/shell.rb +47 -15
  17. data/lib/pry/helpers/command_helpers.rb +28 -6
  18. data/lib/pry/helpers/options_helpers.rb +7 -4
  19. data/lib/pry/helpers/text.rb +23 -3
  20. data/lib/pry/history.rb +55 -17
  21. data/lib/pry/history_array.rb +2 -0
  22. data/lib/pry/hooks.rb +108 -0
  23. data/lib/pry/indent.rb +9 -5
  24. data/lib/pry/method.rb +99 -50
  25. data/lib/pry/plugins.rb +10 -2
  26. data/lib/pry/pry_class.rb +48 -20
  27. data/lib/pry/pry_instance.rb +106 -91
  28. data/lib/pry/version.rb +1 -1
  29. data/lib/pry/wrapped_module.rb +73 -0
  30. data/man/pry.1 +195 -0
  31. data/man/pry.1.html +204 -0
  32. data/man/pry.1.ronn +141 -0
  33. data/pry.gemspec +21 -24
  34. data/test/helper.rb +12 -3
  35. data/test/test_cli.rb +78 -0
  36. data/test/test_command_set.rb +193 -1
  37. data/test/test_default_commands/test_context.rb +19 -4
  38. data/test/test_default_commands/test_input.rb +2 -2
  39. data/test/test_default_commands/test_introspection.rb +63 -6
  40. data/test/test_default_commands/test_ls.rb +8 -35
  41. data/test/test_default_commands/test_shell.rb +36 -1
  42. data/test/test_hooks.rb +175 -0
  43. data/test/test_indent.rb +2 -0
  44. data/test/test_method.rb +10 -0
  45. data/test/test_pry.rb +35 -34
  46. data/test/test_pry_history.rb +24 -24
  47. data/test/test_syntax_checking.rb +47 -0
  48. data/test/test_wrapped_module.rb +71 -0
  49. metadata +40 -34
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
@@ -2,48 +2,45 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "pry"
5
- s.version = "0.9.7.4"
5
+ s.version = "0.9.8.0pre1"
6
6
 
7
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
7
+ s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["John Mair (banisterfiend)"]
9
- s.date = "2011-11-05"
9
+ s.date = "2011-12-17"
10
10
  s.description = "An IRB alternative and runtime developer console"
11
11
  s.email = "jrmair@gmail.com"
12
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"]
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/cli.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/hooks.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", "lib/pry/wrapped_module.rb", "man/pry.1", "man/pry.1.html", "man/pry.1.ronn", "pry.gemspec", "test/helper.rb", "test/test_cli.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_hooks.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/test_syntax_checking.rb", "test/test_wrapped_module.rb", "test/testrc", "test/testrcbad", "wiki/Customizing-pry.md", "wiki/Home.md"]
14
14
  s.homepage = "http://pry.github.com"
15
15
  s.require_paths = ["lib"]
16
- s.rubygems_version = "1.8.11"
16
+ s.rubygems_version = "1.8.10"
17
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"]
18
+ s.test_files = ["test/helper.rb", "test/test_cli.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_hooks.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/test_syntax_checking.rb", "test/test_wrapped_module.rb", "test/testrc", "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>, ["~> 0.9"])
25
+ s.add_runtime_dependency(%q<slop>, ["< 3", ">= 2.4.1"])
26
+ s.add_runtime_dependency(%q<method_source>, ["~> 0.6"])
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>, ["~> 0.9"])
32
+ s.add_dependency(%q<slop>, ["< 3", ">= 2.4.1"])
33
+ s.add_dependency(%q<method_source>, ["~> 0.6"])
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>, ["~> 0.9"])
40
+ s.add_dependency(%q<slop>, ["< 3", ">= 2.4.1"])
41
+ s.add_dependency(%q<method_source>, ["~> 0.6"])
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,7 +3,7 @@ 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'
@@ -25,7 +25,8 @@ class << Pry
25
25
  Pry.config.history.should_load = false
26
26
  Pry.config.history.should_save = false
27
27
  Pry.config.auto_indent = false
28
- Pry.config.hooks = { }
28
+ Pry.config.hooks = Pry::Hooks.new
29
+ Pry.config.collision_warning = false
29
30
  end
30
31
  end
31
32
 
@@ -163,7 +164,7 @@ end
163
164
  # Open a temp file and yield it to the block, closing it after
164
165
  # @return [String] The path of the temp file
165
166
  def temp_file
166
- file = Tempfile.new("tmp")
167
+ file = Tempfile.new('pry')
167
168
  yield file
168
169
  ensure
169
170
  file.close
@@ -179,3 +180,11 @@ CommandTester = Pry::CommandSet.new do
179
180
  output.puts arg
180
181
  end
181
182
  end
183
+
184
+ # to help with tracking down bugs that cause an infinite loop in the test suite
185
+ if ENV["SET_TRACE_FUNC"]
186
+ require 'set_trace' if defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /rbx/ # gem install 'rbx-tracer'
187
+ set_trace_func proc { |event, file, line, id, binding, classname|
188
+ STDERR.printf "%8s %s:%-2d %10s %8s\n", event, file, line, id, classname
189
+ }
190
+ 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
@@ -50,6 +50,15 @@ describe Pry::CommandSet do
50
50
  }.should.raise(Pry::NoCommandError)
51
51
  end
52
52
 
53
+ it 'should be able to remove its own commands, by listing name' do
54
+ @set.command(/^foo1/, 'desc', :listing => 'foo') {}
55
+ @set.delete 'foo'
56
+
57
+ lambda {
58
+ @set.run_command @ctx, /^foo1/
59
+ }.should.raise(Pry::NoCommandError)
60
+ end
61
+
53
62
  it 'should be able to import some commands from other sets' do
54
63
  run = false
55
64
 
@@ -68,6 +77,19 @@ describe Pry::CommandSet do
68
77
  }.should.raise(Pry::NoCommandError)
69
78
  end
70
79
 
80
+ it 'should be able to import some commands from other sets using listing name' do
81
+ run = false
82
+
83
+ other_set = Pry::CommandSet.new do
84
+ command(/^foo1/, 'desc', :listing => 'foo') { run = true }
85
+ end
86
+
87
+ @set.import_from(other_set, 'foo')
88
+
89
+ @set.run_command @ctx, /^foo1/
90
+ run.should == true
91
+ end
92
+
71
93
  it 'should be able to import a whole set' do
72
94
  run = []
73
95
 
@@ -108,13 +130,35 @@ describe Pry::CommandSet do
108
130
  run.should == true
109
131
  end
110
132
 
111
- it 'should be able to change the descritpions of methods' do
133
+ it "should be able to alias a method by the command's listing name" do
134
+ run = false
135
+ @set.command(/^foo1/, 'stuff', :listing => 'foo') { run = true }
136
+
137
+ @set.alias_command 'bar', 'foo'
138
+ @set.commands['bar'].name.should == 'bar'
139
+ @set.commands['bar'].description.should == ''
140
+
141
+ @set.run_command @ctx, 'bar'
142
+ run.should == true
143
+ end
144
+
145
+ it 'should be able to change the descriptions of commands' do
112
146
  @set.command('foo', 'bar') {}
113
147
  @set.desc 'foo', 'baz'
114
148
 
115
149
  @set.commands['foo'].description.should == 'baz'
116
150
  end
117
151
 
152
+ it 'should get the descriptions of commands' do
153
+ @set.command('foo', 'bar') {}
154
+ @set.desc('foo').should == 'bar'
155
+ end
156
+
157
+ it 'should get the descriptions of commands, by listing' do
158
+ @set.command(/^foo1/, 'bar', :listing => 'foo') {}
159
+ @set.desc('foo').should == 'bar'
160
+ end
161
+
118
162
  it 'should return Pry::CommandContext::VOID_VALUE for commands by default' do
119
163
  @set.command('foo') { 3 }
120
164
  @set.run_command(@ctx, 'foo').should == Pry::CommandContext::VOID_VALUE
@@ -226,4 +270,152 @@ describe Pry::CommandSet do
226
270
 
227
271
  order.should == order.sort
228
272
  end
273
+
274
+ describe "renaming a command" do
275
+ it 'should be able to rename and run a command' do
276
+ run = false
277
+ @set.command('foo') { run = true }
278
+ @set.rename_command('bar', 'foo')
279
+ @set.run_command(@ctx, 'bar')
280
+ run.should == true
281
+ end
282
+
283
+ it 'should accept listing name when renaming a command' do
284
+ run = false
285
+ @set.command('foo', "", :listing => 'love') { run = true }
286
+ @set.rename_command('bar', 'love')
287
+ @set.run_command(@ctx, 'bar')
288
+ run.should == true
289
+ end
290
+
291
+ it 'should raise exception trying to rename non-existent command' do
292
+ lambda { @set.rename_command('bar', 'foo') }.should.raise ArgumentError
293
+ end
294
+
295
+ it 'should make old command name inaccessible' do
296
+ @set.command('foo') { }
297
+ @set.rename_command('bar', 'foo')
298
+ lambda { @set.run_command(@ctx, 'foo') }.should.raise Pry::NoCommandError
299
+ end
300
+
301
+
302
+ it 'should be able to pass in options when renaming command' do
303
+ desc = "hello"
304
+ listing = "bing"
305
+ @set.command('foo') { }
306
+ @set.rename_command('bar', 'foo', :description => desc, :listing => listing, :keep_retval => true)
307
+ @set.commands['bar'].description.should == desc
308
+ @set.commands['bar'].options[:listing].should == listing
309
+ @set.commands['bar'].options[:keep_retval].should == true
310
+ end
311
+ end
312
+
313
+ describe "command decorators - before_command and after_command" do
314
+ describe "before_command" do
315
+ it 'should be called before the original command' do
316
+ foo = []
317
+ @set.command('foo') { foo << 1 }
318
+ @set.before_command('foo') { foo << 2 }
319
+ @set.run_command(@ctx, 'foo')
320
+
321
+ foo.should == [2, 1]
322
+ end
323
+
324
+ it 'should be called before the original command, using listing name' do
325
+ foo = []
326
+ @set.command(/^foo1/, '', :listing => 'foo') { foo << 1 }
327
+ @set.before_command('foo') { foo << 2 }
328
+ @set.run_command(@ctx, /^foo1/)
329
+
330
+ foo.should == [2, 1]
331
+ end
332
+
333
+ it 'should share the context with the original command' do
334
+ @ctx.target = "test target string"
335
+ before_val = nil
336
+ orig_val = nil
337
+ @set.command('foo') { orig_val = target }
338
+ @set.before_command('foo') { before_val = target }
339
+ @set.run_command(@ctx, 'foo')
340
+
341
+ before_val.should == @ctx.target
342
+ orig_val.should == @ctx.target
343
+ end
344
+
345
+ it 'should work when applied multiple times' do
346
+ foo = []
347
+ @set.command('foo') { foo << 1 }
348
+ @set.before_command('foo') { foo << 2 }
349
+ @set.before_command('foo') { foo << 3 }
350
+ @set.before_command('foo') { foo << 4 }
351
+ @set.run_command(@ctx, 'foo')
352
+
353
+ foo.should == [4, 3, 2, 1]
354
+ end
355
+
356
+ end
357
+
358
+ describe "after_command" do
359
+ it 'should be called after the original command' do
360
+ foo = []
361
+ @set.command('foo') { foo << 1 }
362
+ @set.after_command('foo') { foo << 2 }
363
+ @set.run_command(@ctx, 'foo')
364
+
365
+ foo.should == [1, 2]
366
+ end
367
+
368
+ it 'should be called after the original command, using listing name' do
369
+ foo = []
370
+ @set.command(/^foo1/, '', :listing => 'foo') { foo << 1 }
371
+ @set.after_command('foo') { foo << 2 }
372
+ @set.run_command(@ctx, /^foo1/)
373
+
374
+ foo.should == [1, 2]
375
+ end
376
+
377
+ it 'should share the context with the original command' do
378
+ @ctx.target = "test target string"
379
+ after_val = nil
380
+ orig_val = nil
381
+ @set.command('foo') { orig_val = target }
382
+ @set.after_command('foo') { after_val = target }
383
+ @set.run_command(@ctx, 'foo')
384
+
385
+ after_val.should == @ctx.target
386
+ orig_val.should == @ctx.target
387
+ end
388
+
389
+ it 'should determine the return value for the command' do
390
+ @set.command('foo', 'bar', :keep_retval => true) { 1 }
391
+ @set.after_command('foo') { 2 }
392
+ @set.run_command(@ctx, 'foo').should == 2
393
+ end
394
+
395
+ it 'should work when applied multiple times' do
396
+ foo = []
397
+ @set.command('foo') { foo << 1 }
398
+ @set.after_command('foo') { foo << 2 }
399
+ @set.after_command('foo') { foo << 3 }
400
+ @set.after_command('foo') { foo << 4 }
401
+ @set.run_command(@ctx, 'foo')
402
+
403
+ foo.should == [1, 2, 3, 4]
404
+ end
405
+ end
406
+
407
+ describe "before_command and after_command" do
408
+ it 'should work when combining both before_command and after_command' do
409
+ foo = []
410
+ @set.command('foo') { foo << 1 }
411
+ @set.after_command('foo') { foo << 2 }
412
+ @set.before_command('foo') { foo << 3 }
413
+ @set.run_command(@ctx, 'foo')
414
+
415
+ foo.should == [3, 1, 2]
416
+ end
417
+
418
+ end
419
+
420
+ end
229
421
  end