Class: Synthesis::Adapter

Inherits:
Object show all
Includes:
Logging
Defined in:
lib/synthesis/adapter.rb

Overview

Subclasses of Adapter must implement the run, collect_expectations and stop_collecting_expectations methods. For example implementations refer to Synthesis::MochaAdapter and Synthesis::RSpecAdapter.

Direct Known Subclasses

MochaAdapter, RSpecAdapter

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

#silence!, #speak!

Constructor Details

#initialize(pattern) ⇒ Adapter

Returns a new instance of Adapter.



9
10
11
# File 'lib/synthesis/adapter.rb', line 9

def initialize(pattern)
  @pattern = pattern
end

Class Method Details

.inherited(subclass) ⇒ Object



33
34
35
# File 'lib/synthesis/adapter.rb', line 33

def inherited(subclass)
  @adapter = subclass
end

.load(pattern) ⇒ Object



37
38
39
# File 'lib/synthesis/adapter.rb', line 37

def load(pattern)
  @adapter.new(pattern)
end

Instance Method Details

#fail_unless(&block) ⇒ Object

The block parameter will yield twice, once for collecting and once for verifying the collected expectations.



15
16
17
18
19
20
21
22
23
24
# File 'lib/synthesis/adapter.rb', line 15

def fail_unless(&block)
  log "Collecting expectations..."
  collect_expectations
  Dir[*@pattern].each { |t| require t }
  exit -1 unless yield
  log "Verifying expectation invocations..."
  stop_collecting_expectations
  ExpectationRecord.record_invocations
  yield
end

#ignore_instances_of(type) ⇒ Object

The type of object representing a mock or stub for the test framework. Objects of this type will be ignored by Synthesis.



28
29
30
# File 'lib/synthesis/adapter.rb', line 28

def ignore_instances_of(type)
  Synthesis.const_set(:MOCK_OBJECT, type)
end