class Bogus::CreatesFakesWithStubbedMethods
Public Instance Methods
create(name = nil, methods = {}, &block)
click to toggle source
# File lib/bogus/fakes/creates_fakes_with_stubbed_methods.rb, line 8 def create(name = nil, methods = {}, &block) if name.is_a?(Hash) methods = name name = nil end fake = responds_to_everything unless name fake_opts, methods = split_methods(methods) fake_definition = get_configuration(name, fake_opts, methods, block) fake ||= creates_fakes.create(fake_definition.name, fake_definition.opts, &fake_definition.class_block) multi_stubber.stub_all(fake, fake_definition.stubs) end
Private Instance Methods
get_configuration(name, fake_opts, methods, block)
click to toggle source
# File lib/bogus/fakes/creates_fakes_with_stubbed_methods.rb, line 32 def get_configuration(name, fake_opts, methods, block) fake = FakeDefinition.new(name: name, opts: fake_opts, stubs: methods, class_block: block) return fake unless fake_configuration.include?(name) configured_fake = fake_configuration.get(name) configured_fake.merge(fake) end
split_methods(methods)
click to toggle source
# File lib/bogus/fakes/creates_fakes_with_stubbed_methods.rb, line 27 def split_methods(methods) fake_args = proc{ |k,_| [:as].include?(k) } [methods.select(&fake_args), methods.reject(&fake_args)] end