Class: RSpec::Contracts::Requirement

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(interface_name, method_name, options = {}) ⇒ Requirement

Returns a new instance of Requirement.



9
10
11
12
13
14
# File 'lib/rspec/contracts/requirement.rb', line 9

def initialize(interface_name, method_name, options = {})
  @interface_name = interface_name
  @method_name = method_name
  @arguments = options[:arguments]
  @return_value = options[:return_value]
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



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

def arguments
  @arguments
end

#interface_nameObject (readonly)

Returns the value of attribute interface_name.



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

def interface_name
  @interface_name
end

#method_nameObject (readonly)

Returns the value of attribute method_name.



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

def method_name
  @method_name
end

#return_valueObject (readonly)

Returns the value of attribute return_value.



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

def return_value
  @return_value
end

Class Method Details

.create(*args) ⇒ Object



20
21
22
# File 'lib/rspec/contracts/requirement.rb', line 20

def self.create(*args)
  group.add new(*args)
end

.groupObject



16
17
18
# File 'lib/rspec/contracts/requirement.rb', line 16

def self.group
  @group ||= RequirementGroup.new
end

Instance Method Details

#matches?(requirement) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
27
28
# File 'lib/rspec/contracts/requirement.rb', line 24

def matches?(requirement)
  [:interface_name, :method_name, :arguments, :return_value].select do |attribute|
    requirement.send(attribute) != send(attribute)
  end.empty?
end