Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

refactor: make tests more expressive and explicit

Christophe Bliardf1ea26c38113
diff --git a/spec/models/relation_spec.rb b/spec/models/relation_spec.rb
index 4b28413bb24..e68e4bb3c09 100644
--- a/spec/models/relation_spec.rb
+++ b/spec/models/relation_spec.rb
@@ -38,24 +38,10 @@ RSpec.describe Relation do
let(:relation) { build(:relation, from:, to:, relation_type: type) }
it "validates lag numericality" do
- relation.lag = nil
- expect(relation).to be_valid
- relation.lag = -1
- expect(relation).to be_valid
- relation.lag = 2_000
- expect(relation).to be_valid
- relation.lag = -2_000
- expect(relation).to be_valid
-
- relation.lag = 2_001
- expect(relation).not_to be_valid
- expect(relation.errors[:lag])
- .to eq(["must be less than or equal to #{Relation::MAX_LAG}."])
-
- relation.lag = -2_001
- expect(relation).not_to be_valid
- expect(relation.errors[:lag])
- .to eq(["must be greater than or equal to #{Relation::MIN_LAG}."])
+ expect(relation).to validate_numericality_of(:lag)
+ .is_greater_than_or_equal_to(Relation::MIN_LAG)
+ .is_less_than_or_equal_to(Relation::MAX_LAG)
+ .allow_nil
end
it "validates relation uniqueness on both from_id and to_id" do
diff --git a/spec/services/work_packages/shared/all_days_spec.rb b/spec/services/work_packages/shared/all_days_spec.rb
index 2b47a526d78..229ac27ee11 100644
--- a/spec/services/work_packages/shared/all_days_spec.rb
+++ b/spec/services/work_packages/shared/all_days_spec.rb
@@ -44,7 +44,7 @@ RSpec.describe WorkPackages::Shared::AllDays do
end
end
- context "with weekend days (Saturday and Sunday)", :weekend_saturday_sunday do
+ context "with Saturday and Sunday being non-working days", :weekend_saturday_sunday do
it "considers all days as working days and returns the number of days between two dates, inclusive" do
expect(subject.duration(sunday_2022_07_31, sunday_2022_07_31 + 6)).to eq(7)
expect(subject.duration(sunday_2022_07_31, sunday_2022_07_31 + 50)).to eq(51)
@@ -94,7 +94,7 @@ RSpec.describe WorkPackages::Shared::AllDays do
expect(subject.start_date(sunday_2022_07_31, nil)).to be_nil
end
- context "with weekend days (Saturday and Sunday)", :weekend_saturday_sunday do
+ context "with Saturday and Sunday being non-working days", :weekend_saturday_sunday do
include_examples "start_date", due_date: sunday_2022_07_31, duration: 1, expected: sunday_2022_07_31
include_examples "start_date", due_date: sunday_2022_07_31, duration: 5, expected: sunday_2022_07_31 - 4.days
include_examples "start_date", due_date: sunday_2022_07_31, duration: 10, expected: sunday_2022_07_31 - 9.days
@@ -127,7 +127,7 @@ RSpec.describe WorkPackages::Shared::AllDays do
expect(subject.due_date(sunday_2022_07_31, nil)).to be_nil
end
- context "with weekend days (Saturday and Sunday)", :weekend_saturday_sunday do
+ context "with Saturday and Sunday being non-working days", :weekend_saturday_sunday do
include_examples "due_date", start_date: sunday_2022_07_31, duration: 1, expected: sunday_2022_07_31
include_examples "due_date", start_date: sunday_2022_07_31, duration: 5, expected: sunday_2022_07_31 + 4.days
include_examples "due_date", start_date: sunday_2022_07_31, duration: 10, expected: sunday_2022_07_31 + 9.days
@@ -148,7 +148,7 @@ RSpec.describe WorkPackages::Shared::AllDays do
expect(subject.soonest_working_day(nil)).to be_nil
end
- context "with weekend days (Saturday and Sunday)", :weekend_saturday_sunday do
+ context "with Saturday and Sunday being non-working days", :weekend_saturday_sunday do
it "returns the given day" do
expect(subject.soonest_working_day(sunday_2022_07_31)).to eq(sunday_2022_07_31)
end
diff --git a/spec/services/work_packages/shared/shared_examples_days.rb b/spec/services/work_packages/shared/shared_examples_days.rb
index 49549ca521c..084fd6159c3 100644
--- a/spec/services/work_packages/shared/shared_examples_days.rb
+++ b/spec/services/work_packages/shared/shared_examples_days.rb
@@ -136,7 +136,7 @@ RSpec.shared_examples "lag computation excluding non-working days" do
end
end
- context "with weekend days (Saturday and Sunday)", :weekend_saturday_sunday do
+ context "with Saturday and Sunday being non-working days", :weekend_saturday_sunday do
include_examples "it returns lag", 0, sunday_2022_07_31, monday_2022_08_01
include_examples "it returns lag", 4, sunday_2022_07_31, Date.new(2022, 8, 5) # Friday
include_examples "it returns lag", 5, sunday_2022_07_31, Date.new(2022, 8, 6) # Saturday
@@ -209,7 +209,7 @@ RSpec.shared_examples "add lag to a date" do
.not_to raise_error
end
- context "with weekend days (Saturday and Sunday)", :weekend_saturday_sunday do
+ context "with Saturday and Sunday being non-working days", :weekend_saturday_sunday do
include_examples "it adds lag", date: saturday_2022_07_30, lag: 0, expected_result: sunday_2022_07_31
include_examples "it adds lag", date: saturday_2022_07_30, lag: 1, expected_result: Date.new(2022, 8, 2)
include_examples "it adds lag", date: saturday_2022_07_30, lag: -1, expected_result: Date.new(2022, 7, 29) # previous Friday
diff --git a/spec/services/work_packages/shared/working_days_spec.rb b/spec/services/work_packages/shared/working_days_spec.rb
index 4224854dd24..cb1edbe490f 100644
--- a/spec/services/work_packages/shared/working_days_spec.rb
+++ b/spec/services/work_packages/shared/working_days_spec.rb
@@ -52,7 +52,7 @@ RSpec.describe WorkPackages::Shared::WorkingDays do
end
end
- context "with weekend days (Saturday and Sunday)", :weekend_saturday_sunday do
+ context "with Saturday and Sunday being non-working days", :weekend_saturday_sunday do
include_examples "it returns duration", 0, sunday_2022_07_31, sunday_2022_07_31
include_examples "it returns duration", 5, sunday_2022_07_31, Date.new(2022, 8, 5)
include_examples "it returns duration", 5, sunday_2022_07_31, Date.new(2022, 8, 6)
@@ -124,7 +124,7 @@ RSpec.describe WorkPackages::Shared::WorkingDays do
end
end
- context "with weekend days (Saturday and Sunday)", :weekend_saturday_sunday do
+ context "with Saturday and Sunday being non-working days", :weekend_saturday_sunday do
include_examples "start_date", due_date: monday_2022_08_01, duration: 1, expected: monday_2022_08_01
include_examples "start_date", due_date: monday_2022_08_01, duration: 5, expected: monday_2022_08_01 - 6.days
include_examples "start_date", due_date: wednesday_2022_08_03, duration: 10, expected: wednesday_2022_08_03 - 13.days
@@ -168,7 +168,7 @@ RSpec.describe WorkPackages::Shared::WorkingDays do
end
end
- context "with weekend days (Saturday and Sunday)", :weekend_saturday_sunday do
+ context "with Saturday and Sunday being non-working days", :weekend_saturday_sunday do
include_examples "due_date", start_date: monday_2022_08_01, duration: 1, expected: monday_2022_08_01
include_examples "due_date", start_date: monday_2022_08_01, duration: 5, expected: monday_2022_08_01 + 4.days
include_examples "due_date", start_date: wednesday_2022_08_03, duration: 10, expected: wednesday_2022_08_03 + 13.days
@@ -194,7 +194,7 @@ RSpec.describe WorkPackages::Shared::WorkingDays do
expect(subject.soonest_working_day(nil)).to be_nil
end
- context "with weekend days (Saturday and Sunday)", :weekend_saturday_sunday do
+ context "with Saturday and Sunday being non-working days", :weekend_saturday_sunday do
include_examples "soonest working day", date: friday_2022_07_29, expected: friday_2022_07_29
include_examples "soonest working day", date: saturday_2022_07_30, expected: monday_2022_08_01
include_examples "soonest working day", date: sunday_2022_07_31, expected: monday_2022_08_01