-
Notifications
You must be signed in to change notification settings - Fork 42
Add VALID_MODES constant and validate tracker mode at initialization #186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| class DeprecationTracker | ||
| VALID_MODES = %i[save compare].freeze | ||
| VALID_MODES_DISPLAY = VALID_MODES.map(&:to_s).join(", ").freeze | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -264,11 +264,10 @@ | |
| expect(tracker.mode).to eq(:save) | ||
| end | ||
|
|
||
| it "does not save nor compare if mode is invalid" do | ||
| tracker = DeprecationTracker.new(shitlist_path, nil, "random_stuff") | ||
| expect(tracker).not_to receive(:save) | ||
| expect(tracker).not_to receive(:compare) | ||
| tracker.after_run | ||
| it "raises ArgumentError for invalid mode" do | ||
| expect { | ||
| DeprecationTracker.new(shitlist_path, nil, "random_stuff") | ||
| }.to raise_error(ArgumentError) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this change intentional? because it's not testing the same thing as before now it's testing that "at some point" it raises an error, but it's not really testing that it's not calling save or compare, the code could change to call save and fail with an ArgumentError caused by some code after that and this test would still pass, even if the failure is not caused by the invalid mode now it's testing an implementation detail when before it was testing the actual expected behavior of not creating a sideeffect calling those methods I think the previous test was better |
||
| end | ||
| end | ||
|
|
||
|
|
@@ -426,6 +425,27 @@ def self.behavior | |
| tracker = DeprecationTracker.init_tracker({}) | ||
| expect(tracker.mode).to eq(:compare) | ||
| end | ||
|
|
||
| it "raises ArgumentError when ENV['DEPRECATION_TRACKER'] is invalid" do | ||
| stub_const("ENV", ENV.to_h.merge("DEPRECATION_TRACKER" => "bogus")) | ||
| expect { | ||
| DeprecationTracker.init_tracker({}) | ||
| }.to raise_error(ArgumentError) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you should probably include the error message or at least part of the exception message in the expectation because now ANY ArgumentError thrown would satisfy this test, even if unrelated to a wrong tracker mode, it's not exactly testing that the reason it failed was the invalid value |
||
| end | ||
| end | ||
|
|
||
| describe "VALID_MODES" do | ||
| it "contains save and compare" do | ||
| expect(DeprecationTracker::VALID_MODES).to include(:save, :compare) | ||
| end | ||
|
|
||
| it "accepts all valid modes without error" do | ||
| DeprecationTracker::VALID_MODES.each do |mode| | ||
| expect { | ||
| DeprecationTracker.new(shitlist_path, nil, mode) | ||
| }.not_to raise_error | ||
| end | ||
| end | ||
| end | ||
|
|
||
| describe DeprecationTracker::KernelWarnTracker do | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one more thing to add and super nit pick, it feels weird that this string is stored as a constant
I'm not sure how to explain it,
VALID_MODESmakes total sense to me butVALID_MODES_DISPLAYsounds more like just a way to not repeatVALID_MODES.map(&:to_s).join(", ")than what a constant should bemaybe this can be a class method (with memoization)? or a class attribute instead of a constant?
not really a blocker though, just sharing this cause it feels weird