Skip to content

Instantly share code, notes, and snippets.

@rishiip
Forked from mistrikushal/Rspec private methods.txt
Created December 8, 2015 11:08
Show Gist options
  • Save rishiip/bd36c65f85031e66ee56 to your computer and use it in GitHub Desktop.
Save rishiip/bd36c65f85031e66ee56 to your computer and use it in GitHub Desktop.
RSpec - Testing private methods of a model
# RSpec allows us to test private methods of a model.
for example,
class User
def is_active?
true
end
private :is_active?
end
RSpec.describe 'private methods' do
subject { User.new }
# success pass
it { is_expected.to is_active? }
# deliberate failure
it { is_expected.to has_secret? }
end
# :) Happy Coding
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment