From b5c40619be97768cc8537c525614a1eedc1e5892 Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Sat, 16 Apr 2022 03:50:28 +0200 Subject: [PATCH] Add tests for `Retrospring::Version` --- spec/lib/version_spec.rb | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 spec/lib/version_spec.rb diff --git a/spec/lib/version_spec.rb b/spec/lib/version_spec.rb new file mode 100644 index 00000000..8d94b627 --- /dev/null +++ b/spec/lib/version_spec.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +require "version" + +RSpec.describe Retrospring::Version do + before(:each) do + allow(Retrospring::Version).to receive(:year) { 1984 } + allow(Retrospring::Version).to receive(:month) { 1 } + allow(Retrospring::Version).to receive(:day) { 1 } + allow(Retrospring::Version).to receive(:patch) { 0 } + end + + describe "#to_s" do + context "without suffix" do + it "should return the correct version string" do + expect(Retrospring::Version.to_s).to eq("1984.0101.0") + end + end + + context "with suffix" do + before(:each) do + allow(Retrospring::Version).to receive(:suffix) { "+shutdown" } + end + + it "should return the correct version string" do + expect(Retrospring::Version.to_s).to eq("1984.0101.0+shutdown") + end + end + end + + describe "#to_a" do + it "should return the correct version as array" do + expect(Retrospring::Version.to_a).to eq(["1984", "0101", "0"]) + end + end +end