title: How to pass objects with stubbed methods in it_behaves_like to shared_examples_for block in rspec?
body: <p>I have a spec like</p>
  
  <pre><code>describe MyClass do
    it_behaves_like SharedClass, MyClass.new
  end
  </code></pre>
  
  <p>and in my shared example spec, I have</p>
  
  <pre><code>shared_examples_for SharedClass do |instance|
    before do 
      instance.some_my_class_method = double
    end
    # some specs here
  end
  </code></pre>
  
  <p>There are few methods in MyClass instance that I cannot stub in the shared_examples_for block, so I want to stub them before passing it in it_behaves_like statement. like,</p>
  
  <pre><code>describe MyClass do
    before do
      @instance = MyClass.new
      @instance.stub(:my_class_method)
    end
    it_behaves_like SharedClass, @instance
  end
  </code></pre>
  
  <p>but I cannot do that.It throws me<br>
  NoMethodError:
         undefined method `some_my_class_method=' for nil:NilClass</p>
  
  <p>somehow I am not able to access that @instance object in the shared_examples_for context.
  I am using ruby 1.9.3p392 and rspec (2.14.1)</p>