Class: JobSpec::AdhocExpectations

Inherits:
Object
  • Object
show all
Defined in:
lib/job_spec/adhoc_expectations.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(expectation, &block) ⇒ AdhocExpectations

Returns a new instance of AdhocExpectations.



32
33
34
35
36
# File 'lib/job_spec/adhoc_expectations.rb', line 32

def initialize(expectation, &block)
  @expectation = expectation
  @block = block
  instance_eval(&block) unless block.nil?
end

Class Method Details

.clear!Object



3
4
5
# File 'lib/job_spec/adhoc_expectations.rb', line 3

def self.clear!
  @expectations = nil
end

.define(expectation, &block) ⇒ Object



7
8
9
10
# File 'lib/job_spec/adhoc_expectations.rb', line 7

def self.define(expectation, &block)
  @expectations ||= []
  @expectations << new(expectation, &block)
end

.rolesObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/job_spec/adhoc_expectations.rb', line 12

def self.roles
  return [] if @expectations.nil?

  roles = {}
  @expectations.each do |expectation|
    expectation.to_a.each do |role_expectation|
      roles[role_expectation[:role]] ||= {
        name: role_expectation[:role],
        expectations: []
      }

      roles[role_expectation[:role]][:expectations] << {
        expectation: role_expectation[:expectation],
        description: role_expectation[:description]
      }
    end
  end
  roles.values
end

Instance Method Details

#description(description) ⇒ Object



38
39
40
# File 'lib/job_spec/adhoc_expectations.rb', line 38

def description(description)
  @description = description
end

#roles(*roles) ⇒ Object



42
43
44
# File 'lib/job_spec/adhoc_expectations.rb', line 42

def roles(*roles)
  @roles = roles
end

#to_aObject



46
47
48
49
50
51
52
53
54
# File 'lib/job_spec/adhoc_expectations.rb', line 46

def to_a
  @roles.map do |role|
    {
      role: role,
      expectation: @expectation,
      description: @description
    }
  end
end