title: How can I test delegating methods using SimpleDelegator and RSpec?
body: <p>I'm using Ruby 1.9.3 and trying to make some tests with RSpec. </p>
  
  <p>I have a class: </p>
  
  <pre><code>class A 
    def method1
      "test"
     end
  end
  
  class B &lt; SimpleDelegator
    def initialize(events)
      @events = events 
    end
  end
  </code></pre>
  
  <p>Now I'm trying to test delegation behaviour: </p>
  
  <pre><code>require 'spec_helper'
  
  RSpec.describe B do
    let(:a) { A.new }
    let(:b) { B.new(a) }
  
    it "Should delegate unknown calls to A object" do
      expect(b.method1).not_to eq(nil)
    end
  end
  </code></pre>
  
  <p>I get the following error: </p>
  
  <pre><code> NoMethodError:
     undefined method `method1' for nil:B
  </code></pre>
  
  <p>Seems that the test would pass if add method_missing manually: </p>
  
  <pre><code>class B &lt; SimpleDelegator
    def initialize(events)
      @events = events 
    end
    def method_missing(meth, *args, &amp;blk)
      @events.send(meth, *args, &amp;blk)
    end
  end
  </code></pre>
  
  <p>What I'm doing wrong here? </p>
  
  <p>Thanks </p>