Sha256: 10b8a32fad8e50e0be66173a249ec3b1471e0a012ec1a241dece1242ed6b1d20

Contents?: true

Size: 1.7 KB

Versions: 1

Compression:

Stored size: 1.7 KB

Contents

require 'spec_helper'

describe PrivatePlease, 'calling marked methods' do
  before() do
    PrivatePlease.activate(true)
  end
  let(:storage) { PrivatePlease.storage }

  module Calling
    class Simple
      def public_m ;  private_m()   end
      def private_m; 'SUCCESS'      end
      private_please  :private_m
    end
  end

#--------------
  context 'from INSIDE the class' do
#--------------

    before { Calling::Simple.new.public_m }

    it('records the call to the p+p method in PrivatePlease.inside_called_candidates') do
      storage.inside_called_candidates[ 'Calling::Simple'].to_a.should == [:private_m]
      storage.outside_called_candidates['Calling::Simple'].to_a.should == []
    end

    it('records multiple calls only once') do
      2.times{ Calling::Simple.new.public_m }
      storage.inside_called_candidates[ 'Calling::Simple'].to_a.should == [:private_m]
      storage.outside_called_candidates['Calling::Simple'].to_a.should == []
    end
  end


#--------------
  context 'from OUTSIDE the class' do
#--------------

    before { @result = Calling::Simple.new.private_m }

    it 'goes thru (as the method is still public)' do
      @result.should == 'SUCCESS'
    end

    it('records the call to the p+p method in PrivatePlease.inside_called_candidates') do
      storage.inside_called_candidates[ 'Calling::Simple'].to_a.should == []
      storage.outside_called_candidates['Calling::Simple'].to_a.should == [:private_m]
    end

    it('records multiple calls only once') do
      2.times{ Calling::Simple.new.private_m }
      storage.inside_called_candidates[ 'Calling::Simple'].to_a.should == []
      storage.outside_called_candidates['Calling::Simple'].to_a.should == [:private_m]
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
private_please-0.0.2 spec/02_calling_methods_spec.rb