January 2010
2 posts
Fun (and evil) tricks with rspec
original_glob = Dir.method(:glob)
Dir.stub!(:glob).and_return do |glob_string|
if glob_string =~ /public/
glob_string
else
original_glob.call(glob_string)
end
end
Of course, you shouldn’t do this because return blocks on stubs (calculated return blocks) are evil.
Still fun, though.
JSON.stringify bug with Native FF Implementation
Firefox past 3.5.4 natively implements JSON.stringify with replacers, similarly to the way JSON2 works. However, it’s doing something wrong (optimization related?). Supposedly, you can pass stringify a replacer function as a second argument and it will use whatever is returned from that argument as the value in the serialized copy. HOWEVER, if you pass a value back that contains the same...