Class: ConvenientService::RSpec::PrimitiveMatchers::Classes::SingletonPrependModule

Inherits:
Object
  • Object
show all
Defined in:
lib/convenient_service/rspec/primitive_matchers/classes/singleton_prepend_module.rb

Instance Method Summary collapse

Constructor Details

#initialize(mod) ⇒ void

Parameters:

  • mod (Module)


27
28
29
# File 'lib/convenient_service/rspec/primitive_matchers/classes/singleton_prepend_module.rb', line 27

def initialize(mod)
  @mod = mod
end

Instance Method Details

#descriptionString

Returns:

  • (String)


44
45
46
# File 'lib/convenient_service/rspec/primitive_matchers/classes/singleton_prepend_module.rb', line 44

def description
  "`singleton_class.prepend` module `#{mod}`"
end

#failure_messageString

Returns:

  • (String)


51
52
53
# File 'lib/convenient_service/rspec/primitive_matchers/classes/singleton_prepend_module.rb', line 51

def failure_message
  "expected `#{klass}` to `singleton_class.prepend` module `#{mod}`"
end

#failure_message_when_negatedString

Returns:

  • (String)


58
59
60
# File 'lib/convenient_service/rspec/primitive_matchers/classes/singleton_prepend_module.rb', line 58

def failure_message_when_negated
  "expected `#{klass}` NOT to `singleton_class.prepend` module `#{mod}`"
end

#matches?(klass) ⇒ Boolean

Parameters:

  • klass (Class, Module)

Returns:

  • (Boolean)


35
36
37
38
39
# File 'lib/convenient_service/rspec/primitive_matchers/classes/singleton_prepend_module.rb', line 35

def matches?(klass)
  @klass = klass

  klass.singleton_class.ancestors.take_while { |ancestor| ancestor != klass }.include?(mod)
end