Hi
I’m using JRuby 1.6.7 and having problem running custom matchers in
RSpecs with lambdas.
(Home – Travis-CI)
It’s really strange because it works if the code is not loaded from a
different script.
Try this:
test.rb:
class PositiveExpectationHandler
def self.handle_matcher(actual, matcher, message=nil, &block)
matcher.matches?(actual, &block)
end
end
module Kernel
def should(matcher=nil, message=nil, &block)
PositiveExpectationHandler.handle_matcher(self, matcher, message,
&block)
end
end
class Bar
def initialize(query=nil, &dsl_block)
self.instance_eval(&dsl_block)
end
end
class Foo
def matches?(actual, &block)
puts “actual #{actual.inspect}, block=#{block.inspect}”
Bar.new(&actual)
end
end
lambda { puts “HEJ” }.should(Foo.new, “message”)
main.rb
load ‘test.rb’
Reproducing the bug (?)
=> Running test.rb in 1.8 mode, works
lib master] $ ruby test.rb
actual #Proc:[email protected]:26, block=nil
HEJ
=> Running main.rb in 1.8 mode, works
[lib master] $ ruby main.rb
actual #Proc:0x304cf82d@./test.rb:26, block=nil
HEJ
=> Running test.rb in 1.9 mode, works
[lib master] $ ruby --1.9 test.rb
actual #<Proc:[email protected]:26 (lambda)>, block=nil
HEJ
=> Running main.rb in 1.9 mod, FAILURE
[lib master] $ ruby --1.9 main.rb
actual
#<Proc:0x613efefe@/home/andreas/projects/neo4j-core/lib/test.rb:26
(lambda)>, block=nil
ArgumentError: wrong number of arguments (1 for 0)
instance_eval at org/jruby/RubyBasicObject.java:1730
initialize at /home/andreas/projects/neo4j-core/lib/test.rb:15
matches? at /home/andreas/projects/neo4j-core/lib/test.rb:22
handle_matcher at /home/andreas/projects/neo4j-core/lib/test.rb:3
should at /home/andreas/projects/neo4j-core/lib/test.rb:9
(root) at /home/andreas/projects/neo4j-core/lib/test.rb:26
load at org/jruby/RubyKernel.java:1068
(root) at main.rb:1
java version “1.7.0_147-icedtea”
OpenJDK Runtime Environment (IcedTea7 2.0) (7~b147-2.0-0ubuntu0.11.10.1)
OpenJDK 64-Bit Server VM (build 21.0-b17, mixed mode)
Cheers
Andreas