Sha256: 72d6148a6c266c6acc1f2d305eb2d3167f05a7be9e4797c75b763d2ecad0e1e8
Contents?: true
Size: 1.74 KB
Versions: 3
Compression:
Stored size: 1.74 KB
Contents
module FlickrMocks # contains various helper methods for comparing and marshaling FlickRaw::Response and # ResponseList objects. module Helpers class << self # returns the file extension used to store the marshaled FlickRaw fixtures def extension ".marshal" end # returns the file name for the marshaled FlickRaw fixture def fname_fixture(symbol) raise RunTimeError unless symbol.is_a? Symbol symbol.to_s + extension end # compares two FlickRaw::Response or two FlickRaw::ResponseList. # It recursively checks the internal state of these two objects. def equivalent?(a,b) return false if a.class != b.class case a when FlickRaw::Response,FlickRaw::ResponseList then a.methods(false).collect do |m| b.respond_to?(m) ? equivalent?(a.send(m),b.send(m)) : false end.inject(true) {|r1,r2| r1 && r2} when Hash then a.keys.collect do |k| b.has_key?(k) ? equivalent?(a[k],b[k]) : false end.inject(true){|r1,r2| r1 && r2} when Array then a.each_with_index.collect do |v,i| b.length == a.length ? equivalent?(v,b[i]) : false end.inject(true) {|r1,r2| r1 && r2} else a == b end end # saves the marshaled version of the supplied object into a file def dump(response,file) begin f = File.open(file,'w') f.write Marshal.dump(response) ensure f.close end end # returns the un-marshaled contents of the user-specified file def load(file) begin f=File.open(file,'r') Marshal.load(f) ensure f.close end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
flickrmocks-0.9.2 | lib/flickr_mocks/helpers.rb |
flickrmocks-0.9.1 | lib/flickr_mocks/helpers.rb |
flickrmocks-0.9.0 | lib/flickr_mocks/helpers.rb |