No commit activity in last 3 years
No release in over 3 years
RSpec shared context to make private methods temporarily public.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.5
>= 0
>= 0
 Project Readme

rspec-context-private

Writing Ruby? 👍 Using RSpec? 👍 Feeling naughty? 😱 Want to test some private methods? 😲

# Gemfile
gem 'rspec-context-private'
# example.rb
class Example
  private def foo
    'bar'
  end
end
# example_spec.rb
describe Example do
  describe 'some private methods', :private do
    it 'does not raise an error' do
      expect{subject.foo}.not_to raise_error(NoMethodError)
    end
  end
end

Why would you EVER!? want to test a private method?

If you're using some flavor of TDD, you might want to test some private methods that you develop along the way. Maybe you'll delete them later? Or maybe you're a crazy rebel 😝 and you'll keep the tests around and make your code difficult to refactor and disappoint the Internet!

Whatever your reason - this gem makes it more pleasant to test private methods.

Credits

Written by @barelyknown.

This gem uses RSpec's shared context feature.

The idea for the gem came from this old blog post by Jay Fielder.