rack-var-dump 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ -fs --color
@@ -0,0 +1,5 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - ree
@@ -1,6 +1,12 @@
1
- (書きかけ)
1
+ # Build Status
2
2
 
3
- = Japanese
3
+ <img src="https://secure.travis-ci.org/daic-h/rack-var-dump.png"/>
4
+
5
+ # English
6
+
7
+ Writing now...
8
+
9
+ # Japanese
4
10
 
5
11
  rack-var-dumpはphpのvar_dump()のようなデバッグ用のメソッドを提供します
6
12
 
@@ -10,52 +16,63 @@ Object Classにvar_dumpメソッドを提供し、レスポンスを返すまで
10
16
 
11
17
  var_dumpの返り値は常にselfです
12
18
 
13
- == Supported versions
19
+ <img src="http://cdn-ak.f.st-hatena.com/images/fotolife/b/bunnyhop/20120127/20120127235528.png"/>
20
+
21
+ ## Supported versions
14
22
 
15
23
  * Ruby 1.8.7, 1.9.x
16
24
 
17
25
  * Rackを利用しているアプリケーション全般 (rails, sinatra, padrino, etc...)
18
26
 
19
- == Install
27
+ ## Install
20
28
 
21
- $ gem install rack-var-dump
29
+ $ gem install rack-var-dump
22
30
 
23
- === Rails
31
+ ### Rails
24
32
 
25
33
  Gemfileに追加
26
- gem 'rack-var-dump'
34
+
35
+ gem 'rack-var-dump'
27
36
 
28
37
  Bundle Install
29
- % bundle install
30
38
 
31
- === Rails3.x以上の場合
39
+ % bundle install
40
+
41
+ ### Rails3.x以上の場合
32
42
 
33
43
  config/application.rb等でRails用に用意されている
34
- require 'rails-var-dump'
44
+
45
+ require 'rails-var-dump'
46
+
35
47
  をrequire
36
48
 
37
- === その他Rackアプリケーション
49
+ ### その他Rackアプリケーション
38
50
 
39
51
  rack/var_dumpをrequire
40
- require 'rack/var_dump'
52
+
53
+ require 'rack/var_dump'
41
54
 
42
55
  Rack::VarDumpミドルウェアをuse
43
- use Rack::VarDump
44
56
 
45
- == 使い方
57
+ use Rack::VarDump
58
+
59
+ ## 使い方
46
60
 
47
61
  rails-var-dumpもしくはrack/var_dumpをrequireしている場合、全てのオブジェクトに
48
- var_dump(subject = nil)
62
+
63
+ var_dump(subject = nil)
64
+
49
65
  が提供されています
50
66
 
51
- ===
52
- @users = User.all.var_dump
53
- @users.var_dump("user.all")
67
+ ###
68
+
69
+ @users = User.all.var_dump
70
+ @users.var_dump("user.all")
54
71
 
55
72
  var_dumpの返り値は常にselfのため、チェーンが途切れずに使用できます
56
- @first_name = User.find(3).var_dump('user.id(3)').first_name
57
73
 
74
+ @first_name = User.find(3).var_dump('user.id(3)').first_name
58
75
 
59
- == Copyright
76
+ ## Copyright
60
77
 
61
- Copyright (c) 2012 Daichi Hirata. See LICENSE for details.
78
+ Copyright (c) 2012 Daichi Hirata. See LICENSE for details.
data/Rakefile CHANGED
@@ -1 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -18,17 +18,16 @@ module Rack
18
18
 
19
19
  def initialize(app)
20
20
  @app = app
21
- VarDump.reset!
22
21
  end
23
22
 
24
23
  def call(env)
25
24
  request = Rack::Request.new(env)
26
25
  status, headers, response = @app.call(env)
27
26
 
28
- if /^text\/html/ =~ headers["Content-Type"] && !@@var_aggregates.empty?
27
+ if headers["Content-Type"] =~ /^text\/html/ && !@@var_aggregates.empty?
29
28
  body = ""
30
29
  response.each {|org_body| body << org_body}
31
- response = [apply(request, body)] if body =~ /<body.*>/
30
+ response = [apply(body)] if body =~ /<body.*>/
32
31
  headers["Content-Length"] = response.join.bytesize.to_s
33
32
  end
34
33
  VarDump.reset!
@@ -36,7 +35,7 @@ module Rack
36
35
  end
37
36
 
38
37
  private
39
- def apply(request, response)
38
+ def apply(body)
40
39
  html = '<div id="var_dump" style="display:block">'
41
40
  html << '<pre style="background-color:#eee;padding:10px;font-size:11px;white-space:pre-wrap;color:black!important;">'
42
41
  @@var_aggregates.each_with_index do |info, n|
@@ -45,7 +44,7 @@ module Rack
45
44
  html << "\n\n"
46
45
  end
47
46
  html << "</pre></div>"
48
- response.sub(/<body.*>/, '\&' + html)
47
+ body.sub(/<body.*>/, '\&' + html)
49
48
  end
50
49
  end
51
50
  end
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class VarDump
3
- VERSION = "0.1.2"
3
+ VERSION = "0.1.3"
4
4
  end
5
5
  end
@@ -16,7 +16,9 @@ Gem::Specification.new do |s|
16
16
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
17
  s.require_paths = ["lib"]
18
18
 
19
- # specify any dependencies here; for example:
20
- # s.add_development_dependency "rspec"
21
- # s.add_runtime_dependency "rest-client"
19
+ s.add_development_dependency 'rake', '>= 0.9.2.2'
20
+ s.add_development_dependency 'rdoc', '>= 3.11'
21
+ s.add_development_dependency "rack", '>= 1.3.5'
22
+ s.add_development_dependency 'rack-test', '>= 0.5.3'
23
+ s.add_development_dependency 'rspec', '>= 2.7.0'
22
24
  end
@@ -0,0 +1,55 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe 'VarDump' do
4
+ include Rack::Test::Methods
5
+
6
+ let(:app) { Rack::VarDump.new(TestRackApp.new) }
7
+
8
+ describe "when var_dump is performed" do
9
+ before { 'sample-text'.var_dump }
10
+ let(:insert_html) do
11
+ %Q[var_dump:0 \n&quot;sample-text&quot;\n\n</pre></div>]
12
+ end
13
+
14
+ it "it is inserted when a status code is 200." do
15
+ get '/'
16
+ last_response.body.should include(insert_html)
17
+ end
18
+
19
+ it "it is not inserted when a contents type is not text/html. " do
20
+ get '/image.jpg'
21
+ last_response.body.should_not include(insert_html)
22
+ end
23
+ end
24
+
25
+ describe "when an argument is given" do
26
+ before { 'sample-text'.var_dump('Rspec:String') }
27
+ let(:insert_html) do
28
+ %Q[var_dump:0 Rspec:String\n&quot;sample-text&quot;\n\n</pre></div>]
29
+ end
30
+
31
+ it "It displays with subject." do
32
+ get '/'
33
+ last_response.body.should include(insert_html)
34
+ end
35
+ end
36
+
37
+ describe "when the two or more sets value is carried out" do
38
+ before{'sample-text'.var_dump; 'sample-text-2'.var_dump('Rspec:String2')}
39
+ let(:insert_html) do
40
+ %Q[var_dump:0 \n&quot;sample-text&quot;\n\nvar_dump:1 Rspec:String2\n&quot;sample-text-2&quot;\n\n</pre></div>]
41
+ end
42
+
43
+ it "more than one are outputted." do
44
+ get '/'
45
+ last_response.body.should include(insert_html)
46
+ end
47
+ end
48
+
49
+ describe "not insert responses" do
50
+ it "nothing is outputted when the value is not set to var_dumo." do
51
+ get '/'
52
+ last_response.body.should eql(DummyBody)
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,11 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe 'Object' do
4
+ it "instance should resond to var_dump" do
5
+ Object.new.should respond_to('var_dump')
6
+ end
7
+
8
+ it "class should resond to var_dump" do
9
+ Object.should respond_to('var_dump')
10
+ end
11
+ end
@@ -0,0 +1,25 @@
1
+ $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $:.unshift(File.dirname(__FILE__))
3
+
4
+ %w(rubygems rack rack/test rack/var_dump rspec).each {|f| require f}
5
+
6
+ DummyBody = <<-EOH
7
+ <html>
8
+ <head></head>
9
+ <body>
10
+ <p>Dummy Rack!</p>
11
+ </body>
12
+ </html>
13
+ EOH
14
+
15
+ class TestRackApp
16
+ def call(env)
17
+ case env['PATH_INFO']
18
+ when '/'
19
+ [200, {"Content-Type" => "text/html"}, [DummyBody]]
20
+ when '/image.jpg'
21
+ [200, {"Content-Type" => "image/ipg"}, [DummyBody]]
22
+ end
23
+ end
24
+ end
25
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-var-dump
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,63 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-27 00:00:00.000000000Z
13
- dependencies: []
12
+ date: 2012-01-29 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &70325150464780 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.9.2.2
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70325150464780
25
+ - !ruby/object:Gem::Dependency
26
+ name: rdoc
27
+ requirement: &70325150463780 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '3.11'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70325150463780
36
+ - !ruby/object:Gem::Dependency
37
+ name: rack
38
+ requirement: &70325150462780 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: 1.3.5
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70325150462780
47
+ - !ruby/object:Gem::Dependency
48
+ name: rack-test
49
+ requirement: &70325150462020 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.5.3
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70325150462020
58
+ - !ruby/object:Gem::Dependency
59
+ name: rspec
60
+ requirement: &70325150461480 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: 2.7.0
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70325150461480
14
69
  description: rack-var-dump provides a method for debugging like var_dump() of php.
15
70
  email:
16
71
  - bunny.hop.md@gmail.com
@@ -19,9 +74,11 @@ extensions: []
19
74
  extra_rdoc_files: []
20
75
  files:
21
76
  - .gitignore
77
+ - .rspec
78
+ - .travis.yml
22
79
  - Gemfile
23
80
  - LICENSE
24
- - README.rdoc
81
+ - README.md
25
82
  - Rakefile
26
83
  - lib/rack/railtie.rb
27
84
  - lib/rack/var_dump.rb
@@ -30,6 +87,9 @@ files:
30
87
  - lib/rails-var-dump.rb
31
88
  - lib/rails_var_dump.rb
32
89
  - rack-var-dump.gemspec
90
+ - spec/middleware_spec.rb
91
+ - spec/object_spec.rb
92
+ - spec/spec_helper.rb
33
93
  homepage: ''
34
94
  licenses: []
35
95
  post_install_message:
@@ -54,5 +114,8 @@ rubygems_version: 1.8.10
54
114
  signing_key:
55
115
  specification_version: 3
56
116
  summary: rack-var-dump provides a method for debugging like var_dump() of php.
57
- test_files: []
117
+ test_files:
118
+ - spec/middleware_spec.rb
119
+ - spec/object_spec.rb
120
+ - spec/spec_helper.rb
58
121
  has_rdoc: