debug-bar 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/.rbenv-version +1 -0
- data/.rspec +1 -0
- data/Gemfile +16 -0
- data/README.rdoc +192 -0
- data/Rakefile +27 -0
- data/debug-bar.gemspec +24 -0
- data/lib/debug-bar/base.rb +208 -0
- data/lib/debug-bar/default.rb +26 -0
- data/lib/debug-bar/ext/binding.rb +17 -0
- data/lib/debug-bar/ext/object.rb +20 -0
- data/lib/debug-bar/ext/string.rb +18 -0
- data/lib/debug-bar/ext.rb +3 -0
- data/lib/debug-bar/recipe_book/base.rb +104 -0
- data/lib/debug-bar/recipe_book/default.rb +34 -0
- data/lib/debug-bar/recipe_book.rb +2 -0
- data/lib/debug-bar/version.rb +3 -0
- data/lib/debug-bar.rb +6 -0
- data/lib/templates/callback_box.html.erb +12 -0
- data/lib/templates/error.html.erb +6 -0
- data/lib/templates/layout.html.erb +142 -0
- data/spec/base_spec.rb +363 -0
- data/spec/binding_spec.rb +62 -0
- data/spec/recipe_book_spec.rb +161 -0
- data/spec/spec_helper.rb +19 -0
- data/spec/support/templates/basic.html.erb +1 -0
- data/spec/support/templates/content.html.erb +1 -0
- metadata +116 -0
@@ -0,0 +1,161 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DebugBar::RecipeBook::Base do
|
4
|
+
|
5
|
+
class RecipeTestBook < DebugBar::RecipeBook::Base
|
6
|
+
|
7
|
+
def time_recipe
|
8
|
+
return Proc.new {|b| ['Time', Time.now, {}]}
|
9
|
+
end
|
10
|
+
|
11
|
+
# Places all key value pairs between vertical pipes.
|
12
|
+
# Ex: {:foo => 'bar'} --> '|foo|bar|'
|
13
|
+
def opts_recipe(opts={})
|
14
|
+
return Proc.new {|b| ['Opts', '|' + opts.to_a.flatten.join('|') + '|', {}]}
|
15
|
+
end
|
16
|
+
|
17
|
+
def render_recipe(opts={})
|
18
|
+
locals = {:content => 'River Song'}.merge(opts)
|
19
|
+
return Proc.new {|b| ['Render', render_template(:content, :locals => locals), {}]}
|
20
|
+
end
|
21
|
+
|
22
|
+
def helper_method
|
23
|
+
return :helper_method_result_standin
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
class BindingContext
|
29
|
+
|
30
|
+
def fetch_binding
|
31
|
+
return binding
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
before(:each) do
|
37
|
+
@book = RecipeTestBook.new
|
38
|
+
end
|
39
|
+
|
40
|
+
describe 'recipe introspection' do
|
41
|
+
|
42
|
+
it 'should give the list of all known recipes as symbols' do
|
43
|
+
@book.recipes.sort.should == [:time, :opts, :render].sort
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should allow checking for knowledge of a recipe by symbol' do
|
47
|
+
@book.include?(:time).should be_true
|
48
|
+
@book.include?(:zeta).should be_false
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should allow checking for knowledge of a recipe by string' do
|
52
|
+
@book.include?('time').should be_true
|
53
|
+
@book.include?('zeta').should be_false
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
describe 'recipe fetching' do
|
59
|
+
|
60
|
+
before(:each) do
|
61
|
+
@binding = BindingContext.new.fetch_binding
|
62
|
+
end
|
63
|
+
|
64
|
+
[:time, 'time'].each do |key|
|
65
|
+
it "should return the generated callback of a recipe reference by #{key.class.name}" do
|
66
|
+
recipe = @book.recipe(key)
|
67
|
+
recipe.should be_kind_of(Proc)
|
68
|
+
title, body = recipe.call(@binding)
|
69
|
+
title.should == 'Time'
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'should pass an options hash to the recipe when given.' do
|
74
|
+
recipe = @book.recipe(:opts, :name => 'Amelia Pond')
|
75
|
+
recipe.should be_kind_of(Proc)
|
76
|
+
title, body= recipe.call(@binding)
|
77
|
+
title.should == 'Opts'
|
78
|
+
body.should == '|name|Amelia Pond|'
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'should get the callback for a recipe that has opts even when they are not given.' do
|
82
|
+
recipe = @book.recipe(:opts)
|
83
|
+
recipe.should be_kind_of(Proc)
|
84
|
+
title, body= recipe.call(@binding)
|
85
|
+
title.should == 'Opts'
|
86
|
+
body.should == '||'
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'should alias [] to recipe' do
|
90
|
+
@book.method(:[]).should == @book.method(:recipe)
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
describe 'templates' do
|
96
|
+
|
97
|
+
before(:each) do
|
98
|
+
@book.send(:template_search_paths=, [Pathname.new(__FILE__).dirname + 'support' + 'templates'])
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'should have configurable template search paths' do
|
102
|
+
@book = RecipeTestBook.new # Need a clean book for this test.
|
103
|
+
@book.send(:template_search_paths).should == []
|
104
|
+
|
105
|
+
@book.send(:template_search_paths=, ['foo', 'bar'])
|
106
|
+
|
107
|
+
@book.send(:template_search_paths).each {|pn| pn.should be_kind_of(Pathname)}
|
108
|
+
@book.send(:template_search_paths).first.basename.to_s.should == 'foo'
|
109
|
+
@book.send(:template_search_paths).last.basename.to_s.should == 'bar'
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'should read template names by symbol from the search path' do
|
113
|
+
template = @book.send(:read_template, :basic)
|
114
|
+
|
115
|
+
template.should be_kind_of(String)
|
116
|
+
template.index('id="basic"').should_not be_nil
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'should read template names by string from the search path' do
|
120
|
+
template = @book.send(:read_template, 'basic')
|
121
|
+
|
122
|
+
template.should be_kind_of(String)
|
123
|
+
template.index('id="basic"').should_not be_nil
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'should raise an ArgumenError when the template is not found' do
|
127
|
+
lambda {@book.send(:read_template, :gallifrey)}.should raise_error(ArgumentError)
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'should render the template' do
|
131
|
+
html = @book.send(:render_template, :basic)
|
132
|
+
html.index('id="basic"').should_not be_nil
|
133
|
+
end
|
134
|
+
|
135
|
+
it 'should render the template with :locals' do
|
136
|
+
html = @book.send(:render_template, :content, :locals => {:content => 'The Doctor'})
|
137
|
+
|
138
|
+
html.index('id="content"').should_not be_nil
|
139
|
+
html.index('River Song').should be_nil
|
140
|
+
html.index('The Doctor').should_not be_nil
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'should render the template within a recipe' do
|
144
|
+
title, html = @book.recipe(:render).call(@binding)
|
145
|
+
|
146
|
+
html.index('id="content"').should_not be_nil
|
147
|
+
html.index('River Song').should_not be_nil
|
148
|
+
html.index('The Doctor').should be_nil
|
149
|
+
end
|
150
|
+
|
151
|
+
it 'should render the template with locals from within a recipe' do
|
152
|
+
title, html = @book.recipe(:render, :content => 'The Doctor').call(@binding)
|
153
|
+
|
154
|
+
html.index('id="content"').should_not be_nil
|
155
|
+
html.index('River Song').should be_nil
|
156
|
+
html.index('The Doctor').should_not be_nil
|
157
|
+
end
|
158
|
+
|
159
|
+
end
|
160
|
+
|
161
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
#require 'vcr'
|
3
|
+
|
4
|
+
require 'debug-bar'
|
5
|
+
|
6
|
+
#WP::Config::set_config_root(File.expand_path(File.join(File.dirname(__FILE__),'data')))
|
7
|
+
#
|
8
|
+
#VCR.configure do |c|
|
9
|
+
# c.cassette_library_dir = File.dirname(__FILE__) + '/fixtures/vcr_cassettes'
|
10
|
+
# c.hook_into :webmock
|
11
|
+
#end
|
12
|
+
|
13
|
+
Dir[File.join(File.dirname(__FILE__), "support/**/*.rb")].each {|f| require f}
|
14
|
+
|
15
|
+
# Require ruby-debugger if it is available, otherwise don't.
|
16
|
+
begin
|
17
|
+
require 'ruby-debugger'
|
18
|
+
rescue LoadError
|
19
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<div id="basic">Basic</div>
|
@@ -0,0 +1 @@
|
|
1
|
+
<div id="content"><%= content %></div>
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: debug-bar
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 1.0.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jeff Reinecke
|
9
|
+
- Keith Stone
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
|
14
|
+
date: 2012-11-15 00:00:00 Z
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: erubis
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: "0"
|
25
|
+
type: :runtime
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
prerelease: false
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: "0"
|
36
|
+
type: :runtime
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: awesome_print
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id003
|
49
|
+
description: Base generic debug bar implementation.
|
50
|
+
email:
|
51
|
+
- jreinecke@whitepages.com
|
52
|
+
- kstone@whitepages.com
|
53
|
+
executables: []
|
54
|
+
|
55
|
+
extensions: []
|
56
|
+
|
57
|
+
extra_rdoc_files: []
|
58
|
+
|
59
|
+
files:
|
60
|
+
- .gitignore
|
61
|
+
- .rbenv-version
|
62
|
+
- .rspec
|
63
|
+
- Gemfile
|
64
|
+
- README.rdoc
|
65
|
+
- Rakefile
|
66
|
+
- debug-bar.gemspec
|
67
|
+
- lib/debug-bar.rb
|
68
|
+
- lib/debug-bar/base.rb
|
69
|
+
- lib/debug-bar/default.rb
|
70
|
+
- lib/debug-bar/ext.rb
|
71
|
+
- lib/debug-bar/ext/binding.rb
|
72
|
+
- lib/debug-bar/ext/object.rb
|
73
|
+
- lib/debug-bar/ext/string.rb
|
74
|
+
- lib/debug-bar/recipe_book.rb
|
75
|
+
- lib/debug-bar/recipe_book/base.rb
|
76
|
+
- lib/debug-bar/recipe_book/default.rb
|
77
|
+
- lib/debug-bar/version.rb
|
78
|
+
- lib/templates/callback_box.html.erb
|
79
|
+
- lib/templates/error.html.erb
|
80
|
+
- lib/templates/layout.html.erb
|
81
|
+
- spec/base_spec.rb
|
82
|
+
- spec/binding_spec.rb
|
83
|
+
- spec/recipe_book_spec.rb
|
84
|
+
- spec/spec_helper.rb
|
85
|
+
- spec/support/templates/basic.html.erb
|
86
|
+
- spec/support/templates/content.html.erb
|
87
|
+
homepage: https://github.com/whitepages/debug-bar
|
88
|
+
licenses:
|
89
|
+
- BSD
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: "0"
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: "0"
|
107
|
+
requirements: []
|
108
|
+
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 1.8.12
|
111
|
+
signing_key:
|
112
|
+
specification_version: 3
|
113
|
+
summary: Debug Bar
|
114
|
+
test_files: []
|
115
|
+
|
116
|
+
has_rdoc:
|