|
251 | 251 | end
|
252 | 252 | end
|
253 | 253 |
|
| 254 | + describe "#init_tracker" do |
| 255 | + it "returns a new instance of DeprecationTracker" do |
| 256 | + tracker = DeprecationTracker.init_tracker({mode: "save"}) |
| 257 | + expect(tracker).to be_a(DeprecationTracker) |
| 258 | + end |
| 259 | + |
| 260 | + it "subscribes to KernelWarnTracker deprecation events" do |
| 261 | + expect do |
| 262 | + DeprecationTracker.init_tracker({mode: "save"}) |
| 263 | + end.to change(DeprecationTracker::KernelWarnTracker.callbacks, :size).by(1) |
| 264 | + end |
| 265 | + |
| 266 | + context "when Rails.application.deprecation is not defined and ActiveSupport is defined" do |
| 267 | + it "sets the ActiveSupport::Deprecation behavior" do |
| 268 | + # Stub ActiveSupport::Deprecation with a simple behavior array |
| 269 | + stub_const("ActiveSupport::Deprecation", Class.new { |
| 270 | + def self.behavior |
| 271 | + @behavior ||= [] |
| 272 | + end |
| 273 | + }) |
| 274 | + |
| 275 | + expect do |
| 276 | + DeprecationTracker.init_tracker({mode: "save"}) |
| 277 | + end.to change(ActiveSupport::Deprecation.behavior, :size).by(1) |
| 278 | + end |
| 279 | + end |
| 280 | + |
| 281 | + context "when Rails.application.deprecation is defined" do |
| 282 | + it "sets the behavior of each Rails.application.deprecators" do |
| 283 | + # Stub Rails.application.deprecators with an array of mock deprecators |
| 284 | + fake_deprecator_1 = double("Deprecator", behavior: []) |
| 285 | + fake_deprecator_2 = double("Deprecator", behavior: []) |
| 286 | + stub_const("Rails", Module.new) |
| 287 | + allow(Rails).to receive_message_chain(:application, :deprecators).and_return([fake_deprecator_1, fake_deprecator_2]) |
| 288 | + |
| 289 | + expect do |
| 290 | + DeprecationTracker.init_tracker({ mode: "save" }) |
| 291 | + end.to change(fake_deprecator_1.behavior, :size).by(1).and change(fake_deprecator_2.behavior, :size).by(1) |
| 292 | + end |
| 293 | + end |
| 294 | + end |
| 295 | + |
254 | 296 | describe DeprecationTracker::KernelWarnTracker do
|
255 | 297 | it "captures Kernel#warn" do
|
256 | 298 | warn_messages = []
|
|
0 commit comments