Class: RSpec::Fire::FireClassDoubleBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/fire.rb

Defined Under Namespace

Modules: AsReplacedConstant

Class Method Summary collapse

Class Method Details

.build(doubled_class, stubs = {}) ⇒ Object



275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
# File 'lib/rspec/fire.rb', line 275

def self.build(doubled_class, stubs = {})
  Module.new do
    extend FireDoublable

    @__doubled_class_name = doubled_class
    @__checked_methods = :public_methods
    @__method_finder   = :method

    verify_constant_name if RSpec::Fire.configuration.verify_constant_names?

    ::RSpec::Mocks::TestDouble.extend_onto self,
      doubled_class, stubs.merge(:__declared_as => "FireClassDouble")

    def self.as_replaced_constant(options = {})
      RSpec::Mocks::ConstantStubber.stub(@__doubled_class_name, self, options)
      @__original_class = RSpec::Mocks::Constant.original(@__doubled_class_name).original_value

      extend AsReplacedConstant
      self
    end

    def self.to_s
      @__doubled_class_name + " (fire double)"
    end

    def self.inspect
      to_s
    end

    def self.name
      @__doubled_class_name
    end
  end
end