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.6.3 lib/sugar-high/rspec/matchers/have_aliases.rb
sugar-high-0.6.2.1 lib/sugar-high/rspec/matchers/have_aliases.rb
sugar-high-0.6.1 lib/sugar-high/rspec/matchers/have_aliases.rb
sugar-high-0.6.0 lib/sugar-high/rspec/matchers/have_aliases.rb
sugar-high-0.5.5 lib/sugar-high/rspec/matchers/have_aliases.rb
sugar-high-0.5.4 lib/sugar-high/rspec/matchers/have_aliases.rb
sugar-high-0.5.3 lib/sugar-high/rspec/matchers/have_aliases.rb
sugar-high-0.5.1 lib/sugar-high/rspec/matchers/have_aliases.rb
sugar-high-0.5.0 lib/sugar-high/rspec/matchers/have_aliases.rb
sugar-high-0.4.9.5 lib/sugar-high/rspec/matchers/have_aliases.rb
sugar-high-0.4.9.3 lib/sugar-high/rspec/matchers/have_aliases.rb
sugar-high-0.4.9.2 lib/sugar-high/rspec/matchers/have_aliases.rb
sugar-high-0.4.9.1 lib/sugar-high/rspec/matchers/have_aliases.rb
sugar-high-0.4.9 lib/sugar-high/rspec/matchers/have_aliases.rb
sugar-high-0.4.8 lib/sugar-high/rspec/matchers/have_aliases.rb
sugar-high-0.4.7 lib/sugar-high/rspec/matchers/have_aliases.rb
sugar-high-0.4.6.4 lib/sugar-high/rspec/matchers/have_aliases.rb
sugar-high-0.4.6.3 lib/sugar-high/rspec/matchers/have_aliases.rb
sugar-high-0.4.6.2 lib/sugar-high/rspec/matchers/have_aliases.rb
sugar-high-0.4.6.1 lib/sugar-high/rspec/matchers/have_aliases.rb