ripl-fresh 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,7 @@
1
+ == 0.2.1
2
+ * Be compatible with latest ripls
3
+ * Deactivate rocket prompt
4
+
1
5
  == 0.2.0
2
6
  * Better system command error handling
3
7
  * Refactored command mode detection, changed configuration settings
@@ -90,7 +90,9 @@ Currently, most {plugins}[http://github.com/cldwalker/ripl-color_error] {enable}
90
90
 
91
91
  There are lots of things which can get better:
92
92
 
93
+ * Refactor a little bit
93
94
  * Improve auto-completion
95
+ * RVM support possible?
94
96
  * More cool (and colorful?) <tt>:mixed</tt> Ruby commands
95
97
  * Respect "..." (single argument) for :mixed commands
96
98
  * Add tests
data/Rakefile CHANGED
@@ -14,7 +14,7 @@ end
14
14
 
15
15
  desc "Install the gem locally"
16
16
  task :install => :gem do
17
- sh %{gem install pkg/#{gemspec.name}-#{gemspec.version}}
17
+ sh %{gem install pkg/#{gemspec.name}-#{gemspec.version} --no-rdoc --no-ri}
18
18
  end
19
19
 
20
20
  desc "Generate the gemspec"
@@ -1,9 +1,10 @@
1
1
  require 'ripl'
2
+ require 'ripl/multi_line'
2
3
  require 'fileutils'
3
4
 
4
5
  module Ripl
5
6
  module Fresh
6
- VERSION = '0.2.0'
7
+ VERSION = '0.2.1'
7
8
 
8
9
  def before_loop
9
10
  @command_mode = :ruby
@@ -92,7 +93,7 @@ module Ripl
92
93
  raise( SystemCallError.new $?.exitstatus )
93
94
  end;"
94
95
 
95
- super @input = "(#{ ruby_command_code })"
96
+ super @input = ruby_command_code
96
97
 
97
98
  when :mixed # call the ruby method, but with shell style arguments TODO more shell like (e.g. "")
98
99
  method_name, *args = *input.split
@@ -116,11 +117,12 @@ module Ripl
116
117
  end
117
118
  end
118
119
 
119
- # load plugins and hook in (and work around readline loading behaviour)
120
+ # load plugins and hook in (and work around readline loading behaviour) TODO: refactor
121
+ readline = Ripl.config[:readline] == true ? 'readline' : Ripl.config[:readline]
120
122
  Ripl.config[:readline] = false
123
+ require readline
121
124
  require 'ripl/readline'
122
- require 'ripl/multi_line'
123
- Ripl::Shell.send :include, Ripl::Fresh
125
+ Ripl::Shell.include Ripl::Fresh
124
126
 
125
127
  # load :mixed commands
126
128
  require File.dirname(__FILE__) + '/fresh/commands'
@@ -131,4 +133,7 @@ require File.dirname(__FILE__) + '/fresh/config'
131
133
  # fresh_prompt management
132
134
  require File.dirname(__FILE__) + '/fresh/prompt'
133
135
 
136
+ # configure other plugins
137
+ Ripl.config[:rocket_mode] = false
138
+
134
139
  # J-_-L
@@ -0,0 +1,3 @@
1
+ bacon >=1.1.0
2
+ rr >=1.0.0
3
+ bacon-bits >=0
@@ -0,0 +1,248 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ describe "Runner" do
4
+ describe ".start" do
5
+ before { reset_ripl }
6
+
7
+ it "loads riplrc" do
8
+ mock_riplrc
9
+ mock_shell
10
+ Ripl.start
11
+ end
12
+
13
+ it "doesn't load riplrc" do
14
+ mock_shell
15
+ dont_allow(Runner).load_rc(anything)
16
+ Ripl.start :riplrc => false
17
+ end
18
+
19
+ it "sets a shell's variables" do
20
+ mock_riplrc
21
+ mock_shell
22
+ Ripl.start(:name=>'shh')
23
+ Ripl.shell.name.should == 'shh'
24
+ end
25
+
26
+ it "passes options to Ripl.config" do
27
+ mock_riplrc
28
+ mock_shell
29
+ Ripl.start(:history=>'~/.mah_history')
30
+ Ripl.config[:history].should == '~/.mah_history'
31
+ end
32
+
33
+ it "overrides config set in riplrc" do
34
+ mock_riplrc { Ripl.config[:name] = 'blah' }
35
+ mock_shell
36
+ Ripl.start(:name=>'dude')
37
+ Ripl.shell.name.should == 'dude'
38
+ end
39
+ end
40
+
41
+ describe ".run" do
42
+ describe "riplrc" do
43
+ before { reset_ripl }
44
+
45
+ it "sets config" do
46
+ mock_riplrc { Ripl.config[:blah] = true }
47
+ mock_shell
48
+ Runner.run([])
49
+ Ripl.config[:blah].should == true
50
+ end
51
+
52
+ it "catches and prints error" do
53
+ mock(Runner).load(anything) { raise SyntaxError }
54
+ mock_shell
55
+ capture_stderr { Runner.run([]) }.should =~ %r{^ripl: Error while loading ~/.riplrc:\nSyntaxError:}
56
+ end
57
+ end
58
+
59
+ describe "with subcommand" do
60
+ def set_dollar_zero(val)
61
+ $progname = $0
62
+ alias $0 $progname
63
+ $0 = val
64
+ end
65
+
66
+ def mock_exec(*args)
67
+ mock(Runner).exec('ripl-rails', *args) do
68
+ set_dollar_zero 'ripl-rails'
69
+ ARGV.replace(args)
70
+ Ripl.start
71
+ end
72
+ end
73
+
74
+ it "gets invoked with arguments" do
75
+ mock_exec 'blah'
76
+ ripl("rails", 'blah')
77
+ end
78
+
79
+ it "has -F global option parsed" do
80
+ mock_exec '-F'
81
+ dont_allow(Runner).load_rc(anything)
82
+ ripl("rails", "-F", :riplrc=>false)
83
+ end
84
+
85
+ it "saves arguments passed to it" do
86
+ mock_exec 'blah', '-F'
87
+ ripl("rails", "blah", "-F", :riplrc=>false)
88
+ Ripl::Runner.argv.should == ['blah', '-F']
89
+ end
90
+
91
+ it "has other global option parsed" do
92
+ mock_exec '-r=blah'
93
+ mock(Runner).require('blah')
94
+ ripl("rails", "-r=blah")
95
+ end
96
+
97
+ it "has automatic --help" do
98
+ mock_exec '--help'
99
+ mock(Runner).exit
100
+ ripl("rails", "--help").chomp.should == "ripl rails [OPTIONS] [ARGS]"
101
+ end
102
+
103
+ it "that is invalid aborts" do
104
+ mock(Runner).abort("`zzz' is not a ripl command.")
105
+ ripl 'zzz', :riplrc => false, :loop => false
106
+ end
107
+ after_all { set_dollar_zero 'ripl' }
108
+ end
109
+
110
+ describe "with -I option" do
111
+ before { @old_load_path = $:.dup }
112
+ after { $:.replace @old_load_path }
113
+
114
+ it "and equal sign adds to $LOAD_PATH" do
115
+ ripl("-I=blah")
116
+ $:[0].should == 'blah'
117
+ end
118
+
119
+ it "and no equal sign adds to $LOAD_PATH" do
120
+ ripl("-Ispec")
121
+ $:[0].should == 'spec'
122
+ end
123
+
124
+ it "and whitespace delimited argument adds to $LOAD_PATH" do
125
+ ripl("-I", "spec")
126
+ $:[0].should == 'spec'
127
+ end
128
+
129
+ it "containing multiple paths adds to $LOAD_PATH" do
130
+ ripl("-I=app:lib")
131
+ $:[0,2].should == ['app', 'lib']
132
+ end
133
+
134
+ it "called more than once adds to $LOAD_PATH" do
135
+ ripl("-Ilib", "-Ispec")
136
+ $:[0,2].should == ['spec', 'lib']
137
+ end
138
+
139
+ it "with invalid argument doesn't add to $LOAD_PATH" do
140
+ previous_size = $:.size
141
+ ripl("-I")
142
+ $:.size.should == previous_size
143
+ end
144
+ end
145
+
146
+ describe "with -r option" do
147
+ it "and equal sign requires path" do
148
+ mock(Runner).require('rip')
149
+ ripl("-r=rip")
150
+ end
151
+
152
+ it "and no equal sign requires path" do
153
+ mock(Runner).require('rip')
154
+ ripl("-rrip")
155
+ end
156
+
157
+ it "and whitespace delimited argument requires path" do
158
+ mock(Runner).require('rip')
159
+ ripl("-r", "rip")
160
+ end
161
+
162
+ it "called more than once requires paths" do
163
+ mock(Runner).require('rip')
164
+ mock(Runner).require('dude')
165
+ ripl("-rrip", "-rdude")
166
+ end
167
+
168
+ it "with invalid argument requires blank" do
169
+ mock(Runner).require('')
170
+ ripl('-r')
171
+ end
172
+ end
173
+
174
+ it "with -f option doesn't load irbrc" do
175
+ reset_ripl
176
+ reset_config
177
+ stub(Kernel).at_exit()
178
+ mock_shell { |shell|
179
+ mock(shell).loop_once { throw :ripl_exit }
180
+ dont_allow(Runner).load_rc(anything)
181
+ }
182
+ ripl("-f", :loop => false)
183
+ Ripl.config[:irbrc] = '~/.irbrc'
184
+ end
185
+
186
+ it "with -F option doesn't load riplrc" do
187
+ reset_ripl
188
+ dont_allow(Runner).load_rc(anything)
189
+ mock_shell { |shell|
190
+ stub(Kernel).at_exit
191
+ mock(shell).before_loop
192
+ mock(shell).loop_once { throw :ripl_exit }
193
+ }
194
+ ripl("-F", :riplrc => false, :loop => false)
195
+ end
196
+
197
+ it "with -d option sets $DEBUG" do
198
+ ripl("-d")
199
+ $DEBUG.should == true
200
+ $DEBUG = nil
201
+ end
202
+
203
+ it "with -v option prints version" do
204
+ mock(Runner).exit
205
+ ripl("-v").chomp.should == Ripl::VERSION
206
+ end
207
+
208
+ it "with -h option prints help" do
209
+ mock(Runner).exit
210
+ actual = ripl("-h")
211
+ actual.should =~ /^Usage: ripl/
212
+ actual.should =~ /Options:\n -f/
213
+ end
214
+
215
+ it "with invalid options prints errors" do
216
+ capture_stderr {
217
+ ripl('--blah', '-z')
218
+ }.chomp.should == "ripl: invalid option `blah'\nripl: invalid option `z'"
219
+ end
220
+
221
+ describe "with plugin" do
222
+ before_all do
223
+ Moo = Module.new do
224
+ def parse_option(option, argv)
225
+ option == '--moo' ? puts("MOOOO") : super
226
+ end
227
+ end
228
+ Runner.extend Moo
229
+ Runner.add_options ['--moo', 'just moos']
230
+ end
231
+
232
+ it "parses plugin option" do
233
+ ripl("--moo").chomp.should == 'MOOOO'
234
+ end
235
+
236
+ it "displays plugin option in --help" do
237
+ mock(Runner).exit
238
+ ripl("--help").should =~ /--moo\s*just moos/
239
+ end
240
+
241
+ it "handles invalid option" do
242
+ capture_stderr {
243
+ ripl('--blah')
244
+ }.chomp.should == "ripl: invalid option `blah'"
245
+ end
246
+ end
247
+ end
248
+ end
@@ -0,0 +1,121 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ describe "Shell" do
4
+ before { reset_ripl }
5
+
6
+ def shell(options={})
7
+ Ripl.shell(options)
8
+ end
9
+
10
+ describe "#loop" do
11
+ before { mock(shell).before_loop }
12
+ it "exits with exit" do
13
+ mock(shell).get_input { 'exit' }
14
+ dont_allow(shell).eval_input
15
+ shell.loop
16
+ end
17
+
18
+ it "exits with quit" do
19
+ mock(shell).get_input { 'quit' }
20
+ dont_allow(shell).eval_input
21
+ shell.loop
22
+ end
23
+
24
+ it "exits with Control-D" do
25
+ mock(shell).get_input { nil }
26
+ dont_allow(shell).eval_input
27
+ shell.loop
28
+ end
29
+ end
30
+
31
+ it "#loop_once handles Control-C" do
32
+ mock(shell).get_input { raise Interrupt }
33
+ dont_allow(shell).eval_input
34
+ capture_stdout { shell.loop_once }.should == "\n"
35
+ end
36
+
37
+ describe "#prompt" do
38
+ it "from a string" do
39
+ shell(:prompt=>'> ').prompt.should == '> '
40
+ end
41
+
42
+ it "from a lambda" do
43
+ shell(:prompt=>lambda { "#{10 + 10}> " }).prompt.should == '20> '
44
+ end
45
+
46
+ it "rescues from a failed lambda" do
47
+ capture_stderr {
48
+ shell(:prompt=>lambda { wtf }).prompt.should == Shell::OPTIONS[:prompt]
49
+ }.should =~ /ripl: Error while creating.*NameError.*`wtf'/m
50
+ end
51
+ end
52
+
53
+ describe "#before_loop" do
54
+ before_all { Ripl::Commands.send(:define_method, :ping) { 'pong' } }
55
+ before { reset_config }
56
+ it "adds commands to main from Commands" do
57
+ stub(Ripl::Runner).load_rc
58
+ stub(Kernel).at_exit
59
+ Ripl.shell.before_loop
60
+ Ripl.shell.loop_eval("ping").should == 'pong'
61
+ end
62
+
63
+ it "adds commands to fixnum from Commands" do
64
+ stub(Ripl::Runner).load_rc
65
+ Ripl.shell.binding = 1.send(:binding)
66
+ stub(Kernel).at_exit
67
+ Ripl.shell.before_loop
68
+ Ripl.shell.loop_eval("ping").should == 'pong'
69
+ end
70
+ end
71
+
72
+ describe "#eval_input" do
73
+ before { @line = shell.line; shell.eval_input("10 ** 2") }
74
+
75
+ describe "normally" do
76
+ it "sets result" do
77
+ shell.result.should == 100
78
+ end
79
+
80
+ it "sets _" do
81
+ shell.eval_input('_')
82
+ shell.result.should == 100
83
+ end
84
+
85
+ it "increments line" do
86
+ shell.line.should == @line + 1
87
+ end
88
+ end
89
+
90
+ describe "with error" do
91
+ before {
92
+ @line = shell.line
93
+ @stderr = capture_stderr { shell.eval_input('{') }
94
+ }
95
+
96
+ it "prints it" do
97
+ # 1.8 # 1.9
98
+ @stderr.should =~ /^(?:SyntaxError: compile error|SyntaxError: \(ripl\):\d+: syntax error)/
99
+ end
100
+
101
+ it "sets @error_raised" do
102
+ shell.instance_variable_get("@error_raised").should == true
103
+ end
104
+
105
+ it "increments line" do
106
+ shell.line.should == @line + 1
107
+ end
108
+ end
109
+ end
110
+
111
+ describe "API#" do
112
+ Shell::API.instance_methods.delete_if {|e| e[/=$/]}.each do |meth|
113
+ it "#{meth} is accessible to plugins" do
114
+ mod = Object.const_set "Ping_#{meth}", Module.new
115
+ mod.send(:define_method, meth) { "pong_#{meth}" }
116
+ Shell.send :include, mod
117
+ shell.send(meth).should == "pong_#{meth}"
118
+ end
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,60 @@
1
+ require 'bacon'
2
+ require 'bacon/bits'
3
+ require 'rr'
4
+ require 'bacon/rr'
5
+ require 'stringio'
6
+ require 'ripl'
7
+ include Ripl
8
+
9
+ module Helpers
10
+ def ripl(*args)
11
+ options = args[-1].is_a?(Hash) ? args.pop : {}
12
+ mock_riplrc unless options[:riplrc] == false
13
+ mock(Ripl.shell).loop unless options[:loop] == false
14
+ capture_stdout { Ripl::Runner.run(args) }
15
+ end
16
+
17
+ def mock_riplrc(&block)
18
+ mock(Runner).load_rc(Ripl.config[:riplrc], &block)
19
+ end
20
+
21
+ def mock_shell(&block)
22
+ mock(Shell).create(anything) {|e|
23
+ shell = Shell.new(e)
24
+ block ? block.call(shell) : mock(shell).loop
25
+ shell
26
+ }
27
+ end
28
+
29
+ def reset_ripl
30
+ Ripl.instance_eval "@config = @shell = @riplrc = nil"
31
+ end
32
+
33
+ def reset_config
34
+ Ripl.config.merge! :history => '~/.irb_history', :completion => {}
35
+ end
36
+
37
+ def capture_stdout(&block)
38
+ original_stdout = $stdout
39
+ $stdout = fake = StringIO.new
40
+ begin
41
+ yield
42
+ ensure
43
+ $stdout = original_stdout
44
+ end
45
+ fake.string
46
+ end
47
+
48
+ def capture_stderr(&block)
49
+ original_stderr = $stderr
50
+ $stderr = fake = StringIO.new
51
+ begin
52
+ yield
53
+ ensure
54
+ $stderr = original_stderr
55
+ end
56
+ fake.string
57
+ end
58
+ end
59
+
60
+ Bacon::Context.send :include, Helpers
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ripl-fresh
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 2
8
- - 0
9
- version: 0.2.0
4
+ prerelease:
5
+ version: 0.2.1
10
6
  platform: ruby
11
7
  authors:
12
8
  - Jan Lelis
@@ -14,8 +10,7 @@ autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2010-12-03 00:00:00 +01:00
18
- default_executable:
13
+ date: 2011-05-20 00:00:00 Z
19
14
  dependencies:
20
15
  - !ruby/object:Gem::Dependency
21
16
  name: ripl
@@ -25,10 +20,6 @@ dependencies:
25
20
  requirements:
26
21
  - - ">="
27
22
  - !ruby/object:Gem::Version
28
- segments:
29
- - 0
30
- - 2
31
- - 6
32
23
  version: 0.2.6
33
24
  type: :runtime
34
25
  version_requirements: *id001
@@ -40,10 +31,6 @@ dependencies:
40
31
  requirements:
41
32
  - - ">="
42
33
  - !ruby/object:Gem::Version
43
- segments:
44
- - 0
45
- - 2
46
- - 0
47
34
  version: 0.2.0
48
35
  type: :runtime
49
36
  version_requirements: *id002
@@ -64,15 +51,17 @@ files:
64
51
  - lib/ripl/fresh.rb
65
52
  - lib/ripl-fresh/bond_workaround.rb
66
53
  - lib/bond/completions/ripl-fresh.rb
54
+ - test/test_helper.rb
55
+ - test/shell_test.rb
56
+ - test/runner_test.rb
67
57
  - bin/fresh
68
58
  - bin/ripl-fresh
69
59
  - README.rdoc
70
60
  - CHANGELOG.rdoc
71
- - deps.rip
61
+ - test/deps.rip
72
62
  - Rakefile
73
63
  - .gemspec
74
64
  - LICENSE
75
- has_rdoc: true
76
65
  homepage: http://github.com/janlelis/fresh
77
66
  licenses:
78
67
  - MIT
@@ -86,24 +75,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
86
75
  requirements:
87
76
  - - ">="
88
77
  - !ruby/object:Gem::Version
89
- segments:
90
- - 1
91
- - 9
92
78
  version: "1.9"
93
79
  required_rubygems_version: !ruby/object:Gem::Requirement
94
80
  none: false
95
81
  requirements:
96
82
  - - ">="
97
83
  - !ruby/object:Gem::Version
98
- segments:
99
- - 1
100
- - 3
101
- - 6
102
84
  version: 1.3.6
103
85
  requirements: []
104
86
 
105
87
  rubyforge_project:
106
- rubygems_version: 1.3.7
88
+ rubygems_version: 1.8.1
107
89
  signing_key:
108
90
  specification_version: 3
109
91
  summary: Fresh Ruby Enhanced SHell
data/deps.rip DELETED
@@ -1 +0,0 @@
1
- ripl >=0.2.5