peekaboo 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ .yardoc/*
2
+ doc/*
3
+ coverage/*
@@ -0,0 +1,20 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'spec/rake/spectask'
4
+ require 'rcov/rcovtask'
5
+ require 'yard'
6
+
7
+ Spec::Rake::SpecTask.new(:spec) do |t|
8
+ t.spec_files = FileList['spec/**/*_spec.rb']
9
+ t.warning = true
10
+ t.verbose = true
11
+ end
12
+
13
+ Rcov::RcovTask.new(:rcov) do |t|
14
+ t.test_files = FileList['spec/**/*_spec.rb']
15
+ t.verbose = true
16
+ end
17
+
18
+ YARD::Rake::YardocTask.new(:yard) do |t|
19
+ t.files = ["lib/**/*.rb", "-", "CHANGELOG.md"]
20
+ end
@@ -2,7 +2,7 @@ module Peekaboo
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- PATCH = 1
5
+ PATCH = 2
6
6
 
7
7
  STRING = [MAJOR, MINOR, PATCH].join('.')
8
8
  end
@@ -0,0 +1,21 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $:.unshift lib unless $:.include? lib
3
+
4
+ require 'peekaboo/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "peekaboo"
8
+ gem.version = Peekaboo::Version::STRING
9
+ gem.summary = %{Beautiful "mixin" magic for tracing Ruby method calls.}
10
+ gem.description = "Allows you to log method call information ( input arguments, class/method name, and return value ) without being overly intrusive."
11
+ gem.email = "sonny.ruben@gmail.com"
12
+ gem.homepage = "http://github.com/sgarcia/peekaboo"
13
+ gem.authors = ["Sonny Ruben Garcia"]
14
+
15
+ gem.add_development_dependency "rspec", "1.3.0"
16
+ gem.add_development_dependency "rcov", "0.9.9"
17
+ gem.add_development_dependency "yard", "0.6.1"
18
+
19
+ gem.files = `git ls-files`.split("\n")
20
+ gem.test_files = `git ls-files -- spec/*`.split("\n")
21
+ end
@@ -0,0 +1,36 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe Peekaboo::Configuration do
4
+
5
+ before(:each) do
6
+ @config = Peekaboo::Configuration.new
7
+ end
8
+
9
+ context "#tracer (default)" do
10
+ it "should initialize tracing" do
11
+ @config.tracer.should_not be_nil
12
+ end
13
+
14
+ it "should adhere to the standard 'Logger' interface" do
15
+ [ :debug, :info, :warn, :error, :fatal, :unknown ].each { |logger_msg|
16
+ @config.tracer.should respond_to(logger_msg)
17
+ }
18
+ end
19
+ end
20
+
21
+ context "#trace_with" do
22
+ it "should set a new tracer for use" do
23
+ new_tracer = Logger.new STDOUT
24
+
25
+ @config.trace_with new_tracer
26
+ @config.tracer.should == new_tracer
27
+ end
28
+
29
+ it "should enforce that new tracer adheres to the standard 'Logger' interface" do
30
+ lambda {
31
+ @config.trace_with 'garbage value'
32
+ }.should raise_exception('Tracer must respond to debug(), info(), warn(), error(), fatal(), and unknown()')
33
+ end
34
+ end
35
+
36
+ end
@@ -0,0 +1,106 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ describe Peekaboo do
4
+
5
+ context ".configuration" do
6
+ it "should hold a reference to the current configuration" do
7
+ Peekaboo.configuration.should be_an_instance_of(Peekaboo::Configuration)
8
+ end
9
+ end
10
+
11
+ context ".configure" do
12
+ it "should yield the current configuration" do
13
+ yielded_object = nil
14
+ Peekaboo.configure { |x| yielded_object = x }
15
+ Peekaboo.configuration.should == yielded_object
16
+ end
17
+ end
18
+
19
+ context ".enable_tracing_on" do
20
+ before(:each) do
21
+ @test_class = new_test_class
22
+ @test_class.instance_eval { include Peekaboo }
23
+ end
24
+
25
+ it "should be a singleton method added to any including class" do
26
+ @test_class.should respond_to(:enable_tracing_on)
27
+ end
28
+
29
+ it "should store a list of methods to trace on any including class" do
30
+ methods_to_trace = [:method_no_args, :method_one_arg]
31
+ @test_class.enable_tracing_on *methods_to_trace
32
+ @test_class::PEEKABOO_METHOD_LIST.should == methods_to_trace
33
+ end
34
+
35
+ it "should raise an exception when trying to add a method that is already being traced" do
36
+ @test_class.enable_tracing_on :some_method
37
+ lambda {
38
+ @test_class.enable_tracing_on :some_method
39
+ }.should raise_exception("Already tracing `some_method'")
40
+ end
41
+ end
42
+
43
+ context "instance method tracing" do
44
+ before(:all) do
45
+ @test_class = new_test_class
46
+ @test_class.instance_eval do
47
+ include Peekaboo
48
+ enable_tracing_on :method_no_args, :method_one_arg, :method_two_args, :method_optional_args, :method_variable_args, :method_raises
49
+ end
50
+
51
+ @test_instance = @test_class.new
52
+ @tracer = Peekaboo.configuration.tracer
53
+ end
54
+
55
+ it "should not take place on unlisted methods" do
56
+ @tracer.should_not_receive(:info)
57
+ @test_instance.method_no_tracing
58
+ end
59
+
60
+ it "should show listed methods with no arguments" do
61
+ @tracer.should_receive(:info).with trace_message "Invoking: #{@test_class}#method_no_args with [] ==> Returning: nil"
62
+ @test_instance.method_no_args
63
+ end
64
+
65
+ it "should show listed methods with standard arguments" do
66
+ @tracer.should_receive(:info).
67
+ with trace_message %{Invoking: #{@test_class}#method_one_arg with ["one"] ==> Returning: nil}
68
+ @test_instance.method_one_arg 'one'
69
+
70
+ @tracer.should_receive(:info).
71
+ with trace_message %{Invoking: #{@test_class}#method_two_args with ["one", "two"] ==> Returning: nil}
72
+ @test_instance.method_two_args 'one', 'two'
73
+ end
74
+
75
+ it "should show methods with optional arguments" do
76
+ @tracer.should_receive(:info).
77
+ with trace_message %{Invoking: #{@test_class}#method_optional_args with [] ==> Returning: nil}
78
+ @test_instance.method_optional_args
79
+
80
+ @tracer.should_receive(:info).
81
+ with trace_message %{Invoking: #{@test_class}#method_optional_args with ["override"] ==> Returning: nil}
82
+ @test_instance.method_optional_args 'override'
83
+ end
84
+
85
+ it "should show methods with variable arguments" do
86
+ @tracer.should_receive(:info).
87
+ with trace_message %{Invoking: #{@test_class}#method_variable_args with [] ==> Returning: nil}
88
+ @test_instance.method_variable_args
89
+
90
+ @tracer.should_receive(:info).
91
+ with trace_message %{Invoking: #{@test_class}#method_variable_args with ["one"] ==> Returning: nil}
92
+ @test_instance.method_variable_args 'one'
93
+
94
+ @tracer.should_receive(:info).
95
+ with trace_message %{Invoking: #{@test_class}#method_variable_args with ["one", "two"] ==> Returning: nil}
96
+ @test_instance.method_variable_args 'one', 'two'
97
+ end
98
+
99
+ it "should show methods that raise an exception" do
100
+ @tracer.should_receive(:info).
101
+ with trace_message %{Invoking: #{@test_class}#method_raises with [] !!! Raising: "something went wrong"}
102
+ lambda { @test_instance.method_raises }.should raise_exception
103
+ end
104
+ end
105
+
106
+ end
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format specdoc
@@ -0,0 +1,42 @@
1
+ $:.unshift File.expand_path('../../lib', __FILE__)
2
+
3
+ require 'rubygems'
4
+ require 'peekaboo'
5
+ require 'ruby-debug'
6
+ require 'spec'
7
+ require 'spec/autorun'
8
+
9
+ Spec::Runner.configure do |config|
10
+ def new_test_class
11
+ Class.new do
12
+ def method_no_tracing
13
+ end
14
+
15
+ def method_no_args
16
+ end
17
+
18
+ def method_one_arg arg1
19
+ end
20
+
21
+ def method_two_args arg1, arg2
22
+ end
23
+
24
+ def method_optional_args optional = 'default'
25
+ end
26
+
27
+ def method_variable_args *args
28
+ end
29
+
30
+ def method_raises
31
+ raise 'something went wrong'
32
+ end
33
+ end
34
+ end
35
+
36
+ def trace_message contents, offset = 1
37
+ file_and_line = caller(1)[0]
38
+ file, line = file_and_line.split(':')
39
+ line = line.to_i + offset
40
+ "#{file}:#{line}\n\t( #{contents} )"
41
+ end
42
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: peekaboo
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sonny Ruben Garcia
@@ -75,11 +75,18 @@ extensions: []
75
75
  extra_rdoc_files: []
76
76
 
77
77
  files:
78
- - README.md
78
+ - .gitignore
79
79
  - CHANGELOG.md
80
+ - README.md
81
+ - Rakefile
80
82
  - lib/peekaboo.rb
81
83
  - lib/peekaboo/configuration.rb
82
84
  - lib/peekaboo/version.rb
85
+ - peekaboo.gemspec
86
+ - spec/peekaboo/configuration_spec.rb
87
+ - spec/peekaboo_spec.rb
88
+ - spec/spec.opts
89
+ - spec/spec_helper.rb
83
90
  has_rdoc: true
84
91
  homepage: http://github.com/sgarcia/peekaboo
85
92
  licenses: []
@@ -114,5 +121,8 @@ rubygems_version: 1.3.7
114
121
  signing_key:
115
122
  specification_version: 3
116
123
  summary: Beautiful "mixin" magic for tracing Ruby method calls.
117
- test_files: []
118
-
124
+ test_files:
125
+ - spec/peekaboo/configuration_spec.rb
126
+ - spec/peekaboo_spec.rb
127
+ - spec/spec.opts
128
+ - spec/spec_helper.rb