dbg-rb 0.2.8 β†’ 0.3.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2db3ba3ac88033948685e877c1b9245f77c4f0c3b3b061d786305ea1a2059113
4
- data.tar.gz: 0412b7c4b793aabe451c622fbf293938a5e9dce9ad4ae06d4cda8604d4798df9
3
+ metadata.gz: fd12005e78ffa686afda779eabb3adf25011f8c2c53a8aeba8b34115f6fc481a
4
+ data.tar.gz: 4854bb2a74440292fb681b949dcbb44af0c25fb8fba074de45df923827c6f9dc
5
5
  SHA512:
6
- metadata.gz: 5b655b3c9c88e2e973cf860f1bf8228e27075b115d6ce37e4a0903ae0a062194c15915dcb3cd851b4234dcfa119d669b57af25f563ed4f14c852b5361f67d03b
7
- data.tar.gz: d71e5a0b42c1999ab7e981ba467fa7bd19851f26c8e3f5dcd22576db306f756b95edbe04562918b372e9a1e7bfcb96e6449fc08f79dbf5db969844b6240cb994
6
+ metadata.gz: 2cf2c64ce51787a3613c57a37c090166e22d26b23cf832e00ac1a087469f8eb77beb18a60f85665cd1b50222161a860b7de89383a8ac349667f833f0968922a0
7
+ data.tar.gz: 6be32da1ee94b9c02ad0be8156daceda13a775482d8f51a30150652b6e2b41d70cc4cb88169e00da3a519efd75fb25c342713b7a43376cd210d907beaaec310e
@@ -27,4 +27,4 @@ jobs:
27
27
  bundle install
28
28
  - name: Run tests
29
29
  run: |
30
- bundle exec rspec spec
30
+ bundle exec rake test
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # dbg! [![Gem Version](https://badge.fury.io/rb/dbg-rb.svg)](https://badge.fury.io/rb/dbg-rb) [![GH Actions](https://github.com/pawurb/dbg-rb/actions/workflows/ci.yml/badge.svg)](https://github.com/pawurb/dbg-rb/actions)
1
+ # dbg [![Gem Version](https://badge.fury.io/rb/dbg-rb.svg)](https://badge.fury.io/rb/dbg-rb) [![GH Actions](https://github.com/pawurb/dbg-rb/actions/workflows/ci.yml/badge.svg)](https://github.com/pawurb/dbg-rb/actions)
2
2
 
3
3
  ![Dbg base](https://github.com/pawurb/dbg-rb/raw/main/dbg_base.png)
4
4
 
@@ -16,10 +16,9 @@ too many times already.
16
16
 
17
17
  ## Installation
18
18
 
19
- `Gemfile`
20
- ```ruby
21
- gem "dbg-rb"
22
- ```
19
+ `bundle add dbg-rb`
20
+
21
+ Alternatively, you can use an inline version of `dbg-rb` without adding it to the Gemfile. Check out [this post](https://pawelurbanek.com/rails-puts-debug#inline-setup) for info on how to do it.
23
22
 
24
23
  ## Usage
25
24
 
@@ -98,14 +97,6 @@ DbgRb.highlight!("πŸŽ‰πŸ’”πŸ’£πŸ•ΊπŸš€πŸ§¨πŸ™ˆπŸ€―πŸ₯³πŸŒˆπŸ¦„")
98
97
 
99
98
  ![Dbg emoji](https://github.com/pawurb/dbg-rb/raw/main/dbg_emoji.png)
100
99
 
101
- You can also use `DbgRb.dbg!(*msgs)` directly or wrap it to rename the helper method:
102
-
103
- ```ruby
104
- def dd(*msgs)
105
- DbgRb.dbg!(*msgs)
106
- end
107
- ```
108
-
109
100
  ## Status
110
101
 
111
102
  Contributions & ideas very welcome!
data/Rakefile CHANGED
@@ -7,5 +7,6 @@ desc "Run tests"
7
7
  task :default => :test
8
8
 
9
9
  task :test do
10
- system("bundle exec rspec spec")
10
+ system("bundle exec rspec spec/gem_spec.rb")
11
+ system("bundle exec rspec spec/inline_spec.rb")
11
12
  end
data/dbg-rb.gemspec CHANGED
@@ -14,7 +14,6 @@ Gem::Specification.new do |s|
14
14
  s.files = `git ls-files`.split("\n").reject { |f| f.match?(/\.db$/) }
15
15
  s.require_paths = ["lib"]
16
16
  s.license = "MIT"
17
- s.add_dependency "binding_of_caller"
18
17
  s.add_dependency "json"
19
18
  s.add_development_dependency "ostruct"
20
19
  s.add_development_dependency "rake"
data/inline/dbg_rb.rb ADDED
@@ -0,0 +1,145 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Source https://github.com/pawurb/dbg-rb
4
+ # The MIT License (MIT)
5
+
6
+ # Copyright Β© PaweΕ‚ Urbanek 2024
7
+
8
+ # Permission is hereby granted, free of charge, to any person obtaining
9
+ # a copy of this software and associated documentation files (the
10
+ # "Software"), to deal in the Software without restriction, including
11
+ # without limitation the rights to use, copy, modify, merge, publish,
12
+ # distribute, sublicense, and/or sell copies of the Software, and to
13
+ # permit persons to whom the Software is furnished to do so, subject to
14
+ # the following conditions:
15
+
16
+ # The above copyright notice and this permission notice shall be
17
+ # included in all copies or substantial portions of the Software.
18
+
19
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
23
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
+
27
+ require "json"
28
+
29
+ module DbgRb
30
+ def self.color_code=(val)
31
+ Impl.color_code = val
32
+ end
33
+
34
+ def self.highlight!(wrapper = "!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
35
+ Impl.highlight!(wrapper)
36
+ end
37
+
38
+ def self.dbg(*msgs)
39
+ Impl.new.dbg(*msgs)
40
+ end
41
+
42
+ class Impl
43
+ @@color_code = nil
44
+ @@highlight = false
45
+
46
+ def self.color_code=(val)
47
+ @@color_code = val
48
+ end
49
+
50
+ def self.highlight!(wrapper)
51
+ @@highlight = wrapper
52
+ end
53
+
54
+ def dbg(value)
55
+ loc = caller_locations.first(3).last
56
+ source_file = if (path = loc.absolute_path)
57
+ path.split("/").last(2).join("/")
58
+ else
59
+ loc.label
60
+ end
61
+
62
+ file = loc.absolute_path.split(":").first
63
+
64
+ input = nil
65
+
66
+ File.open(file) do |f|
67
+ f.each_line.with_index do |line, i|
68
+ if i == loc.lineno - 1
69
+ input = line.split("dbg").last.chomp.strip
70
+ input = input.gsub(/[()]/, "").strip
71
+ end
72
+ end
73
+ end
74
+
75
+ if input.nil?
76
+ raise "It should never happen!"
77
+ end
78
+
79
+ line = loc.lineno
80
+ src = "[#{source_file}:#{line}]"
81
+ value = format_val(value)
82
+
83
+ val = if input.to_s == value.to_s
84
+ "#{value}"
85
+ else
86
+ "#{input} = #{value}"
87
+ end
88
+ output = "#{src} #{val}"
89
+
90
+ if @@highlight
91
+ output = "#{@@highlight}\n#{output}\n#{@@highlight}"
92
+ end
93
+
94
+ if @@color_code != nil
95
+ output = colorize(output, @@color_code)
96
+ end
97
+
98
+ puts output
99
+ end
100
+
101
+ private
102
+
103
+ def colorize(str, color_code)
104
+ "\e[#{color_code}m#{str}\e[0m"
105
+ end
106
+
107
+ def format_val(val)
108
+ if val.is_a?(Hash)
109
+ res = val.map { |k, v| [k, dbg_inspect(v, quote_str: false)] }.to_h
110
+ JSON.pretty_generate(res)
111
+ elsif val.is_a?(Array)
112
+ JSON.pretty_generate(val.map do |v|
113
+ dbg_inspect(v, quote_str: false)
114
+ end)
115
+ else
116
+ dbg_inspect(val, quote_str: true)
117
+ end.then do |value|
118
+ if value.is_a?(String)
119
+ value.gsub("\"nil\"", "nil")
120
+ else
121
+ value
122
+ end
123
+ end
124
+ end
125
+
126
+ def dbg_inspect(obj, quote_str:)
127
+ if quote_str && obj.is_a?(String)
128
+ return obj.inspect
129
+ end
130
+
131
+ case obj
132
+ when Numeric, String
133
+ obj
134
+ else
135
+ obj.inspect
136
+ end
137
+ end
138
+ end
139
+ end
140
+
141
+ def dbg(value)
142
+ DbgRb.dbg(value)
143
+ end
144
+
145
+ DbgRb.color_code = 33 # yellow
data/lib/dbg-rb.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "binding_of_caller"
4
3
  require "json"
5
4
 
6
5
  module DbgRb
@@ -12,8 +11,8 @@ module DbgRb
12
11
  Impl.highlight!(wrapper)
13
12
  end
14
13
 
15
- def self.dbg!(*msgs)
16
- Impl.new.dbg!(*msgs)
14
+ def self.dbg(*msgs)
15
+ Impl.new.dbg(*msgs)
17
16
  end
18
17
 
19
18
  class Impl
@@ -28,54 +27,51 @@ module DbgRb
28
27
  @@highlight = wrapper
29
28
  end
30
29
 
31
- def dbg!(*msgs)
30
+ def dbg(value)
32
31
  loc = caller_locations.first(3).last
33
- file = if (path = loc.absolute_path)
32
+ source_file = if (path = loc.absolute_path)
34
33
  path.split("/").last(2).join("/")
35
34
  else
36
35
  loc.label
37
36
  end
38
37
 
39
- line = loc.lineno
40
- src = "[#{file}:#{line}]"
41
-
42
- msgs.each_with_index do |obj, i|
43
- first = i == 0
44
- last = i == (msgs.size - 1)
45
-
46
- val = if obj.is_a?(Symbol)
47
- begin
48
- val = binding.of_caller(4).local_variable_get(obj)
49
- val = format_val(val)
50
-
51
- "#{obj} = #{val}"
52
- rescue NameError
53
- obj.inspect
54
- end
55
- else
56
- format_val(obj)
57
- end
38
+ file = loc.absolute_path.split(":").first
58
39
 
59
- output = "#{src} #{val}"
60
-
61
- if @@highlight
62
- if first
63
- output = "#{@@highlight}\n#{output}"
64
- end
40
+ input = nil
65
41
 
66
- if last
67
- output = "#{output}\n#{@@highlight}"
42
+ File.open(file) do |f|
43
+ f.each_line.with_index do |line, i|
44
+ if i == loc.lineno - 1
45
+ input = line.split("dbg").last.chomp.strip
46
+ input = input.gsub(/[()]/, "").strip
68
47
  end
69
48
  end
49
+ end
50
+
51
+ if input.nil?
52
+ raise "It should never happen!"
53
+ end
70
54
 
71
- if @@color_code != nil
72
- output = colorize(output, @@color_code)
55
+ line = loc.lineno
56
+ src = "[#{source_file}:#{line}]"
57
+ value = format_val(value)
58
+
59
+ val = if input.to_s == value.to_s
60
+ "#{value}"
61
+ else
62
+ "#{input} = #{value}"
73
63
  end
64
+ output = "#{src} #{val}"
65
+
66
+ if @@highlight
67
+ output = "#{@@highlight}\n#{output}\n#{@@highlight}"
68
+ end
74
69
 
75
- puts output
70
+ if @@color_code != nil
71
+ output = colorize(output, @@color_code)
76
72
  end
77
73
 
78
- nil
74
+ puts output
79
75
  end
80
76
 
81
77
  private
@@ -94,6 +90,12 @@ module DbgRb
94
90
  end)
95
91
  else
96
92
  dbg_inspect(val, quote_str: true)
93
+ end.then do |value|
94
+ if value.is_a?(String)
95
+ value.gsub("\"nil\"", "nil")
96
+ else
97
+ value
98
+ end
97
99
  end
98
100
  end
99
101
 
@@ -112,10 +114,8 @@ module DbgRb
112
114
  end
113
115
  end
114
116
 
115
- def dbg!(*msgs)
116
- DbgRb.dbg!(*msgs)
117
+ def dbg(value)
118
+ DbgRb.dbg(value)
117
119
  end
118
120
 
119
121
  DbgRb.color_code = 33 # yellow
120
-
121
- alias dbg dbg!
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DbgRb
4
- VERSION = "0.2.8"
4
+ VERSION = "0.3.0"
5
5
  end
data/spec/gem_spec.rb ADDED
@@ -0,0 +1,108 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+ require "dbg-rb"
5
+ require "ostruct"
6
+
7
+ describe DbgRb do
8
+ before do
9
+ DbgRb.color_code = nil
10
+ end
11
+
12
+ it "constant values" do
13
+ expect do
14
+ dbg("123")
15
+ end.to output("[spec/gem_spec.rb:14] \"123\"\n").to_stdout
16
+
17
+ expect do
18
+ dbg(123)
19
+ end.to output("[spec/gem_spec.rb:18] 123\n").to_stdout
20
+
21
+ expect do
22
+ dbg(nil)
23
+ end.to output("[spec/gem_spec.rb:22] nil\n").to_stdout
24
+
25
+ expect do
26
+ dbg "123"
27
+ end.to output("[spec/gem_spec.rb:26] \"123\"\n").to_stdout
28
+
29
+ expect do
30
+ dbg 123
31
+ end.to output("[spec/gem_spec.rb:30] 123\n").to_stdout
32
+
33
+ expect do
34
+ dbg nil
35
+ end.to output("[spec/gem_spec.rb:34] nil\n").to_stdout
36
+ end
37
+
38
+ it "variables" do
39
+ a = 123
40
+
41
+ expect do
42
+ dbg(a)
43
+ end.to output("[spec/gem_spec.rb:42] a = 123\n").to_stdout
44
+
45
+ b = "123"
46
+
47
+ expect do
48
+ dbg(b)
49
+ end.to output("[spec/gem_spec.rb:48] b = \"123\"\n").to_stdout
50
+
51
+ c = nil
52
+
53
+ expect do
54
+ dbg(c)
55
+ end.to output("[spec/gem_spec.rb:54] c = nil\n").to_stdout
56
+ end
57
+
58
+ it "complex objects" do
59
+ s = OpenStruct.new(a: 1, b: 2)
60
+
61
+ expect do
62
+ dbg(s)
63
+ end.to output("[spec/gem_spec.rb:62] s = #<OpenStruct a=1, b=2>\n").to_stdout
64
+ end
65
+
66
+ it "hashes" do
67
+ h = { a: 1, b: "2" }
68
+ expect do
69
+ dbg(h)
70
+ end.to output("[spec/gem_spec.rb:69] h = {\n \"a\": 1,\n \"b\": \"2\"\n}\n").to_stdout
71
+ end
72
+
73
+ it "arrays" do
74
+ a = [1, "str"]
75
+ expect do
76
+ dbg(a)
77
+ end.to output("[spec/gem_spec.rb:76] a = [\n 1,\n \"str\"\n]\n").to_stdout
78
+ end
79
+
80
+ it "hash formatting" do
81
+ h = { a: 1, b: "2", c: nil }
82
+ expect do
83
+ dbg(h)
84
+ end.to output("[spec/gem_spec.rb:83] h = {\n \"a\": 1,\n \"b\": \"2\",\n \"c\": nil\n}\n").to_stdout
85
+ end
86
+
87
+ it "highlight" do
88
+ DbgRb.highlight!
89
+ expect do
90
+ dbg("123")
91
+ end.to output("!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n[spec/gem_spec.rb:90] \"123\"\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n").to_stdout
92
+ end
93
+
94
+ it "color_code" do
95
+ DbgRb.color_code = 31
96
+ expect do
97
+ dbg(123)
98
+ end.to output("\e[31m!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n[spec/gem_spec.rb:97] 123\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!\e[0m\n").to_stdout
99
+ end
100
+
101
+ it "highlight and color_code" do
102
+ DbgRb.highlight!
103
+ DbgRb.color_code = 31
104
+ expect do
105
+ dbg(123)
106
+ end.to output("\e[31m!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n[spec/gem_spec.rb:105] 123\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!\e[0m\n").to_stdout
107
+ end
108
+ end
@@ -0,0 +1,108 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+ require "dbg-rb"
5
+ require "ostruct"
6
+
7
+ describe DbgRb do
8
+ before do
9
+ DbgRb.color_code = nil
10
+ end
11
+
12
+ it "constant values" do
13
+ expect do
14
+ dbg("123")
15
+ end.to output("[spec/inline_spec.rb:14] \"123\"\n").to_stdout
16
+
17
+ expect do
18
+ dbg(123)
19
+ end.to output("[spec/inline_spec.rb:18] 123\n").to_stdout
20
+
21
+ expect do
22
+ dbg(nil)
23
+ end.to output("[spec/inline_spec.rb:22] nil\n").to_stdout
24
+
25
+ expect do
26
+ dbg "123"
27
+ end.to output("[spec/inline_spec.rb:26] \"123\"\n").to_stdout
28
+
29
+ expect do
30
+ dbg 123
31
+ end.to output("[spec/inline_spec.rb:30] 123\n").to_stdout
32
+
33
+ expect do
34
+ dbg nil
35
+ end.to output("[spec/inline_spec.rb:34] nil\n").to_stdout
36
+ end
37
+
38
+ it "variables" do
39
+ a = 123
40
+
41
+ expect do
42
+ dbg(a)
43
+ end.to output("[spec/inline_spec.rb:42] a = 123\n").to_stdout
44
+
45
+ b = "123"
46
+
47
+ expect do
48
+ dbg(b)
49
+ end.to output("[spec/inline_spec.rb:48] b = \"123\"\n").to_stdout
50
+
51
+ c = nil
52
+
53
+ expect do
54
+ dbg(c)
55
+ end.to output("[spec/inline_spec.rb:54] c = nil\n").to_stdout
56
+ end
57
+
58
+ it "complex objects" do
59
+ s = OpenStruct.new(a: 1, b: 2)
60
+
61
+ expect do
62
+ dbg(s)
63
+ end.to output("[spec/inline_spec.rb:62] s = #<OpenStruct a=1, b=2>\n").to_stdout
64
+ end
65
+
66
+ it "hashes" do
67
+ h = { a: 1, b: "2" }
68
+ expect do
69
+ dbg(h)
70
+ end.to output("[spec/inline_spec.rb:69] h = {\n \"a\": 1,\n \"b\": \"2\"\n}\n").to_stdout
71
+ end
72
+
73
+ it "arrays" do
74
+ a = [1, "str"]
75
+ expect do
76
+ dbg(a)
77
+ end.to output("[spec/inline_spec.rb:76] a = [\n 1,\n \"str\"\n]\n").to_stdout
78
+ end
79
+
80
+ it "hash formatting" do
81
+ h = { a: 1, b: "2", c: nil }
82
+ expect do
83
+ dbg(h)
84
+ end.to output("[spec/inline_spec.rb:83] h = {\n \"a\": 1,\n \"b\": \"2\",\n \"c\": nil\n}\n").to_stdout
85
+ end
86
+
87
+ it "highlight" do
88
+ DbgRb.highlight!
89
+ expect do
90
+ dbg("123")
91
+ end.to output("!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n[spec/inline_spec.rb:90] \"123\"\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n").to_stdout
92
+ end
93
+
94
+ it "color_code" do
95
+ DbgRb.color_code = 31
96
+ expect do
97
+ dbg(123)
98
+ end.to output("\e[31m!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n[spec/inline_spec.rb:97] 123\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!\e[0m\n").to_stdout
99
+ end
100
+
101
+ it "highlight and color_code" do
102
+ DbgRb.highlight!
103
+ DbgRb.color_code = 31
104
+ expect do
105
+ dbg(123)
106
+ end.to output("\e[31m!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n[spec/inline_spec.rb:105] 123\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!\e[0m\n").to_stdout
107
+ end
108
+ end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dbg-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - pawurb
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-01-05 00:00:00.000000000 Z
11
+ date: 2025-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: binding_of_caller
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: json
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -111,9 +97,11 @@ files:
111
97
  - dbg-rb.gemspec
112
98
  - dbg_base.png
113
99
  - dbg_emoji.png
100
+ - inline/dbg_rb.rb
114
101
  - lib/dbg-rb.rb
115
102
  - lib/dbg_rb/version.rb
116
- - spec/smoke_spec.rb
103
+ - spec/gem_spec.rb
104
+ - spec/inline_spec.rb
117
105
  - spec/spec_helper.rb
118
106
  homepage: http://github.com/pawurb/dbg-rb
119
107
  licenses:
data/spec/smoke_spec.rb DELETED
@@ -1,78 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
- require "dbg-rb"
5
- require "ostruct"
6
-
7
- describe DbgRb do
8
- before do
9
- DbgRb.color_code = nil
10
- end
11
-
12
- it "variable values" do
13
- expect { dbg("123") }.to output("[spec/smoke_spec.rb:13] \"123\"\n").to_stdout
14
- end
15
-
16
- it "binded variables" do
17
- b = 123
18
- expect { dbg(:b) }.to output("[spec/smoke_spec.rb:18] b = 123\n").to_stdout
19
- end
20
-
21
- it "missing binded variables" do
22
- b = 123
23
- expect { dbg(:c) }.to output("[spec/smoke_spec.rb:23] :c\n").to_stdout
24
- end
25
-
26
- it "complex objects" do
27
- s = OpenStruct.new(a: 1, b: 2)
28
- expect { dbg!(s) }.to output("[spec/smoke_spec.rb:28] #<OpenStruct a=1, b=2>\n").to_stdout
29
- end
30
-
31
- it "binded complex objects" do
32
- s = OpenStruct.new(a: 1, b: 2)
33
- expect { dbg!(:s) }.to output("[spec/smoke_spec.rb:33] s = #<OpenStruct a=1, b=2>\n").to_stdout
34
- end
35
-
36
- it "multiple msg" do
37
- s = OpenStruct.new(a: 1, b: 2)
38
- expect { dbg!(:s, "other msg") }.to output("[spec/smoke_spec.rb:38] s = #<OpenStruct a=1, b=2>\n[spec/smoke_spec.rb:38] \"other msg\"\n").to_stdout
39
- end
40
-
41
- it "nil" do
42
- expect { dbg!(nil) }.to output("[spec/smoke_spec.rb:42] nil\n").to_stdout
43
- end
44
-
45
- it "highlight" do
46
- DbgRb.highlight!
47
- expect { dbg!("123") }.to output("!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n[spec/smoke_spec.rb:47] \"123\"\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n").to_stdout
48
- end
49
-
50
- it "color_code" do
51
- DbgRb.color_code = 31
52
- expect { dbg!(123) }.to output("\e[31m!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n[spec/smoke_spec.rb:52] 123\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!\e[0m\n").to_stdout
53
- end
54
-
55
- it "alias" do
56
- DbgRb.highlight!(false)
57
- DbgRb.color_code = nil
58
-
59
- expect {
60
- dbg(123)
61
- }.to output("[spec/smoke_spec.rb:60] 123\n").to_stdout
62
- end
63
-
64
- it "binded nil variables" do
65
- b = nil
66
- expect { dbg(:b) }.to output("[spec/smoke_spec.rb:66] b = nil\n").to_stdout
67
- end
68
-
69
- it "hashes" do
70
- h = { a: 1, b: "2" }
71
- expect { dbg!(h) }.to output("[spec/smoke_spec.rb:71] {\n \"a\": 1,\n \"b\": \"2\"\n}\n").to_stdout
72
- end
73
-
74
- it "arrays" do
75
- a = [1, "str"]
76
- expect { dbg!(a) }.to output("[spec/smoke_spec.rb:76] [\n 1,\n \"str\"\n]\n").to_stdout
77
- end
78
- end