- a second attempt to make test_helper compatible with 1.8.x versions of Ruby

This commit is contained in:
Mark VanderVoord
2014-12-18 16:02:29 -05:00
parent e1cd4135b4
commit 6d4cdf9783
+7 -2
View File
@@ -15,8 +15,13 @@ end
def create_stub(funcs)
stub = Class.new
funcs.each_pair do |k,v|
stub.define_singleton_method(k) {|*unused| return v }
if (RUBY_VERSION.split('.')[0].to_i >= 2)
funcs.each_pair {|k,v| stub.define_singleton_method(k) {|unused=nil| return v } }
else
blob = "class << stub\n"
funcs.each_pair {|k,v| blob += "def #{k.to_s}(unused=nil)\n #{v.inspect}\nend\n" }
blob += "end"
eval blob
end
stub
end