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 specs in date_time_examples.rb

Dombi Attila8a077a196e62
diff --git a/spec/lib/api/v3/support/date_time_examples.rb b/spec/lib/api/v3/support/date_time_examples.rb
index e4e1d4161d5..4f425403866 100644
--- a/spec/lib/api/v3/support/date_time_examples.rb
+++ b/spec/lib/api/v3/support/date_time_examples.rb
@@ -34,13 +34,14 @@ shared_examples_for 'has ISO 8601 date only' do
end
it 'indicates date only as ISO 8601' do
- called_with_expected = false
- expect(::API::V3::Utilities::DateTimeFormatter).to receive(:format_date) do |actual, *_|
- called_with_expected = true if actual.eql? date
- end.at_least(:once)
+ allow(::API::V3::Utilities::DateTimeFormatter).to receive(:format_date)
- subject # we need to resolve the subject for calls to occur
- expect(called_with_expected).to be_truthy
+ subject
+
+ expect(::API::V3::Utilities::DateTimeFormatter)
+ .to have_received(:format_date)
+ .with(date, anything)
+ .at_least(:once)
end
end
@@ -50,30 +51,30 @@ shared_examples_for 'has UTC ISO 8601 date and time' do
end
it 'indicates date and time as ISO 8601' do
- called_with_expected = false
- expect(::API::V3::Utilities::DateTimeFormatter).to receive(:format_datetime) do |actual, *_|
- # ActiveSupport flaws :eql? we circumvent that by calling utc (which is equally valid)
- called_with_expected = true if actual.utc.eql? date.utc
- end.at_least(:once)
+ allow(::API::V3::Utilities::DateTimeFormatter).to receive(:format_datetime)
+
+ subject
- subject # we need to resolve the subject for calls to occur
- expect(called_with_expected).to be_truthy
+ expect(::API::V3::Utilities::DateTimeFormatter)
+ .to have_received(:format_datetime)
+ .with(date.utc, anything)
+ .at_least(:once)
end
end
-shared_examples_for 'has ISO 8601 hours only' do
+shared_examples_for 'has ISO 8601 duration' do
it 'exists' do
expect(subject).to have_json_path(json_path)
end
- it 'indicates date and time as ISO 8601' do
- called_with_expected = false
- expect(::API::V3::Utilities::DateTimeFormatter).to receive(:format_duration_from_hours) do |actual, *_|
- # ActiveSupport flaws :eql? we circumvent that by calling utc (which is equally valid)
- called_with_expected = true if actual.eql? hours
- end.at_least(:once)
+ it 'indicates duration as ISO 8601' do
+ allow(::API::V3::Utilities::DateTimeFormatter).to receive(:format_duration_from_hours)
+
+ subject
- subject # we need to resolve the subject for calls to occur
- expect(called_with_expected).to be_truthy
+ expect(::API::V3::Utilities::DateTimeFormatter)
+ .to have_received(:format_duration_from_hours)
+ .with(duration, anything)
+ .at_least(:once)
end
end
diff --git a/spec/lib/api/v3/support/property_examples.rb b/spec/lib/api/v3/support/property_examples.rb
index b3152d33520..4783da54d88 100644
--- a/spec/lib/api/v3/support/property_examples.rb
+++ b/spec/lib/api/v3/support/property_examples.rb
@@ -56,9 +56,9 @@ shared_examples_for 'datetime property' do |name|
end
end
-shared_examples_for 'hours property' do |name|
- it_behaves_like 'has ISO 8601 hours only' do
+shared_examples_for 'duration property' do |name|
+ it_behaves_like 'has ISO 8601 duration' do
let(:json_path) { name.to_s }
- let(:hours) { value }
+ let(:duration) { value }
end
end
diff --git a/spec/lib/api/v3/user_preferences/notification_setting_representer_rendering_spec.rb b/spec/lib/api/v3/user_preferences/notification_setting_representer_rendering_spec.rb
index 01f36281d96..4439dfa0a79 100644
--- a/spec/lib/api/v3/user_preferences/notification_setting_representer_rendering_spec.rb
+++ b/spec/lib/api/v3/user_preferences/notification_setting_representer_rendering_spec.rb
@@ -71,7 +71,7 @@ describe ::API::V3::UserPreferences::NotificationSettingRepresenter, 'rendering'
NotificationSetting.all_settings.each do |property|
if property.in?(NotificationSetting.duration_settings)
- it_behaves_like 'hours property', property.to_s.camelize(:lower) do
+ it_behaves_like 'duration property', property.to_s.camelize(:lower) do
let(:value) { notification_setting.send property }
end
else