srizzo-irber 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +5 -0
- data/History.txt +10 -0
- data/LICENSE +22 -0
- data/README.rdoc +70 -0
- data/Rakefile +61 -0
- data/VERSION +1 -0
- data/features/get_a_generated_source_code_on_the_fly.feature +151 -0
- data/features/make_an_object_print_itself.feature +29 -0
- data/features/step_definitions/irber_steps.rb +37 -0
- data/features/support/env.rb +9 -0
- data/irber.gemspec +66 -0
- data/lib/irber/printing.rb +30 -0
- data/lib/irber/to_code.rb +48 -0
- data/lib/irber.rb +2 -0
- data/spec/custom_helpers.rb +13 -0
- data/spec/custom_matchers.rb +6 -0
- data/spec/irber/printing_spec.rb +52 -0
- data/spec/irber/to_code_spec.rb +141 -0
- data/spec/spec_helper.rb +19 -0
- metadata +96 -0
data/.document
ADDED
data/History.txt
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
=== 0.0.2 2009-07-16
|
2
|
+
|
3
|
+
* 1 major enhancement:
|
4
|
+
* printing - adds puts_it, pp_it and p_it methods to make an object print itself
|
5
|
+
|
6
|
+
|
7
|
+
=== 0.0.1 2009-07-15
|
8
|
+
|
9
|
+
* 1 major enhancement:
|
10
|
+
* to_code - adds a to_code method to generate a class or method code on the fly
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
(The MIT License)
|
2
|
+
|
3
|
+
Copyright (c) 2009 Samuel Rizzo
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
'Software'), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
19
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
20
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
21
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
22
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
== DESCRIPTION:
|
2
|
+
|
3
|
+
Little tools to enhance your irb experience
|
4
|
+
|
5
|
+
== INSTALL:
|
6
|
+
|
7
|
+
* sudo gem install srizzo-irber
|
8
|
+
* add to your ~/.irbrc
|
9
|
+
|
10
|
+
require 'irber'
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
== BASIC USAGE:
|
15
|
+
|
16
|
+
* generate a class or method source code on the fly
|
17
|
+
|
18
|
+
Given a class:
|
19
|
+
|
20
|
+
class A
|
21
|
+
def a
|
22
|
+
"a"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
Generate source code on the fly:
|
28
|
+
|
29
|
+
>> puts A.to_code
|
30
|
+
class A < Object
|
31
|
+
def a()
|
32
|
+
"a"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
=> nil
|
36
|
+
>> puts A.to_code :a
|
37
|
+
def a()
|
38
|
+
"a"
|
39
|
+
end
|
40
|
+
=> nil
|
41
|
+
|
42
|
+
|
43
|
+
* make an object print itself
|
44
|
+
|
45
|
+
>> [1,2].puts_it
|
46
|
+
1
|
47
|
+
2
|
48
|
+
|
49
|
+
>> [1,2].pp_it
|
50
|
+
[1, 2]
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
== FEATURES/PROBLEMS:
|
56
|
+
|
57
|
+
* generate a class or method source code on the fly
|
58
|
+
* limitation: won't work for all classes and methods (e.g: native classes)
|
59
|
+
|
60
|
+
|
61
|
+
== REQUIREMENTS:
|
62
|
+
|
63
|
+
* ParseTree
|
64
|
+
* Ruby2Ruby
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
== Copyright
|
69
|
+
|
70
|
+
Copyright (c) 2009 Samuel Rizzo. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "irber"
|
8
|
+
gem.summary = %Q{Little tools to enhance your irb experience}
|
9
|
+
gem.email = "rizzolabs@gmail.com"
|
10
|
+
gem.homepage = "http://github.com/srizzo/irber"
|
11
|
+
gem.authors = ["srizzo"]
|
12
|
+
|
13
|
+
gem.add_runtime_dependency 'ParseTree', '>= 3.0.4'
|
14
|
+
gem.add_runtime_dependency 'ruby2ruby', '>= 1.2.3'
|
15
|
+
|
16
|
+
|
17
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
18
|
+
end
|
19
|
+
|
20
|
+
rescue LoadError
|
21
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
22
|
+
end
|
23
|
+
|
24
|
+
require 'spec/rake/spectask'
|
25
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
26
|
+
spec.libs << 'lib' << 'spec'
|
27
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
28
|
+
end
|
29
|
+
|
30
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
31
|
+
spec.libs << 'lib' << 'spec'
|
32
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
33
|
+
spec.rcov = true
|
34
|
+
end
|
35
|
+
|
36
|
+
begin
|
37
|
+
require 'cucumber/rake/task'
|
38
|
+
Cucumber::Rake::Task.new(:features)
|
39
|
+
rescue LoadError
|
40
|
+
task :features do
|
41
|
+
abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
task :default => :spec
|
46
|
+
|
47
|
+
require 'rake/rdoctask'
|
48
|
+
Rake::RDocTask.new do |rdoc|
|
49
|
+
if File.exist?('VERSION.yml')
|
50
|
+
config = YAML.load(File.read('VERSION.yml'))
|
51
|
+
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
52
|
+
else
|
53
|
+
version = ""
|
54
|
+
end
|
55
|
+
|
56
|
+
rdoc.rdoc_dir = 'rdoc'
|
57
|
+
rdoc.title = "irber #{version}"
|
58
|
+
rdoc.rdoc_files.include('README*')
|
59
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
60
|
+
end
|
61
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.2
|
@@ -0,0 +1,151 @@
|
|
1
|
+
Feature: get a generated source code on the fly
|
2
|
+
In order to save time looking for source code
|
3
|
+
As a lazy programmer
|
4
|
+
I want to get a generated source code on the fly
|
5
|
+
|
6
|
+
Scenario: from a class
|
7
|
+
Given the definition
|
8
|
+
"""
|
9
|
+
class A
|
10
|
+
def an_instance_method
|
11
|
+
"result"
|
12
|
+
end
|
13
|
+
def self.a_class_method
|
14
|
+
"result"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
"""
|
18
|
+
And I have required "irber/to_code"
|
19
|
+
When I run "A.to_code"
|
20
|
+
Then I should get the code
|
21
|
+
"""
|
22
|
+
class A < Object
|
23
|
+
def an_instance_method()
|
24
|
+
\"result\"
|
25
|
+
end
|
26
|
+
def self.a_class_method()
|
27
|
+
\"result\"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
"""
|
31
|
+
|
32
|
+
Scenario: from an object
|
33
|
+
Given the definition
|
34
|
+
"""
|
35
|
+
class A
|
36
|
+
def an_instance_method
|
37
|
+
"result"
|
38
|
+
end
|
39
|
+
def self.a_class_method
|
40
|
+
"result"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
"""
|
44
|
+
And I have required "irber/to_code"
|
45
|
+
When I run "A.new.to_code"
|
46
|
+
Then I should get the code
|
47
|
+
"""
|
48
|
+
class A < Object
|
49
|
+
def an_instance_method()
|
50
|
+
\"result\"
|
51
|
+
end
|
52
|
+
def self.a_class_method()
|
53
|
+
\"result\"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
"""
|
57
|
+
|
58
|
+
Scenario: from a module
|
59
|
+
Given the definition
|
60
|
+
"""
|
61
|
+
module M
|
62
|
+
def a_method
|
63
|
+
"result"
|
64
|
+
end
|
65
|
+
def self.a_module_method
|
66
|
+
"result"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
"""
|
70
|
+
And I have required "irber/to_code"
|
71
|
+
When I run "M.to_code"
|
72
|
+
Then I should get the code
|
73
|
+
"""
|
74
|
+
module M
|
75
|
+
def a_method()
|
76
|
+
"result"
|
77
|
+
end
|
78
|
+
def self.a_module_method()
|
79
|
+
"result"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
"""
|
83
|
+
|
84
|
+
|
85
|
+
Scenario: from a class method
|
86
|
+
Given the definition
|
87
|
+
"""
|
88
|
+
class A
|
89
|
+
def an_instance_method
|
90
|
+
"result"
|
91
|
+
end
|
92
|
+
def self.a_class_method
|
93
|
+
"result"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
"""
|
97
|
+
And I have required "irber/to_code"
|
98
|
+
When I run "A.to_code :a_class_method"
|
99
|
+
Then I should get the code
|
100
|
+
"""
|
101
|
+
def a_class_method()
|
102
|
+
"result"
|
103
|
+
end
|
104
|
+
"""
|
105
|
+
|
106
|
+
Scenario: from an object method
|
107
|
+
Given the definition
|
108
|
+
"""
|
109
|
+
class A
|
110
|
+
def an_instance_method
|
111
|
+
"result"
|
112
|
+
end
|
113
|
+
def self.a_class_method
|
114
|
+
"result"
|
115
|
+
end
|
116
|
+
end
|
117
|
+
"""
|
118
|
+
And I have required "irber/to_code"
|
119
|
+
When I run "A.new.to_code :an_instance_method"
|
120
|
+
Then I should get the code
|
121
|
+
"""
|
122
|
+
def an_instance_method()
|
123
|
+
"result"
|
124
|
+
end
|
125
|
+
"""
|
126
|
+
|
127
|
+
Scenario: try to get an inexisting method
|
128
|
+
Given the definition
|
129
|
+
"""
|
130
|
+
class A
|
131
|
+
def an_instance_method
|
132
|
+
"result"
|
133
|
+
end
|
134
|
+
def self.a_class_method
|
135
|
+
"result"
|
136
|
+
end
|
137
|
+
end
|
138
|
+
"""
|
139
|
+
And I have required "irber/to_code"
|
140
|
+
When I run "A.new.to_code :an_inexisting_method"
|
141
|
+
Then I should get the error "NameError"
|
142
|
+
|
143
|
+
Scenario: try on native code
|
144
|
+
Given a native implemented class "String"
|
145
|
+
And I have required "irber/to_code"
|
146
|
+
When I run "String.to_code"
|
147
|
+
Then I should get the error "ParseError"
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
Feature: make an object print itself
|
2
|
+
In order to save time going to the beginning of the line
|
3
|
+
As a lazy programmer
|
4
|
+
I want to print an object appending a method to it
|
5
|
+
|
6
|
+
Scenario: make an object print itself
|
7
|
+
Given the definition
|
8
|
+
"""
|
9
|
+
class O
|
10
|
+
def to_s
|
11
|
+
"O#to_s"
|
12
|
+
end
|
13
|
+
def inspect
|
14
|
+
"O#inspect"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
"""
|
18
|
+
And I have required "irber/printing"
|
19
|
+
And I have run "@o = O.new"
|
20
|
+
|
21
|
+
When I run "@o.puts_it"
|
22
|
+
Then I should get the same stdout as "puts @o"
|
23
|
+
|
24
|
+
When I run "@o.p_it"
|
25
|
+
Then I should get the same stdout as "p @o"
|
26
|
+
|
27
|
+
When I run "@o.pp_it"
|
28
|
+
Then I should get the same stdout as "pp @o"
|
29
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
Given /^the definition$/ do |code|
|
2
|
+
eval code
|
3
|
+
end
|
4
|
+
|
5
|
+
Given /^I have required "(.*)"$/ do |dependency|
|
6
|
+
require dependency
|
7
|
+
end
|
8
|
+
|
9
|
+
|
10
|
+
Given /^a native implemented class "([^\"]*)"$/ do |klass|
|
11
|
+
#do nothing
|
12
|
+
end
|
13
|
+
|
14
|
+
Given /^I have run "([^\"]*)"$/ do |code|
|
15
|
+
eval(code)
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
When /^I run "([^\"]*)"$/ do |code|
|
20
|
+
@result = lambda{ eval(code) }
|
21
|
+
end
|
22
|
+
|
23
|
+
Then /^I should get the code$/ do |code|
|
24
|
+
@result.call.should match_code(code)
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
Then /^I should get the error "([^\"]*)"$/ do |error|
|
29
|
+
@result.should raise_error(
|
30
|
+
Object.module_eval("::#{error}", __FILE__, __LINE__)
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
Then /^I should get the same stdout as "([^\"]*)"$/ do |code|
|
36
|
+
stdout{ @result.call }.should == stdout{ eval(code) }
|
37
|
+
end
|
data/irber.gemspec
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{irber}
|
5
|
+
s.version = "0.0.2"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["srizzo"]
|
9
|
+
s.date = %q{2009-07-16}
|
10
|
+
s.email = %q{rizzolabs@gmail.com}
|
11
|
+
s.extra_rdoc_files = [
|
12
|
+
"LICENSE",
|
13
|
+
"README.rdoc"
|
14
|
+
]
|
15
|
+
s.files = [
|
16
|
+
".document",
|
17
|
+
".gitignore",
|
18
|
+
"History.txt",
|
19
|
+
"LICENSE",
|
20
|
+
"README.rdoc",
|
21
|
+
"Rakefile",
|
22
|
+
"VERSION",
|
23
|
+
"features/get_a_generated_source_code_on_the_fly.feature",
|
24
|
+
"features/make_an_object_print_itself.feature",
|
25
|
+
"features/step_definitions/irber_steps.rb",
|
26
|
+
"features/support/env.rb",
|
27
|
+
"irber.gemspec",
|
28
|
+
"lib/irber.rb",
|
29
|
+
"lib/irber/printing.rb",
|
30
|
+
"lib/irber/to_code.rb",
|
31
|
+
"spec/custom_helpers.rb",
|
32
|
+
"spec/custom_matchers.rb",
|
33
|
+
"spec/irber/printing_spec.rb",
|
34
|
+
"spec/irber/to_code_spec.rb",
|
35
|
+
"spec/spec_helper.rb"
|
36
|
+
]
|
37
|
+
s.has_rdoc = true
|
38
|
+
s.homepage = %q{http://github.com/srizzo/irber}
|
39
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
40
|
+
s.require_paths = ["lib"]
|
41
|
+
s.rubygems_version = %q{1.3.2}
|
42
|
+
s.summary = %q{Little tools to enhance your irb experience}
|
43
|
+
s.test_files = [
|
44
|
+
"spec/custom_helpers.rb",
|
45
|
+
"spec/custom_matchers.rb",
|
46
|
+
"spec/irber/printing_spec.rb",
|
47
|
+
"spec/irber/to_code_spec.rb",
|
48
|
+
"spec/spec_helper.rb"
|
49
|
+
]
|
50
|
+
|
51
|
+
if s.respond_to? :specification_version then
|
52
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
53
|
+
s.specification_version = 3
|
54
|
+
|
55
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
56
|
+
s.add_runtime_dependency(%q<ParseTree>, [">= 3.0.4"])
|
57
|
+
s.add_runtime_dependency(%q<ruby2ruby>, [">= 1.2.3"])
|
58
|
+
else
|
59
|
+
s.add_dependency(%q<ParseTree>, [">= 3.0.4"])
|
60
|
+
s.add_dependency(%q<ruby2ruby>, [">= 1.2.3"])
|
61
|
+
end
|
62
|
+
else
|
63
|
+
s.add_dependency(%q<ParseTree>, [">= 3.0.4"])
|
64
|
+
s.add_dependency(%q<ruby2ruby>, [">= 1.2.3"])
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'pp'
|
2
|
+
|
3
|
+
|
4
|
+
module Irber
|
5
|
+
module Printing
|
6
|
+
|
7
|
+
module InstanceMethods
|
8
|
+
def puts_it
|
9
|
+
puts self
|
10
|
+
end
|
11
|
+
def p_it
|
12
|
+
p self
|
13
|
+
end
|
14
|
+
def pp_it
|
15
|
+
pp self
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.included(receiver)
|
20
|
+
receiver.send :include, InstanceMethods
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
class Object
|
28
|
+
include Irber::Printing
|
29
|
+
end
|
30
|
+
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'parse_tree'
|
2
|
+
require 'ruby2ruby'
|
3
|
+
|
4
|
+
module Irber
|
5
|
+
module ToCode
|
6
|
+
|
7
|
+
class ParseError < StandardError; end
|
8
|
+
|
9
|
+
module InstanceMethods
|
10
|
+
def to_code method = nil
|
11
|
+
|
12
|
+
if method
|
13
|
+
|
14
|
+
if (the_method = self.method(method) rescue nil)
|
15
|
+
receiver = the_method.owner
|
16
|
+
elsif (the_method = self.instance_method(method) if self.respond_to? :instance_method)
|
17
|
+
receiver = the_method.owner
|
18
|
+
else
|
19
|
+
throw NameError.new "couldn't find method `#{method}' for `#{self}' "
|
20
|
+
end
|
21
|
+
|
22
|
+
Ruby2Ruby.new.process(ParseTree.translate(receiver, method)) rescue raise ParseError.new("couldn't parse method")
|
23
|
+
|
24
|
+
else
|
25
|
+
if self.class == Class || self.class == Module
|
26
|
+
receiver = self
|
27
|
+
else
|
28
|
+
receiver = self.class
|
29
|
+
end
|
30
|
+
|
31
|
+
Ruby2Ruby.new.process(ParseTree.translate(receiver)) rescue raise ParseError.new("couldn't parse class")
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.included(receiver)
|
39
|
+
receiver.send :include, InstanceMethods
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
class Object
|
47
|
+
include Irber::ToCode
|
48
|
+
end
|
data/lib/irber.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
require "irber/printing"
|
4
|
+
|
5
|
+
class O
|
6
|
+
def to_s
|
7
|
+
"O#to_s"
|
8
|
+
end
|
9
|
+
def inspect
|
10
|
+
"O#inspect"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
describe Irber::Printing do
|
16
|
+
|
17
|
+
before(:each) do
|
18
|
+
@a = O.new
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#puts_it" do
|
22
|
+
it "should be available on all objects" do
|
23
|
+
Object.new.should respond_to(:puts_it)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should puts itself" do
|
27
|
+
stdout{ @a.puts_it }.should == stdout{ puts @a }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#p_it" do
|
32
|
+
it "should be available on all objects" do
|
33
|
+
Object.new.should respond_to(:p_it)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should puts itself" do
|
37
|
+
stdout{ @a.p_it }.should == stdout{ p @a }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "#pp_it" do
|
42
|
+
it "should be available on all objects" do
|
43
|
+
Object.new.should respond_to(:pp_it)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should puts itself" do
|
47
|
+
stdout{ @a.pp_it }.should == stdout{ pp @a }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
end
|
@@ -0,0 +1,141 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
require "irber/to_code"
|
4
|
+
|
5
|
+
class A
|
6
|
+
def an_instance_method
|
7
|
+
"result"
|
8
|
+
end
|
9
|
+
def self.a_class_method
|
10
|
+
"result"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module M
|
15
|
+
def a_method
|
16
|
+
"result"
|
17
|
+
end
|
18
|
+
def self.a_module_method
|
19
|
+
"result"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
describe Irber::ToCode do
|
25
|
+
|
26
|
+
describe "on classes" do
|
27
|
+
it "should be available on all classes" do
|
28
|
+
A.should respond_to(:to_code)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should generate its source code" do
|
32
|
+
A.to_code.should match_code "
|
33
|
+
class A < Object
|
34
|
+
def an_instance_method()
|
35
|
+
\"result\"
|
36
|
+
end
|
37
|
+
def self.a_class_method()
|
38
|
+
\"result\"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "on objects" do
|
46
|
+
it "should be available on all objects" do
|
47
|
+
A.new.should respond_to(:to_code)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should generate its source code" do
|
51
|
+
A.new.to_code.should match_code "
|
52
|
+
class A < Object
|
53
|
+
def an_instance_method()
|
54
|
+
\"result\"
|
55
|
+
end
|
56
|
+
def self.a_class_method()
|
57
|
+
\"result\"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
"
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "on modules" do
|
66
|
+
it "should generat its source code" do
|
67
|
+
M.to_code.should match_code "
|
68
|
+
module M
|
69
|
+
def a_method()
|
70
|
+
\"result\"
|
71
|
+
end
|
72
|
+
def self.a_module_method()
|
73
|
+
\"result\"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "on class methods" do
|
81
|
+
it "should generate a class instance method source code " do
|
82
|
+
A.to_code(:an_instance_method).should match_code "
|
83
|
+
def an_instance_method()
|
84
|
+
\"result\"
|
85
|
+
end
|
86
|
+
"
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should generate a class method source code " do
|
90
|
+
A.to_code(:a_class_method).should match_code "
|
91
|
+
def a_class_method()
|
92
|
+
\"result\"
|
93
|
+
end
|
94
|
+
"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
|
99
|
+
describe "on object methods" do
|
100
|
+
it "should generate an object method source code" do
|
101
|
+
A.new.to_code(:an_instance_method).should match_code "
|
102
|
+
def an_instance_method()
|
103
|
+
\"result\"
|
104
|
+
end
|
105
|
+
"
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe "on module methods" do
|
110
|
+
it "should generate a module method source code" do
|
111
|
+
M.to_code(:a_method).should match_code "
|
112
|
+
def a_method()
|
113
|
+
\"result\"
|
114
|
+
end
|
115
|
+
"
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
describe "on inexisting methods" do
|
121
|
+
it "should raise NameError" do
|
122
|
+
lambda{ A.new.to_code(:an_inexisting_method) }.should raise_error(NameError)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
|
127
|
+
describe "on native classes" do
|
128
|
+
it "should raise ParseError" do
|
129
|
+
lambda{ String.to_code }.should raise_error(ParseError)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
describe "on native methods" do
|
134
|
+
it "should raise ParseError" do
|
135
|
+
lambda{ "".to_code :to_s }.should raise_error(ParseError)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
require 'spec'
|
4
|
+
|
5
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
6
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
7
|
+
require 'irber'
|
8
|
+
|
9
|
+
Spec::Runner.configure do |config|
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
require File.join(File.dirname(__FILE__), 'custom_helpers')
|
16
|
+
require File.join(File.dirname(__FILE__), 'custom_matchers')
|
17
|
+
|
18
|
+
|
19
|
+
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: srizzo-irber
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- srizzo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-07-16 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: ParseTree
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 3.0.4
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: ruby2ruby
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.2.3
|
34
|
+
version:
|
35
|
+
description:
|
36
|
+
email: rizzolabs@gmail.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- LICENSE
|
43
|
+
- README.rdoc
|
44
|
+
files:
|
45
|
+
- .document
|
46
|
+
- .gitignore
|
47
|
+
- History.txt
|
48
|
+
- LICENSE
|
49
|
+
- README.rdoc
|
50
|
+
- Rakefile
|
51
|
+
- VERSION
|
52
|
+
- features/get_a_generated_source_code_on_the_fly.feature
|
53
|
+
- features/make_an_object_print_itself.feature
|
54
|
+
- features/step_definitions/irber_steps.rb
|
55
|
+
- features/support/env.rb
|
56
|
+
- irber.gemspec
|
57
|
+
- lib/irber.rb
|
58
|
+
- lib/irber/printing.rb
|
59
|
+
- lib/irber/to_code.rb
|
60
|
+
- spec/custom_helpers.rb
|
61
|
+
- spec/custom_matchers.rb
|
62
|
+
- spec/irber/printing_spec.rb
|
63
|
+
- spec/irber/to_code_spec.rb
|
64
|
+
- spec/spec_helper.rb
|
65
|
+
has_rdoc: true
|
66
|
+
homepage: http://github.com/srizzo/irber
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options:
|
69
|
+
- --charset=UTF-8
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: "0"
|
77
|
+
version:
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: "0"
|
83
|
+
version:
|
84
|
+
requirements: []
|
85
|
+
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 1.2.0
|
88
|
+
signing_key:
|
89
|
+
specification_version: 3
|
90
|
+
summary: Little tools to enhance your irb experience
|
91
|
+
test_files:
|
92
|
+
- spec/custom_helpers.rb
|
93
|
+
- spec/custom_matchers.rb
|
94
|
+
- spec/irber/printing_spec.rb
|
95
|
+
- spec/irber/to_code_spec.rb
|
96
|
+
- spec/spec_helper.rb
|