Skip to content

Instantly share code, notes, and snippets.

@peteryates
Forked from efexen/gist:62db8c7b6c4756f193fe
Last active August 29, 2015 14:18
Show Gist options
  • Save peteryates/bcc2856a1b4a7c395d76 to your computer and use it in GitHub Desktop.
Save peteryates/bcc2856a1b4a7c395d76 to your computer and use it in GitHub Desktop.

Revisions

  1. peteryates revised this gist Mar 31, 2015. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -9,11 +9,11 @@ RSpec::Matchers.define :alias_from do |alias_method|
    raise "expected alias_method from #{alias_method} to #{@original_method} but #{alias_method} is not defined"
    end

    expect(subject.method(alias_method)).to eq(subject.method(@original_method))
    subject.method(alias_method).eql?(subject.method(@original_method))
    end

    description do
    "RSpec matcher for alias_method"
    "delegate :#{@original_method} to :#{alias_method}"
    end

    failure_message do |text|
    @@ -25,4 +25,4 @@ RSpec::Matchers.define :alias_from do |alias_method|
    end

    chain(:to) { |original_method| @original_method = original_method }
    end
    end
  2. @efexen efexen created this gist Jul 22, 2014.
    28 changes: 28 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    # Original: https://gist.github.com/otaviomedeiros/1950961
    # Updated for new RSpec syntax

    RSpec::Matchers.define :alias_from do |alias_method|
    match do |subject|
    begin
    subject.send(alias_method)
    rescue NoMethodError
    raise "expected alias_method from #{alias_method} to #{@original_method} but #{alias_method} is not defined"
    end

    expect(subject.method(alias_method)).to eq(subject.method(@original_method))
    end

    description do
    "RSpec matcher for alias_method"
    end

    failure_message do |text|
    "expected alias_method from #{alias_method} to #{@original_method}"
    end

    failure_message_when_negated do |text|
    "do not expected alias_method from #{alias_method} to #{@original_method}"
    end

    chain(:to) { |original_method| @original_method = original_method }
    end