Sha256: 689b8e6b4bc65624566dd59866841b399b596031c031023b380a5e5b1180c3ed
Contents?: true
Size: 765 Bytes
Versions: 2
Compression:
Stored size: 765 Bytes
Contents
require 'ostruct' # A simple mocking facility. Typically used in test cases. # # === Example: # # class ContextMock < Mock # mock :response_headers, {} # mock :host_url, 'http://www.nitrohq.com' # end # # ctx = ContextMock.new # ctx.response_headers['location'] = url # ctx.host_url class Mock < OpenStruct class << self attr :mocks # Mock a symbol, val is the default values. Useful # for mocking structured variables like arrays and # hashes. def mock(sym, val) @mocks ||= {} @mocks[sym] = val attr_accessor sym end end def initialize super for sym, val in self.class.mocks unless val.is_a? Proc instance_variable_set "@#{sym}", val end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
glue-0.23.0 | lib/glue/mock.rb |
glue-0.24.0 | lib/glue/mock.rb |