@@ -13,7 +13,15 @@ def dummy_method_with_params(param_1, param_2)
13
13
RSpec . describe RailsTracepointStack ::Tracer do
14
14
let ( :tracer ) { RailsTracepointStack ::Tracer . new }
15
15
16
- context "when the log not should be ignored" do
16
+ before do
17
+ allow ( RailsTracepointStack ::Logger )
18
+ . to receive ( :log )
19
+
20
+ allow_any_instance_of ( TracePoint )
21
+ . to receive ( :lineno ) . and_return ( 6 )
22
+ end
23
+
24
+ describe "when the log should not be ignored because not match any filter block" do
17
25
before do
18
26
allow ( RailsTracepointStack ::Filter ::GemPath )
19
27
. to receive ( :full_gem_path )
@@ -23,71 +31,16 @@ def dummy_method_with_params(param_1, param_2)
23
31
. to receive ( :ruby_lib_path )
24
32
. and_return ( '/path/to/ruby/lib' )
25
33
26
- allow ( RailsTracepointStack ::Logger ) . to receive ( :log )
27
-
28
34
allow_any_instance_of ( TracePoint )
29
35
. to receive ( :path )
30
36
. and_return ( "/app/rails_tracepoint_stack/spec/tracer_spec.rb" )
31
37
32
- allow_any_instance_of ( TracePoint ) . to receive ( :lineno ) . and_return ( 6 )
33
-
34
38
allow_any_instance_of ( RailsTracepointStack ::Configuration )
35
39
. to receive ( :log_format )
36
40
. and_return ( :text )
37
41
end
38
42
39
- context "when log format is text" do
40
- before do
41
- RailsTracepointStack . configure do |config |
42
- config . log_format = :text
43
- end
44
- end
45
-
46
- it 'calls logger with correct log' do
47
- tracer . tracer . enable do
48
- Foo . new . dummy_method
49
- end
50
-
51
- expect ( RailsTracepointStack ::Logger )
52
- . to have_received ( :log )
53
- . with ( "called: Foo#dummy_method in /app/rails_tracepoint_stack/spec/tracer_spec.rb:6 with params: {}" )
54
- end
55
- end
56
-
57
- context "when log format is json" do
58
- before do
59
- RailsTracepointStack . configure do |config |
60
- config . log_format = :json
61
- end
62
- end
63
- # TODO: Extract this test to a proper place
64
- it 'calls logger with correct log with json log format' do
65
- allow_any_instance_of ( RailsTracepointStack ::Configuration )
66
- . to receive ( :log_format )
67
- . and_return ( :json )
68
-
69
- tracer . tracer . enable do
70
- Foo . new . dummy_method
71
- end
72
-
73
- expect ( RailsTracepointStack ::Logger )
74
- . to have_received ( :log )
75
- . with ( "{\" class\" :\" Foo\" ,\" method_name\" :\" dummy_method\" ,\" path\" :\" /app/rails_tracepoint_stack/spec/tracer_spec.rb\" ,\" line\" :6,\" params\" :{}}" )
76
- end
77
-
78
- # TODO: Extract this test to a proper place
79
- it 'calls logger with correct log with json log format' do
80
- allow_any_instance_of ( RailsTracepointStack ::Configuration ) . to receive ( :log_format ) . and_return ( :json )
81
-
82
- tracer . tracer . enable do
83
- Foo . new . dummy_method_with_params ( "param_1_value" , "param_2_value" )
84
- end
85
-
86
- expect ( RailsTracepointStack ::Logger )
87
- . to have_received ( :log )
88
- . with ( "{\" class\" :\" Foo\" ,\" method_name\" :\" dummy_method_with_params\" ,\" path\" :\" /app/rails_tracepoint_stack/spec/tracer_spec.rb\" ,\" line\" :6,\" params\" :{\" param_1\" :\" param_1_value\" ,\" param_2\" :\" param_2_value\" }}" )
89
- end
90
- end
43
+ include_examples "tracer success examples asserts"
91
44
end
92
45
93
46
context "when the log should be ignored because is a gem dependency" do
@@ -104,8 +57,6 @@ def dummy_method_with_params(param_1, param_2)
104
57
. to receive ( :path )
105
58
. and_return ( "/path/to/ruby/lib" )
106
59
107
- allow ( RailsTracepointStack ::Logger ) . to receive ( :log )
108
-
109
60
RailsTracepointStack . configure do |config |
110
61
config . log_external_sources = false
111
62
end
@@ -134,8 +85,6 @@ def dummy_method_with_params(param_1, param_2)
134
85
. to receive ( :path )
135
86
. and_return ( "/path/to/gem/some_file.rb" )
136
87
137
- allow ( RailsTracepointStack ::Logger ) . to receive ( :log )
138
-
139
88
RailsTracepointStack . configure do |config |
140
89
config . log_external_sources = false
141
90
end
@@ -164,8 +113,6 @@ def dummy_method_with_params(param_1, param_2)
164
113
. to receive ( :path )
165
114
. and_return ( "/another/path/to/gem/some_file.rb" )
166
115
167
- allow ( RailsTracepointStack ::Logger ) . to receive ( :log )
168
-
169
116
RailsTracepointStack . configure do |config |
170
117
config . log_external_sources = true
171
118
end
@@ -194,8 +141,6 @@ def dummy_method_with_params(param_1, param_2)
194
141
. to receive ( :path )
195
142
. and_return ( "/another/path/to/gem/some_file.rb" )
196
143
197
- allow ( RailsTracepointStack ::Logger ) . to receive ( :log )
198
-
199
144
RailsTracepointStack . configure do |config |
200
145
config . ignore_patterns = [ /another\/ path/ ]
201
146
end
@@ -222,20 +167,18 @@ def dummy_method_with_params(param_1, param_2)
222
167
223
168
allow_any_instance_of ( TracePoint )
224
169
. to receive ( :path )
225
- . and_return ( "/another/path/to/gem/some_file.rb" )
226
-
227
- allow ( RailsTracepointStack ::Logger ) . to receive ( :log )
228
-
170
+ . and_return ( "/another/path/some_file.rb" )
171
+
229
172
allow_any_instance_of ( RailsTracepointStack ::Trace )
230
173
. to receive ( :file_path )
231
- . and_return ( "/another/path/to/gem/ some_file.rb" )
174
+ . and_return ( "/another/path/some_file.rb" )
232
175
233
176
RailsTracepointStack . configure do |config |
234
177
config . file_path_to_filter_patterns = [ /another\/ path/ ]
235
178
end
236
179
end
237
180
238
- it ' calls logger' do
181
+ it " calls logger" do
239
182
tracer . tracer . enable do
240
183
Foo . new . dummy_method
241
184
end
0 commit comments