rink 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/rink.gemspec ADDED
@@ -0,0 +1,83 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{rink}
8
+ s.version = "1.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Colin MacKenzie IV"]
12
+ s.date = %q{2010-08-06}
13
+ s.default_executable = %q{rink}
14
+ s.description = %q{Makes interactive consoles awesome.}
15
+ s.email = %q{sinisterchipmunk@gmail.com}
16
+ s.executables = ["rink"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ ".gitignore",
24
+ "LICENSE",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "bin/rink",
29
+ "lib/core_ext/object.rb",
30
+ "lib/rink.rb",
31
+ "lib/rink/console.rb",
32
+ "lib/rink/delegation.rb",
33
+ "lib/rink/input_method/base.rb",
34
+ "lib/rink/input_method/file.rb",
35
+ "lib/rink/input_method/io.rb",
36
+ "lib/rink/input_method/readline.rb",
37
+ "lib/rink/io_methods.rb",
38
+ "lib/rink/lexer.rb",
39
+ "lib/rink/line_processor/base.rb",
40
+ "lib/rink/line_processor/pure_ruby.rb",
41
+ "lib/rink/output_method/base.rb",
42
+ "lib/rink/output_method/io.rb",
43
+ "rink.gemspec",
44
+ "spec/lib/core_ext/object_spec.rb",
45
+ "spec/lib/rink/console_spec.rb",
46
+ "spec/lib/rink/io_methods_spec.rb",
47
+ "spec/lib/rink/pure_ruby_line_processor_spec.rb",
48
+ "spec/lib/rink_spec.rb",
49
+ "spec/spec.opts",
50
+ "spec/spec_helper.rb"
51
+ ]
52
+ s.homepage = %q{http://github.com/sinisterchipmunk/rink}
53
+ s.rdoc_options = ["--charset=UTF-8"]
54
+ s.require_paths = ["lib"]
55
+ s.rubygems_version = %q{1.3.6}
56
+ s.summary = %q{Makes interactive consoles awesome.}
57
+ s.test_files = [
58
+ "spec/lib",
59
+ "spec/lib/core_ext",
60
+ "spec/lib/core_ext/object_spec.rb",
61
+ "spec/lib/rink",
62
+ "spec/lib/rink/console_spec.rb",
63
+ "spec/lib/rink/io_methods_spec.rb",
64
+ "spec/lib/rink/pure_ruby_line_processor_spec.rb",
65
+ "spec/lib/rink_spec.rb",
66
+ "spec/spec.opts",
67
+ "spec/spec_helper.rb"
68
+ ]
69
+
70
+ if s.respond_to? :specification_version then
71
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
72
+ s.specification_version = 3
73
+
74
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
75
+ s.add_development_dependency(%q<rspec>, [">= 1.3.0"])
76
+ else
77
+ s.add_dependency(%q<rspec>, [">= 1.3.0"])
78
+ end
79
+ else
80
+ s.add_dependency(%q<rspec>, [">= 1.3.0"])
81
+ end
82
+ end
83
+
@@ -0,0 +1,19 @@
1
+ describe Object do
2
+ context "#instance_exec" do
3
+ class Dummy
4
+ def value
5
+ :dummy_value
6
+ end
7
+ end
8
+
9
+ subject { Dummy.new }
10
+
11
+ it "should work with args" do
12
+ # Block returns the value passed to it and the value of #value from the Dummy, in whose context
13
+ # it will be eval'd.
14
+ block = lambda { |a| [a, value] }
15
+
16
+ subject.instance_exec(:arg_value, &block).should == [:arg_value, :dummy_value]
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,129 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rink::Console do
4
+ class ExampleObject
5
+ def inspect
6
+ "#<example>"
7
+ end
8
+ end
9
+
10
+ def console(*input)
11
+ if input.last.kind_of?(Hash)
12
+ options = input.pop
13
+ else options = {}
14
+ end
15
+ input = input.flatten.join("\n")
16
+ subject.run(input, options.merge(:output => @output, :silent => false))
17
+ end
18
+
19
+ before(:each) { @input = ""; @output = "" }
20
+ subject { Rink::Console.new(:input => "", :silent => true) }
21
+
22
+ it "should provide an option to not execute Ruby code" do
23
+ console("x = 5", :allow_ruby => false)
24
+ @output.should match(/I don't know the word \"x.\"/)
25
+ end
26
+
27
+ it "should not raise a NameError when invoking a dynamically-defined method" do
28
+ console("def a; 5; end; a", :rescue_errors => false).should == 5
29
+ end
30
+
31
+ it "should retain local variables" do
32
+ subject.run("x = 5\nx", :rescue_errors => false)
33
+ end
34
+
35
+ it "should be able to set itself as the namespace" do
36
+ subject.run("self", :namespace => :self).should == subject
37
+ end
38
+
39
+ it "should return the last value executed" do
40
+ console("1").should == 1
41
+ end
42
+
43
+ it "should not have a nil namespace!" do
44
+ console("self").should_not be_nil
45
+ end
46
+
47
+ it "should be able to span ruby code over 2 lines" do
48
+ proc { console("3.times do\nend", :rescue_errors => false) }.should_not raise_error
49
+ end
50
+
51
+ it "should not output multiple prompts" do
52
+ console("3.times do |i|\nx = i\nend")
53
+ @output.should == ">> Interactive Console <<\nRink::Console > 3.times do |i|\nRink::Console > x = i\nRink::Console > end\n => 3\nRink::Console > "
54
+ end
55
+
56
+ it "should be able to span ruby code over 3 lines" do
57
+ proc { console("3.times do |i|\nx = i\nend", :rescue_errors => false) }.should_not raise_error
58
+
59
+ # this illustrates a totally different prob: losing scope over multiple inputs.
60
+ # proc { console("x = 0\n3.times do |i|\nx += i\nend\nraise unless x == 3", :rescue_errors => false) }.
61
+ # should_not raise_error
62
+
63
+ end
64
+
65
+ # May need a better way to test this.
66
+ it "should be able to add hooks custom commands" do
67
+ # Create a subclass of Rink::Console so we don't contaminate the environment
68
+ klass = Class.new(Rink::Console)
69
+ klass.command(:help) { |*args| puts 'how may I help you?' }
70
+ k = klass.new(:input => "help", :output => @output, :rescue_errors => false)
71
+ @output.should =~ /how may I help you\?/
72
+ end
73
+
74
+ it "should be able to exit" do
75
+ # yeah, it was an oversight. Catching all Exceptions resulted in catching SystemExit, so the app couldn't be
76
+ # stopped. Whoops.
77
+ #proc { console("exit") }.should raise_error(SystemExit)
78
+
79
+ # now an honest-to-goodness 'exit' command exists, so SystemExit doesn't get raised.
80
+ # instead we'll just make sure that exit doesn't execute any further code.
81
+ console("exit\n1").should_not == 1
82
+ end
83
+
84
+ it "should show a banner" do
85
+ console
86
+ @output.should =~ /\A>> Interactive Console <</
87
+ end
88
+
89
+ it "should have a prompt" do
90
+ console
91
+ prompt = Regexp::escape(subject.send(:prompt))
92
+ @output.should =~ /^#{prompt}$/
93
+ end
94
+
95
+ it "should print return value, inspected" do
96
+ console("ExampleObject.new")
97
+ @output.should =~ / => #<example>$/
98
+ end
99
+
100
+ it "should not raise exceptions" do
101
+ proc { console("test") }.should_not raise_error
102
+ end
103
+
104
+ it "should print exceptions" do
105
+ console("test")
106
+ @output.should =~ /ArgumentError: /
107
+ end
108
+
109
+ it "should ignore blank lines" do
110
+ console("\n")
111
+ prompt = Regexp::escape(subject.send(:prompt))
112
+ @output.should =~ /^#{prompt}[\n\r]+#{prompt}$/
113
+ end
114
+
115
+ it "should allow setting namespace" do
116
+ obj = ExampleObject.new
117
+ subject.namespace = obj
118
+ console("self").should == obj
119
+ end
120
+
121
+ it "should allow presetting namespace" do
122
+ obj = ExampleObject.new
123
+ console("self", :namespace => obj).should == obj
124
+ end
125
+
126
+ it "should allow lazily presetting namespace" do
127
+ console("self", :namespace => proc { ExampleObject.new }).should be_kind_of(ExampleObject)
128
+ end
129
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rink::IOMethods do
4
+ include Rink::IOMethods
5
+
6
+ shared_examples_for "an input method" do
7
+ it "should gets" do
8
+ inln = @input.gets
9
+ inln.should_not be_nil
10
+ inln.length.should_not == 0
11
+ end
12
+ end
13
+
14
+ context "input should be set up" do
15
+ context "from a File" do
16
+ before(:each) { setup_input_method(File.new(__FILE__, "r")).should be_kind_of(Rink::InputMethod::Base) }
17
+
18
+ it_should_behave_like "an input method"
19
+ end
20
+
21
+ context "from a String" do
22
+ before(:each) { setup_input_method("a string").should be_kind_of(Rink::InputMethod::Base) }
23
+
24
+ it_should_behave_like "an input method"
25
+ end
26
+
27
+ context "from a StringIO" do
28
+ before(:each) { setup_input_method(StringIO.new("a string")).should be_kind_of(Rink::InputMethod::Base) }
29
+
30
+ it_should_behave_like "an input method"
31
+ end
32
+
33
+ context "from an InputMethod" do
34
+ before(:each) { setup_input_method(setup_input_method("a string")).should be_kind_of(Rink::InputMethod::Base) }
35
+
36
+ it_should_behave_like "an input method"
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rink::LineProcessor::PureRuby do
4
+ it "should autocomplete" do
5
+ subject.autocomplete('insp', Object.new).should == ["inspect"]
6
+ end
7
+
8
+ # probably don't need to test this directly since readline does it (and we know it works) ...
9
+ # maybe test that autocomplete and whatnot are processed correctly, instead.
10
+ # def console(*input)
11
+ # input = input.flatten.join("\n")
12
+ # subject.run(input, :output => @output, :silent => false)
13
+ # end
14
+ #
15
+ # before(:each) { @input = ""; @output = "" }
16
+ # subject { Rink::Console.new(:input => "", :silent => true) }
17
+ #
18
+ #
19
+ # it "should autocomplete 'help'" do
20
+ # console("h\t")
21
+ # @output.should =~ /> help/
22
+ # end
23
+ #
24
+ # it "should not autocomplete 'help' from 'd'" do
25
+ # console("d\t")
26
+ # @output.should_not =~ /> dh?elp/
27
+ # end
28
+ #
29
+ # it "should recall backward" do
30
+ # console("1\n" + ANSI::move_up)
31
+ # @output.should =~ / => 1$/
32
+ # end
33
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rink do
4
+ # it's a placeholder. What's there to describe?
5
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'tmpdir'
3
+
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ require 'rink'
7
+ require 'spec'
8
+ require 'spec/autorun'
9
+
10
+ Spec::Runner.configure do |config|
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rink
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 0
9
+ version: 1.0.0
10
+ platform: ruby
11
+ authors:
12
+ - Colin MacKenzie IV
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-08-06 00:00:00 -04:00
18
+ default_executable: rink
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 3
30
+ - 0
31
+ version: 1.3.0
32
+ type: :development
33
+ version_requirements: *id001
34
+ description: Makes interactive consoles awesome.
35
+ email: sinisterchipmunk@gmail.com
36
+ executables:
37
+ - rink
38
+ extensions: []
39
+
40
+ extra_rdoc_files:
41
+ - LICENSE
42
+ - README.rdoc
43
+ files:
44
+ - .document
45
+ - .gitignore
46
+ - LICENSE
47
+ - README.rdoc
48
+ - Rakefile
49
+ - VERSION
50
+ - bin/rink
51
+ - lib/core_ext/object.rb
52
+ - lib/rink.rb
53
+ - lib/rink/console.rb
54
+ - lib/rink/delegation.rb
55
+ - lib/rink/input_method/base.rb
56
+ - lib/rink/input_method/file.rb
57
+ - lib/rink/input_method/io.rb
58
+ - lib/rink/input_method/readline.rb
59
+ - lib/rink/io_methods.rb
60
+ - lib/rink/lexer.rb
61
+ - lib/rink/line_processor/base.rb
62
+ - lib/rink/line_processor/pure_ruby.rb
63
+ - lib/rink/output_method/base.rb
64
+ - lib/rink/output_method/io.rb
65
+ - rink.gemspec
66
+ - spec/lib/core_ext/object_spec.rb
67
+ - spec/lib/rink/console_spec.rb
68
+ - spec/lib/rink/io_methods_spec.rb
69
+ - spec/lib/rink/pure_ruby_line_processor_spec.rb
70
+ - spec/lib/rink_spec.rb
71
+ - spec/spec.opts
72
+ - spec/spec_helper.rb
73
+ has_rdoc: true
74
+ homepage: http://github.com/sinisterchipmunk/rink
75
+ licenses: []
76
+
77
+ post_install_message:
78
+ rdoc_options:
79
+ - --charset=UTF-8
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ segments:
87
+ - 0
88
+ version: "0"
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ segments:
94
+ - 0
95
+ version: "0"
96
+ requirements: []
97
+
98
+ rubyforge_project:
99
+ rubygems_version: 1.3.6
100
+ signing_key:
101
+ specification_version: 3
102
+ summary: Makes interactive consoles awesome.
103
+ test_files:
104
+ - spec/lib/core_ext/object_spec.rb
105
+ - spec/lib/rink/console_spec.rb
106
+ - spec/lib/rink/io_methods_spec.rb
107
+ - spec/lib/rink/pure_ruby_line_processor_spec.rb
108
+ - spec/lib/rink_spec.rb
109
+ - spec/spec.opts
110
+ - spec/spec_helper.rb