raygun4ruby 3.2.5.pre → 4.0.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/tests.yml +48 -0
- data/.gitignore +22 -21
- data/.rspec +1 -1
- data/Appraisals +19 -0
- data/CHANGELOG.md +169 -130
- data/Gemfile +4 -4
- data/LICENSE.txt +22 -22
- data/README.md +424 -420
- data/Rakefile +32 -27
- data/examples/sinatras_raygun.rb +17 -17
- data/gemfiles/rails_6.gemfile +9 -0
- data/gemfiles/rails_7.gemfile +10 -0
- data/gemfiles/rails_7_sidekiq_6.gemfile +10 -0
- data/lib/generators/raygun/install_generator.rb +26 -26
- data/lib/raygun/affected_user.rb +59 -59
- data/lib/raygun/breadcrumbs/breadcrumb.rb +34 -34
- data/lib/raygun/breadcrumbs/store.rb +86 -86
- data/lib/raygun/breadcrumbs.rb +34 -34
- data/lib/raygun/client.rb +313 -308
- data/lib/raygun/configuration.rb +197 -194
- data/lib/raygun/demo_exception.rb +23 -0
- data/lib/raygun/error.rb +10 -10
- data/lib/raygun/error_subscriber.rb +21 -0
- data/lib/raygun/javascript_tracker.rb +42 -42
- data/lib/raygun/middleware/breadcrumbs_store_initializer.rb +19 -19
- data/lib/raygun/middleware/javascript_exception_tracking.rb +40 -32
- data/lib/raygun/middleware/rack_exception_interceptor.rb +18 -18
- data/lib/raygun/middleware/rails_insert_affected_user.rb +26 -26
- data/lib/raygun/railtie.rb +47 -39
- data/lib/raygun/services/apply_whitelist_filter_to_payload.rb +27 -27
- data/lib/raygun/sidekiq.rb +51 -71
- data/lib/raygun/version.rb +3 -3
- data/lib/raygun.rb +197 -179
- data/lib/raygun4ruby.rb +1 -1
- data/lib/resque/failure/raygun.rb +25 -25
- data/lib/tasks/raygun.tasks +7 -7
- data/raygun4ruby.gemspec +43 -45
- data/spec/features/javascript_spec.rb +48 -48
- data/spec/rails_applications/6.1.4/Gemfile +56 -0
- data/spec/{dummy/README.rdoc → rails_applications/6.1.4/README.md} +24 -28
- data/spec/{dummy → rails_applications/6.1.4}/Rakefile +6 -6
- data/spec/rails_applications/6.1.4/app/assets/config/manifest.js +2 -0
- data/spec/{dummy → rails_applications/6.1.4}/app/assets/stylesheets/application.css +15 -15
- data/spec/rails_applications/6.1.4/app/channels/application_cable/channel.rb +4 -0
- data/spec/rails_applications/6.1.4/app/channels/application_cable/connection.rb +4 -0
- data/spec/rails_applications/6.1.4/app/controllers/application_controller.rb +2 -0
- data/spec/{dummy → rails_applications/6.1.4}/app/controllers/home_controller.rb +4 -4
- data/spec/{dummy → rails_applications/6.1.4}/app/helpers/application_helper.rb +2 -2
- data/spec/rails_applications/6.1.4/app/javascript/channels/consumer.js +6 -0
- data/spec/rails_applications/6.1.4/app/javascript/channels/index.js +5 -0
- data/spec/rails_applications/6.1.4/app/javascript/packs/application.js +13 -0
- data/spec/rails_applications/6.1.4/app/jobs/application_job.rb +7 -0
- data/spec/rails_applications/6.1.4/app/mailers/application_mailer.rb +4 -0
- data/spec/rails_applications/6.1.4/app/models/application_record.rb +3 -0
- data/spec/{dummy → rails_applications/6.1.4}/app/views/home/index.html.erb +3 -3
- data/spec/{dummy → rails_applications/6.1.4}/app/views/home/index.json.erb +1 -1
- data/spec/rails_applications/6.1.4/app/views/layouts/application.html.erb +13 -0
- data/spec/rails_applications/6.1.4/app/views/layouts/mailer.html.erb +13 -0
- data/spec/rails_applications/6.1.4/app/views/layouts/mailer.text.erb +1 -0
- data/spec/rails_applications/6.1.4/bin/rails +5 -0
- data/spec/rails_applications/6.1.4/bin/rake +5 -0
- data/spec/rails_applications/6.1.4/bin/setup +36 -0
- data/spec/rails_applications/6.1.4/bin/spring +14 -0
- data/spec/rails_applications/6.1.4/bin/yarn +17 -0
- data/spec/rails_applications/6.1.4/config/application.rb +22 -0
- data/spec/rails_applications/6.1.4/config/boot.rb +3 -0
- data/spec/rails_applications/6.1.4/config/cable.yml +10 -0
- data/spec/rails_applications/6.1.4/config/credentials.yml.enc +1 -0
- data/spec/{dummy → rails_applications/6.1.4}/config/database.yml +25 -25
- data/spec/{dummy → rails_applications/6.1.4}/config/environment.rb +5 -5
- data/spec/rails_applications/6.1.4/config/environments/development.rb +76 -0
- data/spec/rails_applications/6.1.4/config/environments/production.rb +120 -0
- data/spec/rails_applications/6.1.4/config/environments/test.rb +60 -0
- data/spec/rails_applications/6.1.4/config/initializers/application_controller_renderer.rb +8 -0
- data/spec/rails_applications/6.1.4/config/initializers/assets.rb +14 -0
- data/spec/rails_applications/6.1.4/config/initializers/backtrace_silencers.rb +8 -0
- data/spec/rails_applications/6.1.4/config/initializers/content_security_policy.rb +30 -0
- data/spec/{dummy → rails_applications/6.1.4}/config/initializers/cookies_serializer.rb +5 -3
- data/spec/{dummy → rails_applications/6.1.4}/config/initializers/filter_parameter_logging.rb +6 -4
- data/spec/{dummy → rails_applications/6.1.4}/config/initializers/inflections.rb +16 -16
- data/spec/{dummy → rails_applications/6.1.4}/config/initializers/mime_types.rb +4 -4
- data/spec/rails_applications/6.1.4/config/initializers/permissions_policy.rb +11 -0
- data/spec/{dummy → rails_applications/6.1.4}/config/initializers/wrap_parameters.rb +14 -14
- data/spec/{dummy → rails_applications/6.1.4}/config/locales/en.yml +33 -23
- data/spec/rails_applications/6.1.4/config/master.key +1 -0
- data/spec/rails_applications/6.1.4/config/puma.rb +43 -0
- data/spec/rails_applications/6.1.4/config/routes.rb +4 -0
- data/spec/rails_applications/6.1.4/config/spring.rb +6 -0
- data/spec/rails_applications/6.1.4/config/storage.yml +34 -0
- data/spec/{dummy → rails_applications/6.1.4}/config.ru +6 -4
- data/spec/rails_applications/6.1.4/db/seeds.rb +7 -0
- data/spec/rails_applications/6.1.4/package.json +11 -0
- data/spec/{dummy → rails_applications/6.1.4}/public/404.html +67 -67
- data/spec/{dummy → rails_applications/6.1.4}/public/422.html +67 -67
- data/spec/{dummy → rails_applications/6.1.4}/public/500.html +66 -66
- data/spec/rails_applications/6.1.4/public/robots.txt +1 -0
- data/spec/rails_applications/7.1.3/.dockerignore +37 -0
- data/spec/rails_applications/7.1.3/.gitattributes +9 -0
- data/spec/rails_applications/7.1.3/.gitignore +35 -0
- data/spec/rails_applications/7.1.3/.ruby-version +1 -0
- data/spec/rails_applications/7.1.3/Dockerfile +62 -0
- data/spec/rails_applications/7.1.3/Gemfile +67 -0
- data/spec/rails_applications/7.1.3/README.md +24 -0
- data/spec/rails_applications/7.1.3/Rakefile +6 -0
- data/spec/rails_applications/7.1.3/app/assets/config/manifest.js +4 -0
- data/spec/rails_applications/7.1.3/app/assets/stylesheets/application.css +15 -0
- data/spec/rails_applications/7.1.3/app/channels/application_cable/channel.rb +4 -0
- data/spec/rails_applications/7.1.3/app/channels/application_cable/connection.rb +4 -0
- data/spec/rails_applications/7.1.3/app/controllers/application_controller.rb +2 -0
- data/spec/rails_applications/7.1.3/app/controllers/concerns/.keep +0 -0
- data/spec/rails_applications/7.1.3/app/controllers/home_controller.rb +2 -0
- data/spec/rails_applications/7.1.3/app/helpers/application_helper.rb +2 -0
- data/spec/rails_applications/7.1.3/app/helpers/home_helper.rb +2 -0
- data/spec/rails_applications/7.1.3/app/javascript/application.js +3 -0
- data/spec/rails_applications/7.1.3/app/javascript/controllers/application.js +9 -0
- data/spec/rails_applications/7.1.3/app/javascript/controllers/hello_controller.js +7 -0
- data/spec/rails_applications/7.1.3/app/javascript/controllers/index.js +11 -0
- data/spec/rails_applications/7.1.3/app/jobs/application_job.rb +7 -0
- data/spec/rails_applications/7.1.3/app/mailers/application_mailer.rb +4 -0
- data/spec/rails_applications/7.1.3/app/models/application_record.rb +3 -0
- data/spec/rails_applications/7.1.3/app/models/concerns/.keep +0 -0
- data/spec/rails_applications/7.1.3/app/views/home/index.html.erb +3 -0
- data/spec/rails_applications/7.1.3/app/views/home/index.json.erb +1 -0
- data/spec/rails_applications/7.1.3/app/views/layouts/application.html.erb +16 -0
- data/spec/rails_applications/7.1.3/app/views/layouts/mailer.html.erb +13 -0
- data/spec/rails_applications/7.1.3/app/views/layouts/mailer.text.erb +1 -0
- data/spec/rails_applications/7.1.3/bin/bundle +109 -0
- data/spec/rails_applications/7.1.3/bin/docker-entrypoint +8 -0
- data/spec/rails_applications/7.1.3/bin/importmap +4 -0
- data/spec/rails_applications/7.1.3/bin/rails +4 -0
- data/spec/rails_applications/7.1.3/bin/rake +4 -0
- data/spec/rails_applications/7.1.3/bin/setup +33 -0
- data/spec/rails_applications/7.1.3/config/application.rb +27 -0
- data/spec/rails_applications/7.1.3/config/boot.rb +4 -0
- data/spec/rails_applications/7.1.3/config/cable.yml +11 -0
- data/spec/rails_applications/7.1.3/config/credentials.yml.enc +1 -0
- data/spec/rails_applications/7.1.3/config/database.yml +25 -0
- data/spec/rails_applications/7.1.3/config/environment.rb +5 -0
- data/spec/rails_applications/7.1.3/config/environments/development.rb +76 -0
- data/spec/rails_applications/7.1.3/config/environments/production.rb +97 -0
- data/spec/rails_applications/7.1.3/config/environments/test.rb +64 -0
- data/spec/rails_applications/7.1.3/config/importmap.rb +7 -0
- data/spec/rails_applications/7.1.3/config/initializers/assets.rb +12 -0
- data/spec/rails_applications/7.1.3/config/initializers/content_security_policy.rb +25 -0
- data/spec/rails_applications/7.1.3/config/initializers/filter_parameter_logging.rb +8 -0
- data/spec/rails_applications/7.1.3/config/initializers/inflections.rb +16 -0
- data/spec/rails_applications/7.1.3/config/initializers/permissions_policy.rb +13 -0
- data/spec/rails_applications/7.1.3/config/locales/en.yml +31 -0
- data/spec/rails_applications/7.1.3/config/puma.rb +35 -0
- data/spec/rails_applications/7.1.3/config/routes.rb +11 -0
- data/spec/rails_applications/7.1.3/config/storage.yml +34 -0
- data/spec/rails_applications/7.1.3/config.ru +6 -0
- data/spec/rails_applications/7.1.3/db/seeds.rb +9 -0
- data/spec/rails_applications/7.1.3/lib/assets/.keep +0 -0
- data/spec/rails_applications/7.1.3/lib/tasks/.keep +0 -0
- data/spec/rails_applications/7.1.3/public/404.html +67 -0
- data/spec/rails_applications/7.1.3/public/422.html +67 -0
- data/spec/rails_applications/7.1.3/public/500.html +66 -0
- data/spec/rails_applications/7.1.3/public/apple-touch-icon-precomposed.png +0 -0
- data/spec/rails_applications/7.1.3/public/apple-touch-icon.png +0 -0
- data/spec/rails_applications/7.1.3/public/favicon.ico +0 -0
- data/spec/rails_applications/7.1.3/public/robots.txt +1 -0
- data/spec/rails_applications/7.1.3/storage/.keep +0 -0
- data/spec/rails_applications/7.1.3/test/application_system_test_case.rb +5 -0
- data/spec/rails_applications/7.1.3/test/channels/application_cable/connection_test.rb +13 -0
- data/spec/rails_applications/7.1.3/test/controllers/.keep +0 -0
- data/spec/rails_applications/7.1.3/test/controllers/home_controller_test.rb +7 -0
- data/spec/rails_applications/7.1.3/test/fixtures/files/.keep +0 -0
- data/spec/rails_applications/7.1.3/test/helpers/.keep +0 -0
- data/spec/rails_applications/7.1.3/test/integration/.keep +0 -0
- data/spec/rails_applications/7.1.3/test/mailers/.keep +0 -0
- data/spec/rails_applications/7.1.3/test/models/.keep +0 -0
- data/spec/rails_applications/7.1.3/test/system/.keep +0 -0
- data/spec/rails_applications/7.1.3/test/test_helper.rb +15 -0
- data/spec/rails_applications/7.1.3/vendor/.keep +0 -0
- data/spec/rails_applications/7.1.3/vendor/javascript/.keep +0 -0
- data/spec/rails_helper.rb +8 -4
- data/spec/raygun/breadcrumbs/breadcrumb_spec.rb +171 -171
- data/spec/raygun/breadcrumbs/store_spec.rb +170 -170
- data/spec/services/apply_whitelist_filter_to_payload_spec.rb +251 -251
- data/spec/spec_helper.rb +24 -24
- data/spec/support/fake_logger.rb +17 -17
- data/test/integration/client_test.rb +19 -19
- data/test/rails_helper.rb +6 -0
- data/test/test_helper.rb +76 -72
- data/test/unit/affected_user_test.rb +136 -136
- data/test/unit/client_test.rb +812 -812
- data/test/unit/configuration_test.rb +202 -206
- data/test/unit/error_subscriber_test.rb +43 -0
- data/test/unit/raygun_test.rb +106 -25
- data/test/unit/resque_failure_test.rb +27 -24
- data/test/unit/sidekiq_failure_test.rb +42 -32
- metadata +186 -115
- data/.travis.yml +0 -20
- data/spec/dummy/.gitignore +0 -17
- data/spec/dummy/Gemfile +0 -47
- data/spec/dummy/app/assets/config/manifest.js +0 -3
- data/spec/dummy/app/assets/javascripts/application.js +0 -13
- data/spec/dummy/app/controllers/application_controller.rb +0 -5
- data/spec/dummy/app/views/layouts/application.html.erb +0 -14
- data/spec/dummy/bin/bundle +0 -3
- data/spec/dummy/bin/rails +0 -9
- data/spec/dummy/bin/rake +0 -9
- data/spec/dummy/bin/setup +0 -29
- data/spec/dummy/bin/spring +0 -17
- data/spec/dummy/config/application.rb +0 -26
- data/spec/dummy/config/boot.rb +0 -3
- data/spec/dummy/config/environments/development.rb +0 -41
- data/spec/dummy/config/environments/production.rb +0 -79
- data/spec/dummy/config/initializers/assets.rb +0 -11
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/dummy/config/initializers/session_store.rb +0 -3
- data/spec/dummy/config/initializers/to_time_preserves_timezone.rb +0 -10
- data/spec/dummy/config/routes.rb +0 -58
- data/spec/dummy/config/secrets.yml +0 -22
- data/spec/dummy/db/seeds.rb +0 -7
- data/spec/dummy/public/robots.txt +0 -5
- data/spec/raygun/raygun_spec.rb +0 -47
- /data/spec/{dummy → rails_applications/6.1.4}/app/assets/images/.keep +0 -0
- /data/spec/{dummy → rails_applications/6.1.4}/app/controllers/concerns/.keep +0 -0
- /data/spec/{dummy/app/mailers → rails_applications/6.1.4/app/models/concerns}/.keep +0 -0
- /data/spec/{dummy/app/models/.keep → rails_applications/6.1.4/db/test.sqlite3} +0 -0
- /data/spec/{dummy/app/models/concerns → rails_applications/6.1.4/lib/assets}/.keep +0 -0
- /data/spec/{dummy/lib/assets → rails_applications/6.1.4/lib/tasks}/.keep +0 -0
- /data/spec/{dummy/lib/tasks/.keep → rails_applications/6.1.4/public/apple-touch-icon-precomposed.png} +0 -0
- /data/spec/{dummy/log/.keep → rails_applications/6.1.4/public/apple-touch-icon.png} +0 -0
- /data/spec/{dummy → rails_applications/6.1.4}/public/favicon.ico +0 -0
- /data/spec/{dummy/vendor/assets/javascripts → rails_applications/6.1.4/storage}/.keep +0 -0
- /data/spec/{dummy/vendor/assets/stylesheets → rails_applications/7.1.3/app/assets/images}/.keep +0 -0
@@ -1,171 +1,171 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
module Raygun
|
4
|
-
module Breadcrumbs
|
5
|
-
describe Breadcrumb do
|
6
|
-
let(:subject) { Breadcrumb.new }
|
7
|
-
context 'fields' do
|
8
|
-
it 'has a message' do
|
9
|
-
message = 'foo'
|
10
|
-
|
11
|
-
subject.message = message
|
12
|
-
|
13
|
-
expect(subject.message).to eq(message)
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'has a category' do
|
17
|
-
category = 'foo'
|
18
|
-
|
19
|
-
subject.category = category
|
20
|
-
|
21
|
-
expect(subject.category).to eq(category)
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'has a level' do
|
25
|
-
level = 'foo'
|
26
|
-
|
27
|
-
subject.level = level
|
28
|
-
|
29
|
-
expect(subject.level).to eq(level)
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'has a timestamp' do
|
33
|
-
timestamp = Time.now
|
34
|
-
|
35
|
-
subject.timestamp = timestamp
|
36
|
-
|
37
|
-
expect(subject.timestamp).to eq(timestamp)
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'has metadata' do
|
41
|
-
metadata = {foo: '1'}
|
42
|
-
|
43
|
-
subject.metadata = metadata
|
44
|
-
|
45
|
-
expect(subject.metadata).to eq(metadata)
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'has a class_name' do
|
49
|
-
class_name = 'foo'
|
50
|
-
|
51
|
-
subject.class_name = class_name
|
52
|
-
|
53
|
-
expect(subject.class_name).to eq(class_name)
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'has a method_name' do
|
57
|
-
method_name = 'foo'
|
58
|
-
|
59
|
-
subject.method_name = method_name
|
60
|
-
|
61
|
-
expect(subject.method_name).to eq(method_name)
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'has a line_number' do
|
65
|
-
line_number = 17
|
66
|
-
|
67
|
-
subject.line_number = line_number
|
68
|
-
|
69
|
-
expect(subject.line_number).to eq(line_number)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
describe "#build_payload" do
|
74
|
-
before do
|
75
|
-
Timecop.freeze
|
76
|
-
Store.initialize
|
77
|
-
end
|
78
|
-
after do
|
79
|
-
Timecop.return
|
80
|
-
Store.clear
|
81
|
-
end
|
82
|
-
|
83
|
-
let(:breadcrumb) do
|
84
|
-
Store.record(
|
85
|
-
message: "test",
|
86
|
-
category: "test",
|
87
|
-
level: :info,
|
88
|
-
class_name: "HomeController",
|
89
|
-
method_name: "index",
|
90
|
-
line_number: 17,
|
91
|
-
metadata: {
|
92
|
-
foo: 'bar'
|
93
|
-
}
|
94
|
-
)
|
95
|
-
|
96
|
-
Store.stored[0]
|
97
|
-
end
|
98
|
-
let(:payload) { breadcrumb.build_payload }
|
99
|
-
|
100
|
-
it "joins the class name, method name and line number together" do
|
101
|
-
expect(payload[:location]).to eq("HomeController:index:17")
|
102
|
-
end
|
103
|
-
|
104
|
-
it "does not include the method name and line number if the class name is missing" do
|
105
|
-
breadcrumb.class_name = nil
|
106
|
-
|
107
|
-
expect(payload.has_key?(:location)).to eq(false)
|
108
|
-
end
|
109
|
-
|
110
|
-
it "does not inlcude the line number if is it missing" do
|
111
|
-
breadcrumb.line_number = nil
|
112
|
-
|
113
|
-
expect(payload[:location]).to eq("HomeController:index")
|
114
|
-
end
|
115
|
-
|
116
|
-
it "does not include keys in payload with nil values" do
|
117
|
-
breadcrumb.metadata = nil
|
118
|
-
breadcrumb.category = nil
|
119
|
-
|
120
|
-
expect(payload.key?(:CustomData)).to eq(false)
|
121
|
-
expect(payload.key?(:category)).to eq(false)
|
122
|
-
end
|
123
|
-
|
124
|
-
it 'includes the rest of the fields' do
|
125
|
-
expect(payload[:message]).to eq('test')
|
126
|
-
expect(payload[:category]).to eq('test')
|
127
|
-
expect(payload[:level]).to eq(1)
|
128
|
-
expect(payload[:timestamp]).to_not eq(nil)
|
129
|
-
expect(payload[:CustomData]).to eq(foo: 'bar')
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
describe "#size" do
|
134
|
-
before do
|
135
|
-
Timecop.freeze
|
136
|
-
Store.initialize
|
137
|
-
end
|
138
|
-
after do
|
139
|
-
Timecop.return
|
140
|
-
Store.clear
|
141
|
-
end
|
142
|
-
|
143
|
-
let(:message) { "This is a breadcrumb message" }
|
144
|
-
|
145
|
-
let(:breadcrumb) do
|
146
|
-
Store.record(
|
147
|
-
message: message,
|
148
|
-
category: "test",
|
149
|
-
level: :info,
|
150
|
-
class_name: "HomeController",
|
151
|
-
method_name: "index",
|
152
|
-
line_number: 17,
|
153
|
-
metadata: {
|
154
|
-
foo: 'bar'
|
155
|
-
}
|
156
|
-
)
|
157
|
-
|
158
|
-
Store.stored[0]
|
159
|
-
end
|
160
|
-
|
161
|
-
let(:size) { breadcrumb.size }
|
162
|
-
|
163
|
-
it "returns the estimated size of the breadcrumb" do
|
164
|
-
# Can't check all the fields but message so assume a standard 100 length for all of them
|
165
|
-
# The message should be the bulk of large breadcrumbs anyway
|
166
|
-
expect(size).to eq(message.length + 100)
|
167
|
-
end
|
168
|
-
end
|
169
|
-
end
|
170
|
-
end
|
171
|
-
end
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module Raygun
|
4
|
+
module Breadcrumbs
|
5
|
+
describe Breadcrumb do
|
6
|
+
let(:subject) { Breadcrumb.new }
|
7
|
+
context 'fields' do
|
8
|
+
it 'has a message' do
|
9
|
+
message = 'foo'
|
10
|
+
|
11
|
+
subject.message = message
|
12
|
+
|
13
|
+
expect(subject.message).to eq(message)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'has a category' do
|
17
|
+
category = 'foo'
|
18
|
+
|
19
|
+
subject.category = category
|
20
|
+
|
21
|
+
expect(subject.category).to eq(category)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'has a level' do
|
25
|
+
level = 'foo'
|
26
|
+
|
27
|
+
subject.level = level
|
28
|
+
|
29
|
+
expect(subject.level).to eq(level)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'has a timestamp' do
|
33
|
+
timestamp = Time.now
|
34
|
+
|
35
|
+
subject.timestamp = timestamp
|
36
|
+
|
37
|
+
expect(subject.timestamp).to eq(timestamp)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'has metadata' do
|
41
|
+
metadata = {foo: '1'}
|
42
|
+
|
43
|
+
subject.metadata = metadata
|
44
|
+
|
45
|
+
expect(subject.metadata).to eq(metadata)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'has a class_name' do
|
49
|
+
class_name = 'foo'
|
50
|
+
|
51
|
+
subject.class_name = class_name
|
52
|
+
|
53
|
+
expect(subject.class_name).to eq(class_name)
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'has a method_name' do
|
57
|
+
method_name = 'foo'
|
58
|
+
|
59
|
+
subject.method_name = method_name
|
60
|
+
|
61
|
+
expect(subject.method_name).to eq(method_name)
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'has a line_number' do
|
65
|
+
line_number = 17
|
66
|
+
|
67
|
+
subject.line_number = line_number
|
68
|
+
|
69
|
+
expect(subject.line_number).to eq(line_number)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "#build_payload" do
|
74
|
+
before do
|
75
|
+
Timecop.freeze
|
76
|
+
Store.initialize
|
77
|
+
end
|
78
|
+
after do
|
79
|
+
Timecop.return
|
80
|
+
Store.clear
|
81
|
+
end
|
82
|
+
|
83
|
+
let(:breadcrumb) do
|
84
|
+
Store.record(
|
85
|
+
message: "test",
|
86
|
+
category: "test",
|
87
|
+
level: :info,
|
88
|
+
class_name: "HomeController",
|
89
|
+
method_name: "index",
|
90
|
+
line_number: 17,
|
91
|
+
metadata: {
|
92
|
+
foo: 'bar'
|
93
|
+
}
|
94
|
+
)
|
95
|
+
|
96
|
+
Store.stored[0]
|
97
|
+
end
|
98
|
+
let(:payload) { breadcrumb.build_payload }
|
99
|
+
|
100
|
+
it "joins the class name, method name and line number together" do
|
101
|
+
expect(payload[:location]).to eq("HomeController:index:17")
|
102
|
+
end
|
103
|
+
|
104
|
+
it "does not include the method name and line number if the class name is missing" do
|
105
|
+
breadcrumb.class_name = nil
|
106
|
+
|
107
|
+
expect(payload.has_key?(:location)).to eq(false)
|
108
|
+
end
|
109
|
+
|
110
|
+
it "does not inlcude the line number if is it missing" do
|
111
|
+
breadcrumb.line_number = nil
|
112
|
+
|
113
|
+
expect(payload[:location]).to eq("HomeController:index")
|
114
|
+
end
|
115
|
+
|
116
|
+
it "does not include keys in payload with nil values" do
|
117
|
+
breadcrumb.metadata = nil
|
118
|
+
breadcrumb.category = nil
|
119
|
+
|
120
|
+
expect(payload.key?(:CustomData)).to eq(false)
|
121
|
+
expect(payload.key?(:category)).to eq(false)
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'includes the rest of the fields' do
|
125
|
+
expect(payload[:message]).to eq('test')
|
126
|
+
expect(payload[:category]).to eq('test')
|
127
|
+
expect(payload[:level]).to eq(1)
|
128
|
+
expect(payload[:timestamp]).to_not eq(nil)
|
129
|
+
expect(payload[:CustomData]).to eq(foo: 'bar')
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
describe "#size" do
|
134
|
+
before do
|
135
|
+
Timecop.freeze
|
136
|
+
Store.initialize
|
137
|
+
end
|
138
|
+
after do
|
139
|
+
Timecop.return
|
140
|
+
Store.clear
|
141
|
+
end
|
142
|
+
|
143
|
+
let(:message) { "This is a breadcrumb message" }
|
144
|
+
|
145
|
+
let(:breadcrumb) do
|
146
|
+
Store.record(
|
147
|
+
message: message,
|
148
|
+
category: "test",
|
149
|
+
level: :info,
|
150
|
+
class_name: "HomeController",
|
151
|
+
method_name: "index",
|
152
|
+
line_number: 17,
|
153
|
+
metadata: {
|
154
|
+
foo: 'bar'
|
155
|
+
}
|
156
|
+
)
|
157
|
+
|
158
|
+
Store.stored[0]
|
159
|
+
end
|
160
|
+
|
161
|
+
let(:size) { breadcrumb.size }
|
162
|
+
|
163
|
+
it "returns the estimated size of the breadcrumb" do
|
164
|
+
# Can't check all the fields but message so assume a standard 100 length for all of them
|
165
|
+
# The message should be the bulk of large breadcrumbs anyway
|
166
|
+
expect(size).to eq(message.length + 100)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
@@ -1,170 +1,170 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
module Raygun
|
4
|
-
module Breadcrumbs
|
5
|
-
describe Store do
|
6
|
-
let(:subject) { Store }
|
7
|
-
after { subject.clear }
|
8
|
-
|
9
|
-
describe "#initialize" do
|
10
|
-
before do
|
11
|
-
expect(subject.stored).to eq(nil)
|
12
|
-
|
13
|
-
subject.initialize
|
14
|
-
end
|
15
|
-
|
16
|
-
it "creates the store on the current Thread" do
|
17
|
-
expect(subject.stored).to eq([])
|
18
|
-
end
|
19
|
-
|
20
|
-
it "does not effect other threads" do
|
21
|
-
Thread.new do
|
22
|
-
expect(subject.stored).to eq(nil)
|
23
|
-
end.join
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
describe "#any?" do
|
28
|
-
it "returns true if any breadcrumbs have been logged" do
|
29
|
-
subject.initialize
|
30
|
-
|
31
|
-
subject.record(message: "test")
|
32
|
-
|
33
|
-
expect(subject.any?).to eq(true)
|
34
|
-
end
|
35
|
-
|
36
|
-
it "returns false if none have been logged" do
|
37
|
-
subject.initialize
|
38
|
-
|
39
|
-
expect(subject.any?).to eq(false)
|
40
|
-
end
|
41
|
-
|
42
|
-
it "returns false if the store is uninitialized" do
|
43
|
-
expect(subject.any?).to eq(false)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
describe "#clear" do
|
48
|
-
before do
|
49
|
-
subject.initialize
|
50
|
-
end
|
51
|
-
|
52
|
-
it "resets the store back to nil" do
|
53
|
-
subject.clear
|
54
|
-
|
55
|
-
expect(subject.stored).to eq(nil)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
describe "#should_record?" do
|
60
|
-
it "returns false when the log level is above the breadcrumbs level" do
|
61
|
-
allow(Raygun.configuration).to receive(:breadcrumb_level).and_return(:error)
|
62
|
-
|
63
|
-
crumb = Breadcrumb.new
|
64
|
-
crumb.level = :warning
|
65
|
-
|
66
|
-
expect(subject.send(:should_record?, crumb)).to eq(false)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
describe "#take_until_size" do
|
71
|
-
before do
|
72
|
-
subject.initialize
|
73
|
-
end
|
74
|
-
|
75
|
-
it "takes the most recent breadcrumbs until the size limit is reached" do
|
76
|
-
subject.record(message: '1' * 100)
|
77
|
-
subject.record(message: '2' * 100)
|
78
|
-
subject.record(message: '3' * 100)
|
79
|
-
|
80
|
-
crumbs = subject.take_until_size(500)
|
81
|
-
|
82
|
-
expect(crumbs.length).to eq(2)
|
83
|
-
expect(crumbs[0].message).to eq('2' * 100)
|
84
|
-
expect(crumbs[1].message).to eq('3' * 100)
|
85
|
-
end
|
86
|
-
|
87
|
-
it "does not crash with no recorded breadcrumbs" do
|
88
|
-
crumbs = subject.take_until_size(500)
|
89
|
-
|
90
|
-
expect(crumbs).to eq([])
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
context "adding a breadcrumb" do
|
95
|
-
class Foo
|
96
|
-
include ::Raygun::Breadcrumbs
|
97
|
-
|
98
|
-
def bar
|
99
|
-
record_breadcrumb(message: "test")
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
before do
|
104
|
-
subject.clear
|
105
|
-
subject.initialize
|
106
|
-
end
|
107
|
-
|
108
|
-
it "gets stored" do
|
109
|
-
subject.record(message: "test")
|
110
|
-
|
111
|
-
expect(subject.stored.length).to eq(1)
|
112
|
-
expect(subject.stored[0].message).to eq("test")
|
113
|
-
end
|
114
|
-
|
115
|
-
it "automatically sets the class name" do
|
116
|
-
Foo.new.bar
|
117
|
-
|
118
|
-
bc = subject.stored[0]
|
119
|
-
expect(bc.class_name).to eq("Raygun::Breadcrumbs::Foo")
|
120
|
-
end
|
121
|
-
|
122
|
-
it "automatically sets the method name" do
|
123
|
-
Foo.new.bar
|
124
|
-
|
125
|
-
bc = subject.stored[0]
|
126
|
-
expect(bc.method_name).to eq("bar")
|
127
|
-
end
|
128
|
-
|
129
|
-
it "does not set the method name if it is already set" do
|
130
|
-
subject.record(message: 'test', method_name: "foo")
|
131
|
-
|
132
|
-
expect(subject.stored[0].method_name).to eq("foo")
|
133
|
-
end
|
134
|
-
|
135
|
-
|
136
|
-
it "automatically sets the timestamp" do
|
137
|
-
Timecop.freeze do
|
138
|
-
Foo.new.bar
|
139
|
-
|
140
|
-
bc = subject.stored[0]
|
141
|
-
expect(bc.timestamp).to eq(Time.now.utc.to_i)
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
it "does not set the timestamp if it is already set" do
|
146
|
-
time = Time.now.utc
|
147
|
-
|
148
|
-
Timecop.freeze do
|
149
|
-
subject.record(message: 'test', timestamp: time)
|
150
|
-
|
151
|
-
expect(subject.stored[0].timestamp).to_not eq(Time.now.utc)
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
it "sets the log level to :info if one is not supplied" do
|
156
|
-
Foo.new.bar
|
157
|
-
|
158
|
-
expect(subject.stored[0].level).to eq(:info)
|
159
|
-
end
|
160
|
-
|
161
|
-
it "does not record the breadcrumb if should_record? is false" do
|
162
|
-
expect(subject).to receive(:should_record?).and_return(false)
|
163
|
-
Foo.new.bar
|
164
|
-
|
165
|
-
expect(subject.stored.length).to eq(0)
|
166
|
-
end
|
167
|
-
end
|
168
|
-
end
|
169
|
-
end
|
170
|
-
end
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module Raygun
|
4
|
+
module Breadcrumbs
|
5
|
+
describe Store do
|
6
|
+
let(:subject) { Store }
|
7
|
+
after { subject.clear }
|
8
|
+
|
9
|
+
describe "#initialize" do
|
10
|
+
before do
|
11
|
+
expect(subject.stored).to eq(nil)
|
12
|
+
|
13
|
+
subject.initialize
|
14
|
+
end
|
15
|
+
|
16
|
+
it "creates the store on the current Thread" do
|
17
|
+
expect(subject.stored).to eq([])
|
18
|
+
end
|
19
|
+
|
20
|
+
it "does not effect other threads" do
|
21
|
+
Thread.new do
|
22
|
+
expect(subject.stored).to eq(nil)
|
23
|
+
end.join
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#any?" do
|
28
|
+
it "returns true if any breadcrumbs have been logged" do
|
29
|
+
subject.initialize
|
30
|
+
|
31
|
+
subject.record(message: "test")
|
32
|
+
|
33
|
+
expect(subject.any?).to eq(true)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "returns false if none have been logged" do
|
37
|
+
subject.initialize
|
38
|
+
|
39
|
+
expect(subject.any?).to eq(false)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "returns false if the store is uninitialized" do
|
43
|
+
expect(subject.any?).to eq(false)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "#clear" do
|
48
|
+
before do
|
49
|
+
subject.initialize
|
50
|
+
end
|
51
|
+
|
52
|
+
it "resets the store back to nil" do
|
53
|
+
subject.clear
|
54
|
+
|
55
|
+
expect(subject.stored).to eq(nil)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "#should_record?" do
|
60
|
+
it "returns false when the log level is above the breadcrumbs level" do
|
61
|
+
allow(Raygun.configuration).to receive(:breadcrumb_level).and_return(:error)
|
62
|
+
|
63
|
+
crumb = Breadcrumb.new
|
64
|
+
crumb.level = :warning
|
65
|
+
|
66
|
+
expect(subject.send(:should_record?, crumb)).to eq(false)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "#take_until_size" do
|
71
|
+
before do
|
72
|
+
subject.initialize
|
73
|
+
end
|
74
|
+
|
75
|
+
it "takes the most recent breadcrumbs until the size limit is reached" do
|
76
|
+
subject.record(message: '1' * 100)
|
77
|
+
subject.record(message: '2' * 100)
|
78
|
+
subject.record(message: '3' * 100)
|
79
|
+
|
80
|
+
crumbs = subject.take_until_size(500)
|
81
|
+
|
82
|
+
expect(crumbs.length).to eq(2)
|
83
|
+
expect(crumbs[0].message).to eq('2' * 100)
|
84
|
+
expect(crumbs[1].message).to eq('3' * 100)
|
85
|
+
end
|
86
|
+
|
87
|
+
it "does not crash with no recorded breadcrumbs" do
|
88
|
+
crumbs = subject.take_until_size(500)
|
89
|
+
|
90
|
+
expect(crumbs).to eq([])
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
context "adding a breadcrumb" do
|
95
|
+
class Foo
|
96
|
+
include ::Raygun::Breadcrumbs
|
97
|
+
|
98
|
+
def bar
|
99
|
+
record_breadcrumb(message: "test")
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
before do
|
104
|
+
subject.clear
|
105
|
+
subject.initialize
|
106
|
+
end
|
107
|
+
|
108
|
+
it "gets stored" do
|
109
|
+
subject.record(message: "test")
|
110
|
+
|
111
|
+
expect(subject.stored.length).to eq(1)
|
112
|
+
expect(subject.stored[0].message).to eq("test")
|
113
|
+
end
|
114
|
+
|
115
|
+
it "automatically sets the class name" do
|
116
|
+
Foo.new.bar
|
117
|
+
|
118
|
+
bc = subject.stored[0]
|
119
|
+
expect(bc.class_name).to eq("Raygun::Breadcrumbs::Foo")
|
120
|
+
end
|
121
|
+
|
122
|
+
it "automatically sets the method name" do
|
123
|
+
Foo.new.bar
|
124
|
+
|
125
|
+
bc = subject.stored[0]
|
126
|
+
expect(bc.method_name).to eq("bar")
|
127
|
+
end
|
128
|
+
|
129
|
+
it "does not set the method name if it is already set" do
|
130
|
+
subject.record(message: 'test', method_name: "foo")
|
131
|
+
|
132
|
+
expect(subject.stored[0].method_name).to eq("foo")
|
133
|
+
end
|
134
|
+
|
135
|
+
|
136
|
+
it "automatically sets the timestamp" do
|
137
|
+
Timecop.freeze do
|
138
|
+
Foo.new.bar
|
139
|
+
|
140
|
+
bc = subject.stored[0]
|
141
|
+
expect(bc.timestamp).to eq(Time.now.utc.to_i)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
it "does not set the timestamp if it is already set" do
|
146
|
+
time = Time.now.utc
|
147
|
+
|
148
|
+
Timecop.freeze do
|
149
|
+
subject.record(message: 'test', timestamp: time)
|
150
|
+
|
151
|
+
expect(subject.stored[0].timestamp).to_not eq(Time.now.utc)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
it "sets the log level to :info if one is not supplied" do
|
156
|
+
Foo.new.bar
|
157
|
+
|
158
|
+
expect(subject.stored[0].level).to eq(:info)
|
159
|
+
end
|
160
|
+
|
161
|
+
it "does not record the breadcrumb if should_record? is false" do
|
162
|
+
expect(subject).to receive(:should_record?).and_return(false)
|
163
|
+
Foo.new.bar
|
164
|
+
|
165
|
+
expect(subject.stored.length).to eq(0)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|