Sha256: d886b9b0954f67fea788c0c811b5b381ffb66859373e608693d1fc7cb549254c

Contents?: true

Size: 1.14 KB

Versions: 56

Compression:

Stored size: 1.14 KB

Contents

module RSpec
  module Sugar
  end
end

module RSpec::Sugar
  module Matchers  
    class HaveAliases

      attr_reader :method, :alias_methods, :cause

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

      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

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

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

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

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

    def have_aliases method, *alias_methods
      HaveAliases.new method, *alias_methods
    end
  end
end

Version data entries

56 entries across 56 versions & 1 rubygems

Version Path
sugar-high-0.2.8 lib/sugar-high/rspec/matchers/have_aliases.rb
sugar-high-0.2.7 lib/sugar-high/rspec/matchers/have_aliases.rb
sugar-high-0.2.6 lib/sugar-high/rspec/matchers/have_aliases.rb
sugar-high-0.2.5 lib/sugar-high/rspec/matchers/have_aliases.rb
sugar-high-0.2.4 lib/sugar-high/rspec/matchers/have_aliases.rb
sugar-high-0.2.2 lib/sugar-high/rspec/matchers/have_aliases.rb
sugar-high-0.2.1 lib/sugar-high/rspec/matchers/have_aliases.rb
sugar-high-0.2.0 lib/sugar-high/rspec/matchers/have_aliases.rb
sugar-high-0.1.8 lib/sugar-high/rspec/matchers/have_aliases.rb
sugar-high-0.1.7 lib/sugar-high/rspec/matchers/have_aliases.rb
sugar-high-0.1.6 lib/sugar-high/matchers/have_aliases.rb
sugar-high-0.1.5 lib/sugar-high/matchers/have_aliases.rb
sugar-high-0.1.4 lib/sugar-high/matchers/have_aliases.rb
sugar-high-0.1.2 lib/sugar-high/matchers/have_aliases.rb
sugar-high-0.1.1 lib/sugar-high/matchers/have_aliases.rb
sugar-high-0.1.0 lib/sugar-high/matchers/have_aliases.rb