Skip to content

Commit a5e85b4

Browse files
committed
hook method_missing to call_lisp
1 parent 0f01392 commit a5e85b4

File tree

1 file changed

+35
-23
lines changed

1 file changed

+35
-23
lines changed

test/rspec/rspec-lisp.rb

+35-23
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,13 @@ def initialize(module_name = nil, &block)
2929
##
3030
# @private
3131
def method_missing(method_name, *args, &block)
32-
method_name = method_name.to_s.gsub('_', '-').to_sym
33-
super # TODO: invoke the corresponding Lisp function
32+
function_name = method_name.to_s.gsub('_', '-').to_sym
33+
result = call_lisp_(function_name, args);
34+
if block_given?
35+
block.call(result)
36+
else
37+
result
38+
end
3439
end
3540

3641
##
@@ -44,29 +49,34 @@ def method_missing(method_name, *args, &block)
4449
#
4550
# @param [String] function
4651
# @param [Array] arguments
47-
def call_lisp(function, *arguments)
48-
# the BERTRPC interface is not symmetric, but that's the way it is.
49-
message = encode_ruby_request(BERT::Tuple[:call, @module_name, function, arguments])
50-
pid, stdin, stdout, stderr = Open4.popen4(LISP)
51-
stdin.write(message)
52-
stdin.flush.close
53-
_, status = Process.waitpid2(pid)
54-
if ( status.exitstatus.zero? )
52+
def call_lisp(function, *arguments)
53+
call_lisp_(function, arguments)
54+
end
55+
56+
57+
def call_lisp_(function, arguments)
58+
# the BERTRPC interface is not symmetric, but that's the way it is.
59+
message = encode_ruby_request(BERT::Tuple[:call, @module_name, function, arguments])
60+
pid, stdin, stdout, stderr = Open4.popen4(LISP)
61+
stdin.write(message)
62+
stdin.flush.close
63+
_, status = Process.waitpid2(pid)
64+
if ( status.exitstatus.zero? )
5565
# decode the response directly from the stream w/o a length header
56-
dc = BERT::Decode.new(stdout);
57-
response = dc.read_any
58-
case response[0]
59-
when :reply
60-
response[1]
61-
when :error
62-
error(response[1])
63-
else
64-
raise
66+
dc = BERT::Decode.new(stdout);
67+
response = dc.read_any
68+
case response[0]
69+
when :reply
70+
response[1]
71+
when :error
72+
error(response[1])
73+
else
74+
raise
75+
end
76+
else
77+
raise(StandardError, stderr.read())
6578
end
66-
else
67-
raise(StandardError, stderr.read())
6879
end
69-
end
7080

7181
end
7282

@@ -111,9 +121,11 @@ def self.execute(code)
111121
p RSpec::Lisp.evaluate(%q((* 6 (+ 3 4)))) #=> 42
112122
end
113123

114-
124+
## RSpec::Lisp::Proxy.new("CL").call_lisp("lisp-implementation-type")
115125
## RSpec::Lisp::Proxy.new("CL").call_lisp("round", 7, 3)
116126
## RSpec::Lisp::Proxy.new("keyword").call_lisp("rspec.succeed")
117127
## RSpec::Lisp::Proxy.new("keyword").call_lisp("rspec.fail")
118128
## RSpec::Lisp::Proxy.new("keyword").call_lisp("rspec.error")
119129

130+
## RSpec::Lisp::Proxy.new("CL").lisp_implementation_type
131+

0 commit comments

Comments
 (0)