Class: RSpec::Sugar::Matchers::HaveAliases
- Defined in:
- lib/sugar-high/rspec/matchers/have_aliases.rb
Instance Attribute Summary collapse
-
#alias_methods ⇒ Object
readonly
Returns the value of attribute alias_methods.
-
#cause ⇒ Object
readonly
Returns the value of attribute cause.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
Instance Method Summary collapse
- #cause_msg ⇒ Object
- #failure_message ⇒ Object
-
#initialize(method, *alias_methods) ⇒ HaveAliases
constructor
A new instance of HaveAliases.
- #is_alias?(obj, alias_meth) ⇒ Boolean
- #matches?(obj, options = {}) ⇒ Boolean
- #negative_failure_message ⇒ Object
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_methods ⇒ Object (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 |
#cause ⇒ Object (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 |
#method ⇒ Object (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_msg ⇒ Object
34 35 36 |
# File 'lib/sugar-high/rspec/matchers/have_aliases.rb', line 34 def cause_msg cause[0..3].join('.') end |
#failure_message ⇒ Object
38 39 40 |
# File 'lib/sugar-high/rspec/matchers/have_aliases.rb', line 38 def "Expected aliases to exist, but: #{cause_msg}" end |
#is_alias?(obj, alias_meth) ⇒ Boolean
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
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, ={} 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_message ⇒ Object
42 43 44 |
# File 'lib/sugar-high/rspec/matchers/have_aliases.rb', line 42 def "Did not expect aliases to exist but, #{cause_msg}".gsub /NOT/, '' end |