Skip to content

Commit

Permalink
Tests reliying in Hash#inspect are fixed for ruby 3.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
AlfonsoUceda committed Nov 12, 2024
1 parent 88ceb32 commit a67a273
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
19 changes: 16 additions & 3 deletions test/concept_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,24 @@ class ConceptTest < Minitest::Spec

describe "#cell (in state)" do
it { assert_instance_of Record::Cell, Cell::Concept.cell("record/cell", nil, context: { controller: Object }).cell("record/cell", nil) }
it { assert_equal "A Tribute To Rancid, with 24 songs! [{:controller=>Object}]", Cell::Concept.cell("record/cell", nil, context: { controller: Object }).concept("record/cell", nil, tracks: 24).(:description) }
it do
result = Cell::Concept.cell("record/cell", nil, context: { controller: Object }).concept("record/cell", nil, tracks: 24).(:description)

if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.4.0')
assert_equal "A Tribute To Rancid, with 24 songs! [{:controller=>Object}]", result
else
assert_equal "A Tribute To Rancid, with 24 songs! [{controller: Object}]", result
end
end

it do
assert_equal "A Tribute To Rancid, with 24 songs! [{:controller=>Object}]A Tribute To Rancid, with 24 songs! [{:controller=>Object}]",
Cell::Concept.cell("record/cell", nil, context: { controller: Object }).concept("record/cell", collection: [1,2], tracks: 24).(:description)
result = Cell::Concept.cell("record/cell", nil, context: { controller: Object }).concept("record/cell", collection: [1,2], tracks: 24).(:description)

if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.4.0')
assert_equal "A Tribute To Rancid, with 24 songs! [{:controller=>Object}]A Tribute To Rancid, with 24 songs! [{:controller=>Object}]", result
else
assert_equal "A Tribute To Rancid, with 24 songs! [{controller: Object}]A Tribute To Rancid, with 24 songs! [{controller: Object}]", result
end
end
end
end
7 changes: 6 additions & 1 deletion test/layout_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ class LayoutCell < Cell::ViewModel
class ExternalLayoutTest < Minitest::Spec
it do
result = Comment::ShowCell.new(nil, layout: Comment::LayoutCell, context: { beer: true }).()
assert_equal "$layout.erb{$show.erb, {:beer=>true}\n$show.erb, {:beer=>true}\n, {:beer=>true}}\n", result

if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.4.0')
assert_equal "$layout.erb{$show.erb, {:beer=>true}\n$show.erb, {:beer=>true}\n, {:beer=>true}}\n", result
else
assert_equal "$layout.erb{$show.erb, {beer: true}\n$show.erb, {beer: true}\n, {beer: true}}\n", result
end
end

# collection :layout
Expand Down
17 changes: 15 additions & 2 deletions test/public_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,15 @@ class Songs < Cell::Concept
end

# ViewModel.cell(collection: []) passes generic options to cell.
it { assert_equal "[Object, {:genre=>\"Metal\", :context=>{:ready=>true}}][Module, {:genre=>\"Metal\", :context=>{:ready=>true}}]", Cell::ViewModel.cell("public_test/song", collection: [Object, Module], genre: 'Metal', context: { ready: true }).to_s }
it do
result = Cell::ViewModel.cell("public_test/song", collection: [Object, Module], genre: 'Metal', context: { ready: true }).to_s

if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.4.0')
assert_equal "[Object, {:genre=>\"Metal\", :context=>{:ready=>true}}][Module, {:genre=>\"Metal\", :context=>{:ready=>true}}]", result
else
assert_equal "[Object, {genre: \"Metal\", context: {ready: true}}][Module, {genre: \"Metal\", context: {ready: true}}]", result
end
end

# ViewModel.cell(collection: [], method: :detail) invokes #detail instead of #show.
# TODO: remove in 5.0.
Expand All @@ -65,7 +73,12 @@ class Songs < Cell::Concept
it do
options = { genre: "Fusion", collection: [Object] }
Cell::ViewModel.cell("public_test/song", options).()
assert_equal "{:genre=>\"Fusion\", :collection=>[Object]}", options.to_s

if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.4.0')
assert_equal "{:genre=>\"Fusion\", :collection=>[Object]}", options.to_s
else
assert_equal "{genre: \"Fusion\", collection: [Object]}", options.to_s
end
end

# cell(collection: []).join captures return value and joins it for you.
Expand Down

0 comments on commit a67a273

Please sign in to comment.