Class: Fix::Expectation

Inherits:
Object
  • Object
show all
Includes:
Spectus::DSL
Defined in:
lib/fix/expectation.rb

Direct Known Subclasses

ExpectationHigh

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, positive, definition, *args) ⇒ Expectation

Returns a new instance of Expectation.



12
13
14
15
16
17
18
19
20
# File 'lib/fix/expectation.rb', line 12

def initialize object, positive, definition, *args
  @positive   = positive
  @definition = definition
  @args       = args
  @priority   = DB.instance.random.rand

  DB.instance.update(object => SortedSet[]) unless DB.instance.key? object
  DB.instance.fetch(object).add self
end

Instance Attribute Details

#priorityObject (readonly)

Returns the value of attribute priority.



10
11
12
# File 'lib/fix/expectation.rb', line 10

def priority
  @priority
end

Instance Method Details

#<=>(other) ⇒ Object



22
23
24
# File 'lib/fix/expectation.rb', line 22

def <=> other
  self.priority <=> other.priority
end

#evaluate(front_object) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/fix/expectation.rb', line 26

def evaluate front_object
  Thread.new {
    subject = Subject.new front_object, *@args
    got     = nil

    report = begin
      expect { got = subject.actual }.__send__ target, @definition
    rescue => e
      e
    end

    data = presenter report, got, subject

    Hash[ data.to_a + meta(subject).to_a ].merge object: front_object
  }.value
end