private_please 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/Guardfile +8 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/lib/private_please/candidates.rb +37 -0
- data/lib/private_please/configuration.rb +21 -0
- data/lib/private_please/line_change_tracker.rb +19 -0
- data/lib/private_please/recorder.rb +34 -0
- data/lib/private_please/report/template.txt.erb +15 -0
- data/lib/private_please/report.rb +47 -0
- data/lib/private_please/version.rb +3 -0
- data/lib/private_please.rb +92 -0
- data/private_please.gemspec +22 -0
- data/spec/01_marking_methods_spec.rb +28 -0
- data/spec/02_calling_methods_spec.rb +57 -0
- data/spec/03_configuration_spec.rb +51 -0
- data/spec/04_at_exit_report_printing_spec.rb +47 -0
- data/spec/spec_helper.rb +23 -0
- data/spec/todo_next_spec.rb +52 -0
- metadata +147 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Alain Ravet
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# PrivatePlease
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'private_please'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install private_please
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
module PrivatePlease
|
2
|
+
class Candidates
|
3
|
+
def self.instance
|
4
|
+
@@__instance ||= new
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.reset_before_new_test
|
8
|
+
@@__instance = nil
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_reader :candidates, :inside_called_candidates, :outside_called_candidates
|
12
|
+
def initialize
|
13
|
+
@candidates = Hash.new{ [] }
|
14
|
+
@inside_called_candidates = Hash.new{ [] }
|
15
|
+
@outside_called_candidates = Hash.new{ [] }
|
16
|
+
end
|
17
|
+
|
18
|
+
def record_candidate(self_class, name)
|
19
|
+
candidates[self_class.to_s] += Array(name)
|
20
|
+
end
|
21
|
+
|
22
|
+
def record_outside_call(self_class, name)
|
23
|
+
#TODO use a Set instead of an Array
|
24
|
+
unless outside_called_candidates[self_class.to_s].include?(name)
|
25
|
+
outside_called_candidates[self_class.to_s] += Array(name)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def record_inside_call(self_class, name)
|
30
|
+
#TODO use a Set instead of an Array
|
31
|
+
unless inside_called_candidates[self_class.to_s].include?(name)
|
32
|
+
inside_called_candidates[self_class.to_s] += Array(name)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module PrivatePlease
|
2
|
+
class Configuration
|
3
|
+
def self.instance
|
4
|
+
@@__instance ||= new
|
5
|
+
end
|
6
|
+
|
7
|
+
# only used by tests #TODO : refactor to remove .instance and .reset
|
8
|
+
def self.reset_before_new_test
|
9
|
+
@@__instance = nil
|
10
|
+
end
|
11
|
+
|
12
|
+
attr_reader :active
|
13
|
+
def initialize
|
14
|
+
@active
|
15
|
+
end
|
16
|
+
|
17
|
+
def activate(flag)
|
18
|
+
@active = flag
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module PrivatePlease
|
2
|
+
class LineChangeTracker
|
3
|
+
class << self
|
4
|
+
attr_accessor :prev_prev_self, :prev_self, :curr_self
|
5
|
+
@@prev_self = @@curr_self = nil
|
6
|
+
end
|
7
|
+
|
8
|
+
MY_TRACE_FUN = proc do |event, file, line, id, binding, klass|
|
9
|
+
return unless 'line'==event
|
10
|
+
LineChangeTracker.prev_prev_self = LineChangeTracker.prev_self
|
11
|
+
LineChangeTracker.prev_self = LineChangeTracker.curr_self
|
12
|
+
LineChangeTracker.curr_self = (eval 'self', binding)
|
13
|
+
#puts "my : #{event} in #{file}/#{line} id:#{id} klass:#{klass} - self = #{(eval'self', binding).inspect}"
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
set_trace_func(PrivatePlease::LineChangeTracker::MY_TRACE_FUN)
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module PrivatePlease
|
2
|
+
class Recorder
|
3
|
+
|
4
|
+
def self.instance
|
5
|
+
@@__instance ||= new(Candidates.instance)
|
6
|
+
end
|
7
|
+
|
8
|
+
# only used by tests #TODO : refactor to remove .instance and .reset
|
9
|
+
def self.reset_before_new_test
|
10
|
+
@@__instance = nil
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(storage)
|
14
|
+
@storage = storage
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
def record_candidate(self_class, name)
|
19
|
+
@storage.record_candidate(self_class, name)
|
20
|
+
# do more. ex: logging, ..
|
21
|
+
end
|
22
|
+
|
23
|
+
def record_outside_call(self_class, name)
|
24
|
+
@storage.record_outside_call(self_class, name)
|
25
|
+
# do more. ex: logging, ..
|
26
|
+
end
|
27
|
+
|
28
|
+
def record_inside_call(self_class, name)
|
29
|
+
@storage.record_inside_call(self_class, name)
|
30
|
+
# do more. ex: logging, ..
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
PrivatePlease report :
|
2
|
+
====================================================================================
|
3
|
+
Good candidates :
|
4
|
+
====================================================================================
|
5
|
+
<% good_candidates.keys.each do |klass|%>
|
6
|
+
in <%= klass %> :
|
7
|
+
<%= good_candidates[klass].join(', ')%>
|
8
|
+
<% end %>
|
9
|
+
|
10
|
+
====================================================================================
|
11
|
+
Bad candidates :
|
12
|
+
<% bad_candidates.keys.each do |klass| %>
|
13
|
+
in <%= klass %> :
|
14
|
+
<%= bad_candidates[klass].join(', ')%>
|
15
|
+
<% end %>
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module PrivatePlease
|
2
|
+
class Report
|
3
|
+
|
4
|
+
# @param [PrivatePlease::Recorder] recorder
|
5
|
+
def self.build(storage)
|
6
|
+
new(storage)
|
7
|
+
end
|
8
|
+
|
9
|
+
# @param [PrivatePlease::Recorder] recorder
|
10
|
+
def initialize(storage)
|
11
|
+
@storage = storage
|
12
|
+
end
|
13
|
+
|
14
|
+
TEMPLATE_PATH = File.dirname(__FILE__) + '/report/template.txt.erb'
|
15
|
+
|
16
|
+
def to_s
|
17
|
+
erb = ERB.new(File.read(TEMPLATE_PATH))
|
18
|
+
|
19
|
+
good_candidates = good_candidates() # for ERB/binding
|
20
|
+
bad_candidates = bad_candidates() # for ERB/binding
|
21
|
+
erb.result(binding)
|
22
|
+
end
|
23
|
+
|
24
|
+
# @return [Hash]
|
25
|
+
def never_called_candidates
|
26
|
+
@storage.candidates.tap do |all|
|
27
|
+
all.keys.each do |klass|
|
28
|
+
all[klass] = all[klass] - @storage.outside_called_candidates[klass] - @storage.inside_called_candidates[klass]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# @return [Hash]
|
34
|
+
def good_candidates
|
35
|
+
@storage.inside_called_candidates.tap do |all|
|
36
|
+
all.keys.each do |klass|
|
37
|
+
all[klass] = all[klass] - @storage.outside_called_candidates[klass]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# @return [Hash]
|
43
|
+
def bad_candidates
|
44
|
+
@storage.outside_called_candidates
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'private_please/version'
|
2
|
+
require 'private_please/configuration'
|
3
|
+
require 'private_please/candidates'
|
4
|
+
require 'private_please/recorder'
|
5
|
+
require 'private_please/report'
|
6
|
+
require 'private_please/line_change_tracker'
|
7
|
+
|
8
|
+
module PrivatePlease
|
9
|
+
|
10
|
+
def private_please(*args)
|
11
|
+
klass = self
|
12
|
+
args.reject!{|m| !klass.instance_methods.include?(m.to_s)}
|
13
|
+
candidates[klass.to_s] += args
|
14
|
+
args.each do |m|
|
15
|
+
mark_method(m)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
#--------------
|
20
|
+
# config
|
21
|
+
#--------------
|
22
|
+
def activate(flag)
|
23
|
+
config.activate(flag)
|
24
|
+
end
|
25
|
+
|
26
|
+
def active?
|
27
|
+
!!config.active
|
28
|
+
end
|
29
|
+
|
30
|
+
#--------------
|
31
|
+
# partners :
|
32
|
+
#--------------
|
33
|
+
def recorder ; Recorder .instance end
|
34
|
+
def storage ; Candidates .instance end
|
35
|
+
def config ; Configuration.instance end
|
36
|
+
|
37
|
+
def self.reset_before_new_test
|
38
|
+
Recorder .reset_before_new_test
|
39
|
+
Candidates .reset_before_new_test
|
40
|
+
Configuration .reset_before_new_test
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
#--------------
|
45
|
+
# candidates
|
46
|
+
#--------------
|
47
|
+
|
48
|
+
|
49
|
+
def candidates ; storage.candidates end
|
50
|
+
def inside_called_candidates ; storage.inside_called_candidates end
|
51
|
+
def outside_called_candidates ; storage.outside_called_candidates end
|
52
|
+
|
53
|
+
#--------------
|
54
|
+
# report
|
55
|
+
#--------------
|
56
|
+
def report
|
57
|
+
Report.build(storage)
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def mark_method(name)
|
63
|
+
self_class = self.class
|
64
|
+
PrivatePlease.recorder.record_candidate(self_class, name)
|
65
|
+
orig_method = instance_method(name)
|
66
|
+
define_method(name) do |*args, &blk|
|
67
|
+
set_trace_func(nil) #don't track activity while here
|
68
|
+
|
69
|
+
self_class = self.class
|
70
|
+
if PrivatePlease.active?
|
71
|
+
call_initiator = LineChangeTracker.prev_self
|
72
|
+
is_outside_call = call_initiator.class != self_class
|
73
|
+
is_outside_call ?
|
74
|
+
PrivatePlease.recorder.record_outside_call(self_class, name) :
|
75
|
+
PrivatePlease.recorder.record_inside_call( self_class, name)
|
76
|
+
end
|
77
|
+
|
78
|
+
# make the call :
|
79
|
+
set_trace_func(LineChangeTracker::MY_TRACE_FUN)
|
80
|
+
orig_method.bind(self).call(*args, &blk)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
Module.send :include, PrivatePlease
|
88
|
+
|
89
|
+
at_exit {
|
90
|
+
puts '-'*888
|
91
|
+
puts PrivatePlease.report.to_s
|
92
|
+
}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/private_please/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Alain Ravet"]
|
6
|
+
gem.email = ["alainravet@gmail.com"]
|
7
|
+
gem.description = %q{Test if methods can be made private}
|
8
|
+
gem.summary = %q{Test if methods can be made private}
|
9
|
+
gem.homepage = "https://github.com/alainravet/private_please"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "private_please"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = PrivatePlease::VERSION
|
17
|
+
|
18
|
+
gem.add_development_dependency 'rake' # to run 'All specs' in Rubymine
|
19
|
+
gem.add_development_dependency 'todo_next'
|
20
|
+
gem.add_development_dependency 'rspec'
|
21
|
+
gem.add_development_dependency 'guard-rspec'
|
22
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PrivatePlease, 'marking methods' do
|
4
|
+
|
5
|
+
it('records the candidates and associate them to the owning class') do
|
6
|
+
module Marking
|
7
|
+
class Simple1
|
8
|
+
def foo ; 'foo' end
|
9
|
+
def bar ; 'bar' end
|
10
|
+
def buz ; 'bar' end
|
11
|
+
private_please :bar, :buz
|
12
|
+
end
|
13
|
+
end
|
14
|
+
PrivatePlease.candidates['Marking::Simple1'].should == [:bar, :buz]
|
15
|
+
end
|
16
|
+
|
17
|
+
it('does not record invalid candidates (method not found in the class)') do
|
18
|
+
module Marking
|
19
|
+
class Simple2
|
20
|
+
def foo ; 'foo' end
|
21
|
+
private_please :foo
|
22
|
+
private_please :invalid_method
|
23
|
+
end
|
24
|
+
end
|
25
|
+
PrivatePlease.candidates['Marking::Simple2'].should == [:foo]
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PrivatePlease, 'calling marked methods' do
|
4
|
+
before() do
|
5
|
+
PrivatePlease.activate(true)
|
6
|
+
end
|
7
|
+
|
8
|
+
module Calling
|
9
|
+
class Simple
|
10
|
+
def public_m ; private_m() end
|
11
|
+
def private_m; 'SUCCESS' end
|
12
|
+
private_please :private_m
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
#--------------
|
17
|
+
context 'from INSIDE the class' do
|
18
|
+
#--------------
|
19
|
+
|
20
|
+
before { Calling::Simple.new.public_m }
|
21
|
+
|
22
|
+
it('records the call to the p+p method in PrivatePlease.inside_called_candidates') do
|
23
|
+
PrivatePlease.inside_called_candidates[ 'Calling::Simple'].to_a.should == [:private_m]
|
24
|
+
PrivatePlease.outside_called_candidates['Calling::Simple'].to_a.should == []
|
25
|
+
end
|
26
|
+
|
27
|
+
it('records multiple calls only once') do
|
28
|
+
2.times{ Calling::Simple.new.public_m }
|
29
|
+
PrivatePlease.inside_called_candidates[ 'Calling::Simple'].to_a.should == [:private_m]
|
30
|
+
PrivatePlease.outside_called_candidates['Calling::Simple'].to_a.should == []
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
#--------------
|
36
|
+
context 'from OUTSIDE the class' do
|
37
|
+
#--------------
|
38
|
+
|
39
|
+
before { @result = Calling::Simple.new.private_m }
|
40
|
+
|
41
|
+
it 'goes thru (as the method is still public)' do
|
42
|
+
@result.should == 'SUCCESS'
|
43
|
+
end
|
44
|
+
|
45
|
+
it('records the call to the p+p method in PrivatePlease.inside_called_candidates') do
|
46
|
+
PrivatePlease.inside_called_candidates[ 'Calling::Simple'].to_a.should == []
|
47
|
+
PrivatePlease.outside_called_candidates['Calling::Simple'].to_a.should == [:private_m]
|
48
|
+
end
|
49
|
+
|
50
|
+
it('records multiple calls only once') do
|
51
|
+
2.times{ Calling::Simple.new.private_m }
|
52
|
+
PrivatePlease.inside_called_candidates[ 'Calling::Simple'].to_a.should == []
|
53
|
+
PrivatePlease.outside_called_candidates['Calling::Simple'].to_a.should == [:private_m]
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PrivatePlease, 'configuring PrivatePlease' do
|
4
|
+
module Config
|
5
|
+
class Simple
|
6
|
+
def public_m ; private_m() end
|
7
|
+
def private_m; 'SUCCESS' end
|
8
|
+
private_please :private_m
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def do_the_calls
|
13
|
+
Config::Simple.new.tap do |o|
|
14
|
+
o.public_m # -> inside call
|
15
|
+
o.private_m # -> outside call
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
#--------------
|
20
|
+
|
21
|
+
it 'is disabled by default' do
|
22
|
+
PrivatePlease::Configuration.reset_before_new_test
|
23
|
+
PrivatePlease.should_not be_active
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'when disabled' do
|
27
|
+
|
28
|
+
before { PrivatePlease.activate(false) }
|
29
|
+
before { do_the_calls }
|
30
|
+
|
31
|
+
it('is not active') { PrivatePlease.should_not be_active }
|
32
|
+
|
33
|
+
it 'does NOT record the calls to candidates' do
|
34
|
+
PrivatePlease.inside_called_candidates[ 'Config::Simple'].to_a.should == []
|
35
|
+
PrivatePlease.outside_called_candidates['Config::Simple'].to_a.should == []
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'when enabled' do
|
40
|
+
|
41
|
+
before { PrivatePlease.activate(true) }
|
42
|
+
before { do_the_calls }
|
43
|
+
|
44
|
+
it('is active') { PrivatePlease.should be_active }
|
45
|
+
|
46
|
+
it 'DOES record the calls to candidates' do
|
47
|
+
PrivatePlease.inside_called_candidates[ 'Config::Simple'].to_a.should == [:private_m]
|
48
|
+
PrivatePlease.outside_called_candidates['Config::Simple'].to_a.should == [:private_m]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PrivatePlease, 'reporting the calls on candidates' do
|
4
|
+
|
5
|
+
module Reporting
|
6
|
+
class Simple
|
7
|
+
def public_m ; private_m1a() end
|
8
|
+
def private_m1a ; private_m1b end
|
9
|
+
def private_m1b ; private_m1c end
|
10
|
+
|
11
|
+
def private_m ; private_m1c end
|
12
|
+
def private_m1c ; 'SUCCESS' end
|
13
|
+
|
14
|
+
def ignored ; 'never called' end
|
15
|
+
private_please :private_m1a, :private_m1b, :private_m1c, :private_m, :ignored
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
before() { PrivatePlease.activate(true) }
|
20
|
+
before do
|
21
|
+
Reporting::Simple.new.public_m
|
22
|
+
Reporting::Simple.new.private_m
|
23
|
+
Reporting::Simple.new.private_m1c
|
24
|
+
end
|
25
|
+
|
26
|
+
describe 'the activity report' do
|
27
|
+
let(:the_report) { PrivatePlease.report }
|
28
|
+
|
29
|
+
specify '#good_candidates is the list of methods that CAN be made private' do
|
30
|
+
the_report.good_candidates['Reporting::Simple'].
|
31
|
+
should =~ [:private_m1a, :private_m1b]
|
32
|
+
end
|
33
|
+
|
34
|
+
specify '#bad_candidates is the list of methods that CANNOT be made private' do
|
35
|
+
the_report.bad_candidates['Reporting::Simple'].
|
36
|
+
should =~ [:private_m1c, :private_m]
|
37
|
+
end
|
38
|
+
|
39
|
+
xspecify '#never_called_candidates is the list of methods that were never called' do
|
40
|
+
the_report.never_called_candidates['Reporting::Simple'].
|
41
|
+
should == [:ignored]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
specify 'at_exit prints the report in the STDOUT'
|
46
|
+
|
47
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
config.filter_run :focus
|
11
|
+
|
12
|
+
# Run specs in random order to surface order dependencies. If you find an
|
13
|
+
# order dependency and want to debug it, you can fix the order by providing
|
14
|
+
# the seed, which is printed after each run.
|
15
|
+
# --seed 1234
|
16
|
+
config.order = 'random'
|
17
|
+
|
18
|
+
config.before(:each) do
|
19
|
+
PrivatePlease.reset_before_new_test
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
require File.dirname(__FILE__) + '/../lib/private_please'
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rspec'
|
3
|
+
require 'todo_next'
|
4
|
+
|
5
|
+
todo_next(<<TEXT)
|
6
|
+
* marking 1 method
|
7
|
+
example :
|
8
|
+
def foo
|
9
|
+
..
|
10
|
+
end
|
11
|
+
private_please :foo
|
12
|
+
|
13
|
+
* adds the method to $private_please_candidates
|
14
|
+
|
15
|
+
Marking 2 methods in 1 call
|
16
|
+
example :
|
17
|
+
..
|
18
|
+
private_please :foo, :bar
|
19
|
+
|
20
|
+
* adds the 2 method to $private_please_candidates
|
21
|
+
|
22
|
+
Global usage
|
23
|
+
example :
|
24
|
+
..
|
25
|
+
private_please
|
26
|
+
def foo .. end
|
27
|
+
def bar .. end
|
28
|
+
|
29
|
+
* adds the 2 method to $private_please_candidates
|
30
|
+
|
31
|
+
An outside call to a candidate marked method
|
32
|
+
- goes through as is the method waspublic
|
33
|
+
- $private_please_called_candidates << the candidate
|
34
|
+
- $private_please_INVALID_candidates << the candidate
|
35
|
+
|
36
|
+
An inside call to a candidate marked method
|
37
|
+
- goes through
|
38
|
+
- $private_please_called_candidates << the candidate
|
39
|
+
|
40
|
+
Configuration
|
41
|
+
- 'private_please' is inactive by default
|
42
|
+
'private_please' can be activate
|
43
|
+
- via ENV['private_please']=true
|
44
|
+
- PrivatePlease.activate(true)
|
45
|
+
|
46
|
+
at_exit
|
47
|
+
- prints a report about the candidates in STDOUT
|
48
|
+
|
49
|
+
TEXT
|
50
|
+
|
51
|
+
# √ == passed => same as a comment line
|
52
|
+
# * == current => leading char - '*' - is kept
|
metadata
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: private_please
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Alain Ravet
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-07-23 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
22
|
+
none: false
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
hash: 3
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
prerelease: false
|
31
|
+
type: :development
|
32
|
+
name: rake
|
33
|
+
requirement: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
hash: 3
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
version: "0"
|
44
|
+
prerelease: false
|
45
|
+
type: :development
|
46
|
+
name: todo_next
|
47
|
+
requirement: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
hash: 3
|
55
|
+
segments:
|
56
|
+
- 0
|
57
|
+
version: "0"
|
58
|
+
prerelease: false
|
59
|
+
type: :development
|
60
|
+
name: rspec
|
61
|
+
requirement: *id003
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
hash: 3
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
version: "0"
|
72
|
+
prerelease: false
|
73
|
+
type: :development
|
74
|
+
name: guard-rspec
|
75
|
+
requirement: *id004
|
76
|
+
description: Test if methods can be made private
|
77
|
+
email:
|
78
|
+
- alainravet@gmail.com
|
79
|
+
executables: []
|
80
|
+
|
81
|
+
extensions: []
|
82
|
+
|
83
|
+
extra_rdoc_files: []
|
84
|
+
|
85
|
+
files:
|
86
|
+
- .gitignore
|
87
|
+
- .rspec
|
88
|
+
- Gemfile
|
89
|
+
- Guardfile
|
90
|
+
- LICENSE
|
91
|
+
- README.md
|
92
|
+
- Rakefile
|
93
|
+
- lib/private_please.rb
|
94
|
+
- lib/private_please/candidates.rb
|
95
|
+
- lib/private_please/configuration.rb
|
96
|
+
- lib/private_please/line_change_tracker.rb
|
97
|
+
- lib/private_please/recorder.rb
|
98
|
+
- lib/private_please/report.rb
|
99
|
+
- lib/private_please/report/template.txt.erb
|
100
|
+
- lib/private_please/version.rb
|
101
|
+
- private_please.gemspec
|
102
|
+
- spec/01_marking_methods_spec.rb
|
103
|
+
- spec/02_calling_methods_spec.rb
|
104
|
+
- spec/03_configuration_spec.rb
|
105
|
+
- spec/04_at_exit_report_printing_spec.rb
|
106
|
+
- spec/spec_helper.rb
|
107
|
+
- spec/todo_next_spec.rb
|
108
|
+
homepage: https://github.com/alainravet/private_please
|
109
|
+
licenses: []
|
110
|
+
|
111
|
+
post_install_message:
|
112
|
+
rdoc_options: []
|
113
|
+
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
none: false
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
hash: 3
|
122
|
+
segments:
|
123
|
+
- 0
|
124
|
+
version: "0"
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
|
+
none: false
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
hash: 3
|
131
|
+
segments:
|
132
|
+
- 0
|
133
|
+
version: "0"
|
134
|
+
requirements: []
|
135
|
+
|
136
|
+
rubyforge_project:
|
137
|
+
rubygems_version: 1.8.24
|
138
|
+
signing_key:
|
139
|
+
specification_version: 3
|
140
|
+
summary: Test if methods can be made private
|
141
|
+
test_files:
|
142
|
+
- spec/01_marking_methods_spec.rb
|
143
|
+
- spec/02_calling_methods_spec.rb
|
144
|
+
- spec/03_configuration_spec.rb
|
145
|
+
- spec/04_at_exit_report_printing_spec.rb
|
146
|
+
- spec/spec_helper.rb
|
147
|
+
- spec/todo_next_spec.rb
|