orb 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/orb.rb +27 -9
- data/orb.gemspec +1 -1
- metadata +2 -2
data/lib/orb.rb
CHANGED
@@ -27,13 +27,11 @@ require 'orb/adapters/rspec'
|
|
27
27
|
|
28
28
|
class ORB
|
29
29
|
@@index=0
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
puts "\n\n[[ #{ORB::Adapter.header(bind)} ]]"
|
36
|
-
|
30
|
+
|
31
|
+
# Once ORB is called, the user is presented with a minimal IRB-like REPL,
|
32
|
+
# where they can evaluate arbitrary ruby code or execute a set of built-in
|
33
|
+
# commands to build up a test and save it back to the test file.
|
34
|
+
def orb_it_up
|
37
35
|
while line = Readline.readline(prompt, true)
|
38
36
|
case line
|
39
37
|
|
@@ -79,8 +77,8 @@ class ORB
|
|
79
77
|
else
|
80
78
|
@hist << [line,false]
|
81
79
|
begin
|
82
|
-
this =
|
83
|
-
ret = this.send(:eval, line,
|
80
|
+
this = @binding.eval("self")
|
81
|
+
ret = this.send(:eval, line, @binding)
|
84
82
|
rescue => e
|
85
83
|
puts e.message
|
86
84
|
else
|
@@ -89,6 +87,26 @@ class ORB
|
|
89
87
|
end
|
90
88
|
|
91
89
|
end
|
90
|
+
end
|
91
|
+
|
92
|
+
# It's up to the adapters to figure out the context we need to evaluate code
|
93
|
+
# in. Typically, they'll grab it from an empty block. Adapters call this
|
94
|
+
# intializer with a `Binding`, and we set a few instance variables for the
|
95
|
+
# REPL to use. Notably, `@line` and `@file` are the location of the call
|
96
|
+
# to ORB, where we should insert our code when the test is written out.
|
97
|
+
def initialize(bind)
|
98
|
+
@@index += 1
|
99
|
+
@binding = bind
|
100
|
+
@buf, @hist = [], []
|
101
|
+
@line, @file = bind.eval("[__LINE__, __FILE__]")
|
102
|
+
|
103
|
+
# This is normally used for the test's description. It's not a strict
|
104
|
+
# requirement of an adapter, but will be set and shown if present.
|
105
|
+
@header = ORB::Adapter.header(bind) if ORB::Adapter.respond_to?(:header)
|
106
|
+
puts "\n\n[[ #{@header} ]]" if @header
|
107
|
+
|
108
|
+
# Gentlemen, start your REPLs.
|
109
|
+
orb_it_up
|
92
110
|
end
|
93
111
|
|
94
112
|
private
|
data/orb.gemspec
CHANGED