File: call_super_shared_spec.rb

package info (click to toggle)
ruby-memoizable 0.4.2-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 192 kB
  • sloc: ruby: 605; makefile: 2
file content (23 lines) | stat: -rw-r--r-- 740 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# encoding: utf-8

shared_examples 'it calls super' do |method|
  around do |example|
    # Restore original method after each example
    original = "original_#{method}"
    superclass.class_eval do
      alias_method original, method
      example.call
      undef_method method
      alias_method method, original
    end
  end

  it "delegates to the superclass ##{method} method" do
    # This is the most succinct approach I could think of to test whether the
    # superclass method is called. All of the built-in rspec helpers did not
    # seem to work for this.
    called = false
    superclass.class_eval { define_method(method) { |_| called = true } }
    expect { subject }.to change { called }.from(false).to(true)
  end
end