Class: RSpec::SleepingKingStudios::Support::MethodSignatureExpectation Private

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/sleeping_king_studios/support/method_signature_expectation.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMethodSignatureExpectation

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

rubocop:disable Metrics/ClassLength



10
11
12
13
14
15
16
17
18
# File 'lib/rspec/sleeping_king_studios/support/method_signature_expectation.rb', line 10

def initialize
  @min_arguments       = 0
  @max_arguments       = 0
  @unlimited_arguments = false
  @keywords            = []
  @any_keywords        = false
  @block_argument      = false
  @errors              = {}
end

Instance Attribute Details

#any_keywords=(value) ⇒ Object (writeonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



22
23
24
# File 'lib/rspec/sleeping_king_studios/support/method_signature_expectation.rb', line 22

def any_keywords=(value)
  @any_keywords = value
end

#block_argument=(value) ⇒ Object (writeonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



22
23
24
# File 'lib/rspec/sleeping_king_studios/support/method_signature_expectation.rb', line 22

def block_argument=(value)
  @block_argument = value
end

#errorsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



24
25
26
# File 'lib/rspec/sleeping_king_studios/support/method_signature_expectation.rb', line 24

def errors
  @errors
end

#keywordsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



20
21
22
# File 'lib/rspec/sleeping_king_studios/support/method_signature_expectation.rb', line 20

def keywords
  @keywords
end

#max_argumentsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



20
21
22
# File 'lib/rspec/sleeping_king_studios/support/method_signature_expectation.rb', line 20

def max_arguments
  @max_arguments
end

#min_argumentsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



20
21
22
# File 'lib/rspec/sleeping_king_studios/support/method_signature_expectation.rb', line 20

def min_arguments
  @min_arguments
end

#unlimited_arguments=(value) ⇒ Object (writeonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



22
23
24
# File 'lib/rspec/sleeping_king_studios/support/method_signature_expectation.rb', line 22

def unlimited_arguments=(value)
  @unlimited_arguments = value
end

Instance Method Details

#any_keywords?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


61
62
63
# File 'lib/rspec/sleeping_king_studios/support/method_signature_expectation.rb', line 61

def any_keywords?
  !!@any_keywords
end

#block_argument?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


65
66
67
# File 'lib/rspec/sleeping_king_studios/support/method_signature_expectation.rb', line 65

def block_argument?
  !!@block_argument
end

#descriptionObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/rspec/sleeping_king_studios/support/method_signature_expectation.rb', line 26

def description # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
  messages = []

  messages <<
    if min_arguments == max_arguments
      "#{min_arguments} argument#{'s' unless min_arguments == 1}"
    else
      "#{min_arguments}..#{max_arguments} arguments"
    end

  messages << 'unlimited arguments' if unlimited_arguments?

  unless keywords.empty?
    keywords_list = array_tools.humanize_list keywords.map(&:inspect)
    messages << "keyword#{'s' unless keywords.one?} #{keywords_list}"
  end

  messages << 'arbitrary keywords' if any_keywords?

  messages << 'a block' if block_argument?

  "with #{array_tools.humanize_list messages}"
end

#matches?(method) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


50
51
52
53
54
55
56
57
58
59
# File 'lib/rspec/sleeping_king_studios/support/method_signature_expectation.rb', line 50

def matches?(method)
  @signature = MethodSignature.new(method)
  @errors    = {}

  match = true
  match = false unless matches_arity?
  match = false unless matches_keywords?
  match = false unless matches_block?
  match
end

#unlimited_arguments?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


69
70
71
# File 'lib/rspec/sleeping_king_studios/support/method_signature_expectation.rb', line 69

def unlimited_arguments?
  !!@unlimited_arguments
end