-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use an NpmAndYarn version class to preserve pre-release formatting
- Loading branch information
Showing
5 changed files
with
106 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
lib/dependabot/update_checkers/java_script/npm_and_yarn/version.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
require "dependabot/update_checkers/java_script/npm_and_yarn" | ||
|
||
# JavaScript pre-release versions user 1.0.1-rc1 syntax, which Gem::Version | ||
# converts into 1.0.1.pre.rc1. We override the `to_s` method to stop that | ||
# alteration. | ||
|
||
module Dependabot | ||
module UpdateCheckers | ||
module JavaScript | ||
class NpmAndYarn | ||
class Version < Gem::Version | ||
def initialize(version) | ||
@version_string = version.to_s | ||
super | ||
end | ||
|
||
def to_s | ||
@version_string | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
48 changes: 48 additions & 0 deletions
48
spec/dependabot/update_checkers/java_script/npm_and_yarn/version_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
require "dependabot/update_checkers/java_script/npm_and_yarn/version" | ||
|
||
RSpec.describe Dependabot::UpdateCheckers::JavaScript::NpmAndYarn::Version do | ||
subject(:version) { described_class.new(version_string) } | ||
let(:version_string) { "1.0.0" } | ||
|
||
describe "#to_s" do | ||
subject { version.to_s } | ||
|
||
context "with a non-prerelease" do | ||
let(:version_string) { "1.0.0" } | ||
it { is_expected.to eq "1.0.0" } | ||
end | ||
|
||
context "with a normal prerelease" do | ||
let(:version_string) { "1.0.0.pre1" } | ||
it { is_expected.to eq "1.0.0.pre1" } | ||
end | ||
|
||
context "with a JS-style prerelease" do | ||
let(:version_string) { "1.0.0-pre1" } | ||
it { is_expected.to eq "1.0.0-pre1" } | ||
end | ||
end | ||
|
||
describe "compatibility with Gem::Requirement" do | ||
subject { requirement.satisfied_by?(version) } | ||
let(:requirement) { Gem::Requirement.new(">= 1.0.0") } | ||
|
||
context "with a valid version" do | ||
let(:version_string) { "1.0.0" } | ||
it { is_expected.to eq(true) } | ||
end | ||
|
||
context "with an invalid version" do | ||
let(:version_string) { "0.9.0" } | ||
it { is_expected.to eq(false) } | ||
end | ||
|
||
context "with a valid prerelease version" do | ||
let(:version_string) { "1.1.0-pre" } | ||
it { is_expected.to eq(true) } | ||
end | ||
end | ||
end |