Class: RSpec::Contracts::Message

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method_name, specifications = {}) ⇒ Message

Returns a new instance of Message.



7
8
9
10
# File 'lib/rspec/contracts/message.rb', line 7

def initialize(method_name, specifications = {})
  @method_name = method_name
  @specifications = specifications
end

Instance Attribute Details

#method_nameObject (readonly)

Returns the value of attribute method_name.



4
5
6
# File 'lib/rspec/contracts/message.rb', line 4

def method_name
  @method_name
end

#specificationsObject

Returns the value of attribute specifications.



5
6
7
# File 'lib/rspec/contracts/message.rb', line 5

def specifications
  @specifications
end

Instance Method Details

#fully_described_by?(message) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
18
19
20
# File 'lib/rspec/contracts/message.rb', line 12

def fully_described_by?(message)
  return false if message.method_name != method_name
  @specifications.each do |name, specification|
    unless specification.fully_described_by? message.specifications[name]
      return false
    end
  end
  true
end

#to_hashObject



22
23
24
25
26
27
# File 'lib/rspec/contracts/message.rb', line 22

def to_hash
  {
    :method_name => method_name,
    :specifications => specifications.values.map(&:to_hash),
  }
end