Class: RSpec::Sugar::Matchers::HaveAliases

Inherits:
Object
  • Object
show all
Defined in:
lib/sugar-high/rspec/matchers/have_aliases.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method, *alias_methods) ⇒ HaveAliases

Returns a new instance of HaveAliases.



12
13
14
15
16
# File 'lib/sugar-high/rspec/matchers/have_aliases.rb', line 12

def initialize method, *alias_methods
  @method = method
  @alias_methods = alias_methods.flatten
  @cause = []
end

Instance Attribute Details

#alias_methodsObject (readonly)

Returns the value of attribute alias_methods.



10
11
12
# File 'lib/sugar-high/rspec/matchers/have_aliases.rb', line 10

def alias_methods
  @alias_methods
end

#causeObject (readonly)

Returns the value of attribute cause.



10
11
12
# File 'lib/sugar-high/rspec/matchers/have_aliases.rb', line 10

def cause
  @cause
end

#methodObject (readonly)

Returns the value of attribute method.



10
11
12
# File 'lib/sugar-high/rspec/matchers/have_aliases.rb', line 10

def method
  @method
end

Instance Method Details

#cause_msgObject



34
35
36
# File 'lib/sugar-high/rspec/matchers/have_aliases.rb', line 34

def cause_msg
  cause[0..3].join('.')
end

#failure_messageObject



38
39
40
# File 'lib/sugar-high/rspec/matchers/have_aliases.rb', line 38

def failure_message
  "Expected aliases to exist, but: #{cause_msg}"
end

#is_alias?(obj, alias_meth) ⇒ Boolean

Returns:



30
31
32
# File 'lib/sugar-high/rspec/matchers/have_aliases.rb', line 30

def is_alias? obj, alias_meth
  obj.respond_to? alias_meth
end

#matches?(obj, options = {}) ⇒ Boolean

Returns:



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/sugar-high/rspec/matchers/have_aliases.rb', line 18

def matches? obj, options={}
  if !obj.respond_to? method
    cause << "Method ##{method} to alias does NOT exist"
    return nil
  end

  alias_methods.each do |method|
    cause << "Alias method ##{method} does NOT exist" if !is_alias? obj, alias_meth
  end
  cause.empty?
end

#negative_failure_messageObject



42
43
44
# File 'lib/sugar-high/rspec/matchers/have_aliases.rb', line 42

def negative_failure_message
  "Did not expect aliases to exist but, #{cause_msg}".gsub /NOT/, ''
end