Skip to content

Instantly share code, notes, and snippets.

@evg2108
Last active May 4, 2016 13:40
Show Gist options
  • Save evg2108/83c9ee84f897b6bf9c2c2002f31f5679 to your computer and use it in GitHub Desktop.
Save evg2108/83c9ee84f897b6bf9c2c2002f31f5679 to your computer and use it in GitHub Desktop.
RSpec for private methods

add this to spec_helper.rb or rails_helper.rb

# for testing private methods of classes
RSpec.shared_context 'private', private: true do

  before :all do
    described_class.class_eval do
      @original_private_instance_methods = private_instance_methods
      public *@original_private_instance_methods
    end
  end

  after :all do
    described_class.class_eval do
      private *@original_private_instance_methods
    end
  end

end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment