ice-cube-ruby / ice_cube

Ruby Date Recurrence Library - Allows easy creation of recurrence rules and fast querying
MIT License
2.41k stars 358 forks source link

Fix some failing round trips #536

Open boutil opened 1 year ago

boutil commented 1 year ago

In some Debian environment two of the round trips in to_yaml_spec.rb were failing (those using .month_of_year and day_of_year. Applying the same fix as the one used in 4bf17183be02f8efe17b98c401af40db48a931dc to fix #483 solved the issue.

This patch proposes that corresponding change to /spec/examples/to_yaml_spec.rb.

adfoster-r7 commented 8 months ago

This fixes one of the tests for me :+1:

Before

rspec ./spec/examples/to_yaml_spec.rb:80 # IceCube::Schedule to_yaml should be able to make a round-trip to YAML with .day_of_year
rspec ./spec/examples/to_yaml_spec.rb:114 # IceCube::Schedule to_yaml should be able to make a round-trip to YAML with .month_of_year
rspec ./spec/examples/to_yaml_spec.rb:136 # IceCube::Schedule to_yaml should be able to make a round-trip to YAML whilst preserving exception rules

After

rspec ./spec/examples/occurrence_spec.rb:27 # IceCube::Occurrence to_s accepts a format option to comply with ActiveSupport
rspec ./spec/examples/to_yaml_spec.rb:136 # IceCube::Schedule to_yaml should be able to make a round-trip to YAML whilst preserving exception rules

Remaining failures:

Failures:

  1) IceCube::Occurrence to_s accepts a format option to comply with ActiveSupport
     Failure/Error: expect(occurrence.to_s(:short)).to eq time_now.to_s(:short)

     ArgumentError:
       wrong number of arguments (given 1, expected 0)
     # /Users/user/.rvm/gems/ruby-3.0.6/gems/activesupport-7.1.3/lib/active_support/time_with_zone.rb:200:in `to_s'
     # ./spec/examples/occurrence_spec.rb:31:in `block (3 levels) in <top (required)>'
     # ./spec/spec_helper.rb:76:in `block (3 levels) in <top (required)>'
     # ./spec/spec_helper.rb:75:in `block (2 levels) in <top (required)>'

  2) IceCube::Schedule to_yaml should be able to make a round-trip to YAML whilst preserving exception rules
     Failure/Error: expect(returned_schedule.first(10).map { |r| r.to_s }).to eq(original_schedule.first(10).map { |r| r.to_s })

       expected: ["2024-02-26 22:54:37 +0000", "2024-03-04 22:54:37 +0000", "2024-03-11 22:54:37 +0000", "2024-03-18 2...54:37 +0100", "2024-04-15 22:54:37 +0100", "2024-04-22 22:54:37 +0100", "2024-04-29 22:54:37 +0100"]
            got: ["2024-02-26 22:54:37 +0000", "2024-03-04 22:54:37 +0000", "2024-03-11 22:54:37 +0000", "2024-03-18 2...54:37 +0000", "2024-04-15 22:54:37 +0000", "2024-04-22 22:54:37 +0000", "2024-04-29 22:54:37 +0000"]

       (compared using ==)
     # ./spec/examples/to_yaml_spec.rb:145:in `block (2 levels) in <module:IceCube>'
     # ./spec/spec_helper.rb:76:in `block (3 levels) in <top (required)>'
     # ./spec/spec_helper.rb:75:in `block (2 levels) in <top (required)>'

Finished in 1.18 seconds (files took 0.62841 seconds to load)
1114 examples, 2 failures

The first test failure is fixed by https://github.com/ice-cube-ruby/ice_cube/pull/528 - but it looks like the second test is still failing 🤔

adfoster-r7 commented 8 months ago

Looks like following your pattern for the final remaining test worked for my env :+1:

diff --git a/spec/examples/to_yaml_spec.rb b/spec/examples/to_yaml_spec.rb
index 7166110..913cd05 100644
--- a/spec/examples/to_yaml_spec.rb
+++ b/spec/examples/to_yaml_spec.rb
@@ -134,7 +134,7 @@ module IceCube
     end

     it "should be able to make a round-trip to YAML whilst preserving exception rules" do
-      original_schedule = Schedule.new(Time.now)
+      original_schedule = Schedule.new(Time.zone.now)
       original_schedule.add_recurrence_rule Rule.daily.day(:monday, :wednesday)
       original_schedule.add_exception_rule Rule.daily.day(:wednesday)