Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }

gem "appraisal"
gem "childprocess"
gem "climate_control"
gem "pry-byebug", platform: :mri
gem "pry-nav", platform: :jruby
gem "rake"
Expand Down
1 change: 1 addition & 0 deletions gemfiles/no_rails_rspec_gte_3_10.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ source "https://rubygems.org"

gem "appraisal"
gem "childprocess"
gem "climate_control"
gem "pry-byebug", platform: :mri
gem "pry-nav", platform: :jruby
gem "rake"
Expand Down
4 changes: 3 additions & 1 deletion gemfiles/no_rails_rspec_gte_3_10.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ GEM
attr_extras (6.2.4)
byebug (11.1.3)
childprocess (4.0.0)
climate_control (1.0.0)
coderay (1.1.3)
diff-lcs (1.4.4)
method_source (1.0.0)
Expand Down Expand Up @@ -71,6 +72,7 @@ PLATFORMS
DEPENDENCIES
appraisal
childprocess
climate_control
pry-byebug
pry-nav
rake
Expand All @@ -80,4 +82,4 @@ DEPENDENCIES
warnings_logger

BUNDLED WITH
2.1.4
2.2.16
1 change: 1 addition & 0 deletions gemfiles/no_rails_rspec_lt_3_10.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ source "https://rubygems.org"

gem "appraisal"
gem "childprocess"
gem "climate_control"
gem "pry-byebug", platform: :mri
gem "pry-nav", platform: :jruby
gem "rake"
Expand Down
4 changes: 3 additions & 1 deletion gemfiles/no_rails_rspec_lt_3_10.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ GEM
attr_extras (6.2.4)
byebug (11.1.3)
childprocess (4.0.0)
climate_control (1.0.0)
coderay (1.1.3)
diff-lcs (1.4.4)
method_source (1.0.0)
Expand Down Expand Up @@ -71,6 +72,7 @@ PLATFORMS
DEPENDENCIES
appraisal
childprocess
climate_control
pry-byebug
pry-nav
rake
Expand All @@ -80,4 +82,4 @@ DEPENDENCIES
warnings_logger

BUNDLED WITH
2.1.4
2.2.16
1 change: 1 addition & 0 deletions gemfiles/rails_5_0_rspec_gte_3_10.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ source "https://rubygems.org"

gem "appraisal"
gem "childprocess"
gem "climate_control"
gem "pry-byebug", platform: :mri
gem "pry-nav", platform: :jruby
gem "rake"
Expand Down
1 change: 1 addition & 0 deletions gemfiles/rails_5_0_rspec_lt_3_10.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ source "https://rubygems.org"

gem "appraisal"
gem "childprocess"
gem "climate_control"
gem "pry-byebug", platform: :mri
gem "pry-nav", platform: :jruby
gem "rake"
Expand Down
1 change: 1 addition & 0 deletions gemfiles/rails_5_1_rspec_gte_3_10.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ source "https://rubygems.org"

gem "appraisal"
gem "childprocess"
gem "climate_control"
gem "pry-byebug", platform: :mri
gem "pry-nav", platform: :jruby
gem "rake"
Expand Down
1 change: 1 addition & 0 deletions gemfiles/rails_5_1_rspec_lt_3_10.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ source "https://rubygems.org"

gem "appraisal"
gem "childprocess"
gem "climate_control"
gem "pry-byebug", platform: :mri
gem "pry-nav", platform: :jruby
gem "rake"
Expand Down
1 change: 1 addition & 0 deletions gemfiles/rails_5_2_rspec_gte_3_10.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ source "https://rubygems.org"

gem "appraisal"
gem "childprocess"
gem "climate_control"
gem "pry-byebug", platform: :mri
gem "pry-nav", platform: :jruby
gem "rake"
Expand Down
1 change: 1 addition & 0 deletions gemfiles/rails_5_2_rspec_lt_3_10.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ source "https://rubygems.org"

gem "appraisal"
gem "childprocess"
gem "climate_control"
gem "pry-byebug", platform: :mri
gem "pry-nav", platform: :jruby
gem "rake"
Expand Down
1 change: 1 addition & 0 deletions gemfiles/rails_6_0_rspec_gte_3_10.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ source "https://rubygems.org"

gem "appraisal"
gem "childprocess"
gem "climate_control"
gem "pry-byebug", platform: :mri
gem "pry-nav", platform: :jruby
gem "rake"
Expand Down
2 changes: 2 additions & 0 deletions gemfiles/rails_6_0_rspec_gte_3_10.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ GEM
builder (3.2.4)
byebug (11.1.3)
childprocess (4.0.0)
climate_control (1.0.0)
coderay (1.1.3)
concurrent-ruby (1.1.7)
crass (1.0.6)
Expand Down Expand Up @@ -139,6 +140,7 @@ DEPENDENCIES
activerecord-jdbcsqlite3-adapter
appraisal
childprocess
climate_control
jdbc-sqlite3
pry-byebug
pry-nav
Expand Down
1 change: 1 addition & 0 deletions gemfiles/rails_6_0_rspec_lt_3_10.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ source "https://rubygems.org"

gem "appraisal"
gem "childprocess"
gem "climate_control"
gem "pry-byebug", platform: :mri
gem "pry-nav", platform: :jruby
gem "rake"
Expand Down
4 changes: 3 additions & 1 deletion gemfiles/rails_6_0_rspec_lt_3_10.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ GEM
builder (3.2.4)
byebug (11.1.3)
childprocess (4.0.0)
climate_control (1.0.0)
coderay (1.1.3)
concurrent-ruby (1.1.7)
crass (1.0.6)
Expand Down Expand Up @@ -139,6 +140,7 @@ DEPENDENCIES
activerecord-jdbcsqlite3-adapter
appraisal
childprocess
climate_control
jdbc-sqlite3
pry-byebug
pry-nav
Expand All @@ -152,4 +154,4 @@ DEPENDENCIES
warnings_logger

BUNDLED WITH
2.1.4
2.2.16
46 changes: 43 additions & 3 deletions lib/super_diff/object_inspection/inspectors/time_like.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,55 @@ def self.applies_to?(value)
SuperDiff.time_like?(value)
end

TIME_FORMAT = "%Y-%m-%d %H:%M:%S.%3N %Z %:z".freeze

protected

def inspection_tree
InspectionTree.new do
add_text do |time|
"#{time.strftime(TIME_FORMAT)} (#{time.class})"
"#<#{time.class} "
end

when_singleline do
add_text do |time|
time.strftime("%Y-%m-%d %H:%M:%S") +
(time.subsec == 0 ? "" : "+#{time.subsec.inspect}") +
" " + time.strftime("%:z") +
(time.zone ? " (#{time.zone})" : "")
end
end

when_multiline do
add_text "{"

nested do |time|
add_break " "

insert_separated_list(
[
:year,
:month,
:day,
:hour,
:min,
:sec,
:subsec,
:zone,
:utc_offset
],
separator: ","
) do |name|
add_text name.to_s
add_text ": "
add_inspection_of time.public_send(name)
end
end

add_break

add_text "}"
end

add_text ">"
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/super_diff/operation_tree_builders/defaults.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module SuperDiff
module OperationTreeBuilders
DEFAULTS = [Array, Hash, CustomObject].freeze
DEFAULTS = [Array, Hash, TimeLike, CustomObject].freeze
end
end
4 changes: 2 additions & 2 deletions lib/super_diff/operation_tree_builders/time_like.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ def attribute_names
"hour",
"min",
"sec",
"nsec",
"subsec",
"zone",
"gmt_offset",
"utc_offset",
]

# If timezones are different, also show a normalized timestamp at the
Expand Down
66 changes: 39 additions & 27 deletions spec/integration/rspec/eq_matcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,12 @@
expectation: proc {
line do
plain %|Expected |
actual %|2011-12-13 14:15:16.000 UTC +00:00 (Time)|
plain %| to eq |
expected %|2011-12-13 14:15:16.500 UTC +00:00 (Time)|
plain %|.|
actual %|#<Time 2011-12-13 14:15:16 +00:00 (UTC)>|
end

line do
plain %| to eq |
expected %|#<Time 2011-12-13 14:15:16+(1/2) +00:00 (UTC)>|
end
},
diff: proc {
Expand All @@ -202,10 +204,10 @@
plain_line " hour: 14,"
plain_line " min: 15,"
plain_line " sec: 16,"
expected_line "- nsec: 500000000,"
actual_line "+ nsec: 0,"
expected_line "- subsec: (1/2),"
actual_line "+ subsec: 0,"
plain_line " zone: \"UTC\","
plain_line " gmt_offset: 0"
plain_line " utc_offset: 0"
plain_line " }>"
},
)
Expand Down Expand Up @@ -234,12 +236,12 @@
expectation: proc {
line do
plain %| Expected |
actual %|2011-12-13 14:15:16.000 UTC +00:00 (Time)|
actual %|#<Time 2011-12-13 14:15:16 +00:00 (UTC)>|
end

line do
plain %|not to eq |
expected %|2011-12-13 14:15:16.000 UTC +00:00 (Time)|
expected %|#<Time 2011-12-13 14:15:16 +00:00 (UTC)>|
end
},
)
Expand Down Expand Up @@ -270,31 +272,41 @@
expectation: proc {
line do
plain %|Expected |
actual %|2011-12-13 14:15:16.000 UTC +00:00 (Time)|
actual %|#<Time 2011-12-13 14:15:16 +00:00 (UTC)>|
end

line do
plain %| to eq |
expected %|2011-12-13 16:15:16.000 CET +01:00 (ActiveSupport::TimeWithZone)|
expected %|#<ActiveSupport::TimeWithZone 2011-12-13 16:15:16 +01:00 (CET)>|
end
},
diff: proc {
plain_line " #<ActiveSupport::TimeWithZone {"
plain_line " year: 2011,"
plain_line " month: 12,"
plain_line " day: 13,"
expected_line "- hour: 16,"
actual_line "+ hour: 14,"
plain_line " min: 15,"
plain_line " sec: 16,"
plain_line " nsec: 0,"
expected_line "- zone: \"CET\","
actual_line "+ zone: \"UTC\","
expected_line "- gmt_offset: 3600,"
actual_line "+ gmt_offset: 0,"
expected_line "- utc: 2011-12-13 15:15:16.000 UTC +00:00 (Time)"
actual_line "+ utc: 2011-12-13 14:15:16.000 UTC +00:00 (Time)"
plain_line " }>"
plain_line %| #<ActiveSupport::TimeWithZone {|
plain_line %| year: 2011,|
plain_line %| month: 12,|
plain_line %| day: 13,|
expected_line %|- hour: 16,|
actual_line %|+ hour: 14,|
plain_line %| min: 15,|
plain_line %| sec: 16,|
plain_line %| subsec: 0,|
expected_line %|- zone: \"CET\",|
actual_line %|+ zone: \"UTC\",|
expected_line %|- utc_offset: 3600,|
actual_line %|+ utc_offset: 0,|
plain_line %| utc: #<Time {|
plain_line %| year: 2011,|
plain_line %| month: 12,|
plain_line %| day: 13,|
expected_line %|- hour: 15,|
actual_line %|+ hour: 14,|
plain_line %| min: 15,|
plain_line %| sec: 16,|
plain_line %| subsec: 0,|
plain_line %| zone: "UTC",|
plain_line %| utc_offset: 0|
plain_line %| }>|
plain_line %| }>|
},
)

Expand Down
12 changes: 11 additions & 1 deletion spec/integration/rspec/have_attributes_matcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,17 @@
expected_line %|- data: #<a hash including (|
expected_line %|- active: true|
expected_line %|- )>,|
expected_line %|- created_at: #<a value within 1 of 2020-04-09 00:00:00.000 UTC +00:00 (Time)>|
expected_line %|- created_at: #<a value within 1 of #<Time {|
expected_line %|- year: 2020,|
expected_line %|- month: 4,|
expected_line %|- day: 9,|
expected_line %|- hour: 0,|
expected_line %|- min: 0,|
expected_line %|- sec: 0,|
expected_line %|- subsec: 0,|
expected_line %|- zone: "UTC",|
expected_line %|- utc_offset: 0|
expected_line %|- }>>|
plain_line %| }|
},
)
Expand Down
4 changes: 3 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require "pp"

begin
require "pry-byebug"
rescue LoadError
Expand All @@ -8,7 +10,7 @@
rescue LoadError
end

require "pp"
require "climate_control"

#---

Expand Down
Loading