Skip to content

Commit

Permalink
Merge pull request trailblazer#486 from trailblazer/upMinitest
Browse files Browse the repository at this point in the history
update minitest syntax
  • Loading branch information
seuros authored Jul 21, 2020
2 parents e29d693 + 4501202 commit 7b2a52d
Show file tree
Hide file tree
Showing 15 changed files with 136 additions and 146 deletions.
18 changes: 4 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
language: ruby
before_install: gem install bundler
rvm:
#- ruby-head
- 2.5.1
- 2.4.4
- 2.3.7
- 2.2.10
- 2.7
- 2.6
- 2.5

cache: bundler

matrix:
fast_finish: true
allow_failures:
- rvm: ruby-head

before_install:
- gem update --system
- gem install bundler
16 changes: 8 additions & 8 deletions test/builder_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,28 @@ class EvergreenCell < SongCell
end

# the original class is used when no builder matches.
it { SongCell.(Song.new("Nation States"), {}).must_be_instance_of SongCell }
it { _(SongCell.(Song.new("Nation States"), {})).must_be_instance_of SongCell }

it do
cell = SongCell.(Hit.new("New York"), {})
cell.must_be_instance_of HitCell
cell.options.must_equal({})
_(cell).must_be_instance_of HitCell
_(cell.options).must_equal({})
end

it do
cell = SongCell.(Song.new("San Francisco"), evergreen: true)
cell.must_be_instance_of EvergreenCell
cell.options.must_equal({evergreen:true})
_(cell).must_be_instance_of EvergreenCell
_(cell.options).must_equal({evergreen:true})
end

# without arguments.
it { SongCell.(Hit.new("Frenzy")).must_be_instance_of HitCell }
it { _(SongCell.(Hit.new("Frenzy"))).must_be_instance_of HitCell }

# with collection.
it { SongCell.(collection: [Song.new("Nation States"), Hit.new("New York")]).().must_equal "* Nation States* **New York**" }
it { _(SongCell.(collection: [Song.new("Nation States"), Hit.new("New York")]).()).must_equal "* Nation States* **New York**" }

# with Concept
class Track < Cell::Concept
end
it { Track.().must_be_instance_of Track }
it { _(Track.()).must_be_instance_of Track }
end
4 changes: 2 additions & 2 deletions test/cache_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class Index < Cell::ViewModel
end

it do
Index.new(1).().must_equal("1")
Index.new(2).().must_equal("1")
_(Index.new(1).()).must_equal("1")
_(Index.new(2).()).must_equal("1")
end
end

4 changes: 2 additions & 2 deletions test/cell_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def show_with_block(&block)
end

# #options
it { SongCell.new(nil, genre: "Punkrock").send(:options)[:genre].must_equal "Punkrock" }
it { _(SongCell.new(nil, genre: "Punkrock").send(:options)[:genre]).must_equal "Punkrock" }

# #block
it { SongCell.new(nil, genre: "Punkrock").(:show_with_block) { "hello" }.must_equal "<b>hello</b>\n" }
it { _(SongCell.new(nil, genre: "Punkrock").(:show_with_block) { "hello" }).must_equal "<b>hello</b>\n" }
end
30 changes: 15 additions & 15 deletions test/concept_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,40 +48,40 @@ class Song < ::Cell::Concept

class ConceptTest < MiniTest::Spec
describe "::controller_path" do
it { Record::Cell.new.class.controller_path.must_equal "record" }
it { Record::Cell::Song.new.class.controller_path.must_equal "record/song" }
it { Record::Cells::Cell.new.class.controller_path.must_equal "record/cells" }
it { Record::Cells::Cell::Song.new.class.controller_path.must_equal "record/cells/song" }
it { _(Record::Cell.new.class.controller_path).must_equal "record" }
it { _(Record::Cell::Song.new.class.controller_path).must_equal "record/song" }
it { _(Record::Cells::Cell.new.class.controller_path).must_equal "record/cells" }
it { _(Record::Cells::Cell::Song.new.class.controller_path).must_equal "record/cells/song" }
end


describe "#_prefixes" do
it { Record::Cell.new._prefixes.must_equal ["test/fixtures/concepts/record/views"] }
it { Record::Cell::Song.new._prefixes.must_equal ["test/fixtures/concepts/record/song/views", "test/fixtures/concepts/record/views"] }
it { Record::Cell::Hit.new._prefixes.must_equal ["test/fixtures/concepts/record/hit/views", "test/fixtures/concepts/record/views"] } # with inherit_views.
it { _(Record::Cell.new._prefixes).must_equal ["test/fixtures/concepts/record/views"] }
it { _(Record::Cell::Song.new._prefixes).must_equal ["test/fixtures/concepts/record/song/views", "test/fixtures/concepts/record/views"] }
it { _(Record::Cell::Hit.new._prefixes).must_equal ["test/fixtures/concepts/record/hit/views", "test/fixtures/concepts/record/views"] } # with inherit_views.
end

it { Record::Cell.new("Wayne").call(:show).must_equal "Party on, Wayne!" }
it { _(Record::Cell.new("Wayne").call(:show)).must_equal "Party on, Wayne!" }


describe "::cell" do
it { Cell::Concept.cell("record/cell").must_be_instance_of( Record::Cell) }
it { Cell::Concept.cell("record/cell/song").must_be_instance_of Record::Cell::Song }
it { _(Cell::Concept.cell("record/cell")).must_be_instance_of( Record::Cell) }
it { _(Cell::Concept.cell("record/cell/song")).must_be_instance_of Record::Cell::Song }
# cell("song", concept: "record/compilation") # record/compilation/cell/song
end

describe "#render" do
it { Cell::Concept.cell("record/cell/song").show.must_equal "Lalala" }
it { _(Cell::Concept.cell("record/cell/song").show).must_equal "Lalala" }
end

describe "#cell (in state)" do
# test with controller, but remove tests when we don't need it anymore.
it { Cell::Concept.cell("record/cell", nil, context: { controller: Object }).cell("record/cell", nil).must_be_instance_of Record::Cell }
it { Cell::Concept.cell("record/cell", nil, context: { controller: Object }).concept("record/cell", nil, tracks: 24).(:description).must_equal "A Tribute To Rancid, with 24 songs! [{:controller=>Object}]" }
it { _(Cell::Concept.cell("record/cell", nil, context: { controller: Object }).cell("record/cell", nil)).must_be_instance_of Record::Cell }
it { _(Cell::Concept.cell("record/cell", nil, context: { controller: Object }).concept("record/cell", nil, tracks: 24).(:description)).must_equal "A Tribute To Rancid, with 24 songs! [{:controller=>Object}]" }
# concept(.., collection: ..)
it do
Cell::Concept.cell("record/cell", nil, context: { controller: Object }).
concept("record/cell", collection: [1,2], tracks: 24).(:description).must_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)).must_equal "A Tribute To Rancid, with 24 songs! [{:controller=>Object}]A Tribute To Rancid, with 24 songs! [{:controller=>Object}]"
end
end
end
18 changes: 9 additions & 9 deletions test/context_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ def controller
let (:parent) { ParentCell.(model, admin: true, context: { user: user, controller: controller }) }

it do
parent.model.must_equal model
parent.controller.must_equal controller
parent.user.must_equal user
_(parent.model).must_equal model
_(parent.controller).must_equal controller
_(parent.user).must_equal user

# nested cell
child = parent.cell("context_test/parent", "")

child.model.must_equal ""
child.controller.must_equal controller
child.user.must_equal user
_(child.model).must_equal ""
_(child.controller).must_equal controller
_(child.user).must_equal user
end

# child can add to context
Expand All @@ -37,8 +37,8 @@ def controller
assert_nil(parent.context["is_child?"])

assert_nil(child.model)
child.controller.must_equal controller
child.user.must_equal user
child.context["is_child?"].must_equal true
_(child.controller).must_equal controller
_(child.user).must_equal user
_(child.context["is_child?"]).must_equal true
end
end
20 changes: 10 additions & 10 deletions test/inspect_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ def build_model

inspection_s = cell.inspect

inspection_s.must_match '#<Cell::ViewModel:'
inspection_s.must_match "@model=#{model_obj.inspect}"
inspection_s.must_match "@title=\"Title\""
inspection_s.must_match "@options=#{options.inspect}"
_(inspection_s).must_match '#<Cell::ViewModel:'
_(inspection_s).must_match "@model=#{model_obj.inspect}"
_(inspection_s).must_match "@title=\"Title\""
_(inspection_s).must_match "@options=#{options.inspect}"
end
it do
inspection_s = Cell::ViewModel.().inspect

inspection_s.must_match '#<Cell::ViewModel:'
inspection_s.must_match "@model=nil"
inspection_s.must_match "@options={}"
_(inspection_s).must_match '#<Cell::ViewModel:'
_(inspection_s).must_match "@model=nil"
_(inspection_s).must_match "@options={}"
end

# black list ivars
Expand All @@ -36,9 +36,9 @@ def build_model
cell.stub(:inspect_blacklist, ['model']) do
inspection_s = cell.inspect

inspection_s.must_match '#<Cell::ViewModel:'
inspection_s.must_match "@model=#<InspectTest::FakeModel:#{model_obj.object_id}>"
inspection_s.must_match "@options=#{options.inspect}"
_(inspection_s).must_match '#<Cell::ViewModel:'
_(inspection_s).must_match "@model=#<InspectTest::FakeModel:#{model_obj.object_id}>"
_(inspection_s).must_match "@options=#{options.inspect}"
end
end
end
14 changes: 7 additions & 7 deletions test/layout_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def show_with_layout
class LayoutTest < MiniTest::Spec
# render show.haml calling method.
# same context as content view as layout call method.
it { SongWithLayoutCell.new(nil).show.must_equal "Merry Xmas, <b>Papertiger</b>" }
it { _(SongWithLayoutCell.new(nil).show).must_equal "Merry Xmas, <b>Papertiger</b>\n" }

# raises exception when layout not found!

Expand All @@ -51,10 +51,10 @@ class LayoutTest < MiniTest::Spec
it { }

# with ::layout.
it { SongWithLayoutOnClassCell.new(nil).show.must_equal "Merry Xmas, <b>Papertiger</b>" }
it { _(SongWithLayoutOnClassCell.new(nil).show).must_equal "Merry Xmas, <b>Papertiger</b>\n" }

# with ::layout and :layout, :layout wins.
it { SongWithLayoutOnClassCell.new(nil).show_with_layout.must_equal "Happy Friday!" }
it { _(SongWithLayoutOnClassCell.new(nil).show_with_layout).must_equal "Happy Friday!" }
end

module Comment
Expand All @@ -74,15 +74,15 @@ class LayoutCell < Cell::ViewModel

class ExternalLayoutTest < Minitest::Spec
it do
Comment::ShowCell.new(nil, layout: Comment::LayoutCell, context: { beer: true }).
().must_equal "$layout.erb{$show.erb, {:beer=>true}$show.erb, {:beer=>true}, {:beer=>true}}
_(Comment::ShowCell.new(nil, layout: Comment::LayoutCell, context: { beer: true }).
()).must_equal "$layout.erb{$show.erb, {:beer=>true}\n$show.erb, {:beer=>true}\n, {:beer=>true}}
"
end

# collection :layout
it do
Cell::ViewModel.cell("comment/show", collection: [Object, Module], layout: Comment::LayoutCell).().
must_equal "$layout.erb{$show.erb, nil$show.erb, nil$show.erb, nil$show.erb, nil, nil}
_(Cell::ViewModel.cell("comment/show", collection: [Object, Module], layout: Comment::LayoutCell).()).
must_equal "$layout.erb{$show.erb, nil\n$show.erb, nil\n$show.erb, nil\n$show.erb, nil\n, nil}
"
end
end
12 changes: 6 additions & 6 deletions test/partial_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ class WithPartialAndManyViewPaths < WithPartial
self.view_paths << ['app/views']
end

it { WithPartial.new(nil).show.must_equal "I Am Wrong And I Am Right" }
it { WithPartial.new(nil).show_with_format.must_equal "<xml>I Am Wrong And I Am Right</xml>" }
it { WithPartial.new(nil).show_without_partial.must_equal "Adenosine Breakdown" }
it { _(WithPartial.new(nil).show).must_equal "I Am Wrong And I Am Right" }
it { _(WithPartial.new(nil).show_with_format).must_equal "<xml>I Am Wrong And I Am Right</xml>" }
it { _(WithPartial.new(nil).show_without_partial).must_equal "Adenosine Breakdown" }

it { WithPartialAndManyViewPaths.new(nil).show.must_equal "I Am Wrong And I Am Right" }
it { WithPartialAndManyViewPaths.new(nil).show_with_format.must_equal "<xml>I Am Wrong And I Am Right</xml>" }
it { WithPartialAndManyViewPaths.new(nil).show_without_partial.must_equal "Adenosine Breakdown" }
it { _(WithPartialAndManyViewPaths.new(nil).show).must_equal "I Am Wrong And I Am Right" }
it { _(WithPartialAndManyViewPaths.new(nil).show_with_format).must_equal "<xml>I Am Wrong And I Am Right</xml>" }
it { _(WithPartialAndManyViewPaths.new(nil).show_without_partial).must_equal "Adenosine Breakdown" }
end
46 changes: 23 additions & 23 deletions test/prefixes_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,39 +42,39 @@ def self._local_prefixes


describe "::controller_path" do
it { ::BassistCell.new(@controller).class.controller_path.must_equal "bassist" }
it { SingerCell.new(@controller).class.controller_path.must_equal "prefixes_test/singer" }
it { _(::BassistCell.new(@controller).class.controller_path).must_equal "bassist" }
it { _(SingerCell.new(@controller).class.controller_path).must_equal "prefixes_test/singer" }
end

describe "#_prefixes" do
it { ::BassistCell.new(@controller)._prefixes.must_equal ["test/fixtures/bassist"] }
it { ::BassistCell::FenderCell.new(@controller)._prefixes.must_equal ["app/cells/bassist_cell/fender"] }
it { ::BassistCell::IbanezCell.new(@controller)._prefixes.must_equal ["test/fixtures/bassist_cell/ibanez", "test/fixtures/bassist"] }
it { _(::BassistCell.new(@controller)._prefixes).must_equal ["test/fixtures/bassist"] }
it { _(::BassistCell::FenderCell.new(@controller)._prefixes).must_equal ["app/cells/bassist_cell/fender"] }
it { _(::BassistCell::IbanezCell.new(@controller)._prefixes).must_equal ["test/fixtures/bassist_cell/ibanez", "test/fixtures/bassist"] }

it { SingerCell.new(@controller)._prefixes.must_equal ["app/cells/prefixes_test/singer"] }
it { BackgroundVocalsCell.new(@controller)._prefixes.must_equal ["app/cells/prefixes_test/background_vocals", "app/cells/prefixes_test/singer"] }
it { ChorusCell.new(@controller)._prefixes.must_equal ["app/cells/prefixes_test/chorus", "app/cells/prefixes_test/background_vocals", "app/cells/prefixes_test/singer"] }
it { _(SingerCell.new(@controller)._prefixes).must_equal ["app/cells/prefixes_test/singer"] }
it { _(BackgroundVocalsCell.new(@controller)._prefixes).must_equal ["app/cells/prefixes_test/background_vocals", "app/cells/prefixes_test/singer"] }
it { _(ChorusCell.new(@controller)._prefixes).must_equal ["app/cells/prefixes_test/chorus", "app/cells/prefixes_test/background_vocals", "app/cells/prefixes_test/singer"] }

it { GuitaristCell.new(@controller)._prefixes.must_equal ["stringer", "app/cells/prefixes_test/singer"] }
it { BassistCell.new(@controller)._prefixes.must_equal ["app/cells/prefixes_test/bassist", "basser", "app/cells/prefixes_test/singer"] }
it { _(GuitaristCell.new(@controller)._prefixes).must_equal ["stringer", "app/cells/prefixes_test/singer"] }
it { _(BassistCell.new(@controller)._prefixes).must_equal ["app/cells/prefixes_test/bassist", "basser", "app/cells/prefixes_test/singer"] }
# it { DrummerCell.new(@controller)._prefixes.must_equal ["drummer", "stringer", "prefixes_test/singer"] }

# multiple view_paths.
it { EngineCell.prefixes.must_equal ["app/cells/engine", "/var/engine/app/cells/engine"] }
it { _(EngineCell.prefixes).must_equal ["app/cells/engine", "/var/engine/app/cells/engine"] }
it do
InheritingFromEngineCell.prefixes.must_equal [
_(InheritingFromEngineCell.prefixes).must_equal [
"app/cells/inheriting_from_engine", "/var/engine/app/cells/inheriting_from_engine",
"app/cells/engine", "/var/engine/app/cells/engine"]
end

# ::_prefixes is cached.
it do
WannabeCell.prefixes.must_equal ["test/fixtures/wannabe", "test/fixtures/bassist_cell/ibanez", "test/fixtures/bassist"]
_(WannabeCell.prefixes).must_equal ["test/fixtures/wannabe", "test/fixtures/bassist_cell/ibanez", "test/fixtures/bassist"]
WannabeCell.instance_eval { def _local_prefixes; ["more"] end }
# _prefixes is cached.
WannabeCell.prefixes.must_equal ["test/fixtures/wannabe", "test/fixtures/bassist_cell/ibanez", "test/fixtures/bassist"]
_(WannabeCell.prefixes).must_equal ["test/fixtures/wannabe", "test/fixtures/bassist_cell/ibanez", "test/fixtures/bassist"]
# superclasses don't get disturbed.
::BassistCell.prefixes.must_equal ["test/fixtures/bassist"]
_(::BassistCell.prefixes).must_equal ["test/fixtures/bassist"]
end
end

Expand All @@ -96,12 +96,12 @@ def play
class FunkerCell < SlapperCell
end

it { SlapperCell.new(nil)._prefixes.must_equal ["test/fixtures/inherit_views_test/slapper", "test/fixtures/bassist"] }
it { FunkerCell.new(nil)._prefixes.must_equal ["test/fixtures/inherit_views_test/funker", "test/fixtures/inherit_views_test/slapper", "test/fixtures/bassist"] }
it { _(SlapperCell.new(nil)._prefixes).must_equal ["test/fixtures/inherit_views_test/slapper", "test/fixtures/bassist"] }
it { _(FunkerCell.new(nil)._prefixes).must_equal ["test/fixtures/inherit_views_test/funker", "test/fixtures/inherit_views_test/slapper", "test/fixtures/bassist"] }

# test if normal cells inherit views.
it { cell('inherit_views_test/slapper').play.must_equal 'Doo' }
it { cell('inherit_views_test/funker').play.must_equal 'Doo' }
it { _(cell('inherit_views_test/slapper').play).must_equal 'Doo' }
it { _(cell('inherit_views_test/funker').play).must_equal 'Doo' }


# TapperCell
Expand All @@ -122,12 +122,12 @@ class PopperCell < TapperCell
end

# Tapper renders its play
it { cell('inherit_views_test/tapper').call(:play).must_equal 'Dooom!' }
it { _(cell('inherit_views_test/tapper').call(:play)).must_equal 'Dooom!' }
# Tapper renders its tap
it { cell('inherit_views_test/tapper').call(:tap).must_equal 'Tap tap tap!' }
it { _(cell('inherit_views_test/tapper').call(:tap)).must_equal 'Tap tap tap!' }

# Popper renders Tapper's play
it { cell('inherit_views_test/popper').call(:play).must_equal 'Dooom!' }
it { _(cell('inherit_views_test/popper').call(:play)).must_equal 'Dooom!' }
# Popper renders its tap
it { cell('inherit_views_test/popper').call(:tap).must_equal "TTttttap I'm not good enough!" }
it { _(cell('inherit_views_test/popper').call(:tap)).must_equal "TTttttap I'm not good enough!" }
end
12 changes: 6 additions & 6 deletions test/property_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def title

let (:song) { Struct.new(:title).new("<b>She Sells And Sand Sandwiches") }
# ::property creates automatic accessor.
it { SongCell.(song).title.must_equal "<b>She Sells And Sand Sandwiches</b>" }
it { _(SongCell.(song).title).must_equal "<b>She Sells And Sand Sandwiches</b>" }
end


Expand All @@ -38,11 +38,11 @@ def raw_title
end

# ::property escapes, everywhere.
it { SongCell.(song).title.must_equal "&lt;b&gt;She Sells And Sand Sandwiches</b>" }
it { SongCell.(song).copyright.must_equal "&lt;a&gt;Copy&lt;/a&gt;" }
it { SongCell.(song).lyrics.must_equal "&lt;i&gt;Words&lt;/i&gt;" }
it { _(SongCell.(song).title).must_equal "&lt;b&gt;She Sells And Sand Sandwiches</b>" }
it { _(SongCell.(song).copyright).must_equal "&lt;a&gt;Copy&lt;/a&gt;" }
it { _(SongCell.(song).lyrics).must_equal "&lt;i&gt;Words&lt;/i&gt;" }
# no escaping for non-strings.
it { SongCell.(song).artist.must_equal Object }
it { _(SongCell.(song).artist).must_equal Object }
# no escaping when escape: false
it { SongCell.(song).raw_title.must_equal "<b>She Sells And Sand Sandwiches</b>" }
it { _(SongCell.(song).raw_title).must_equal "<b>She Sells And Sand Sandwiches</b>" }
end
Loading

0 comments on commit 7b2a52d

Please sign in to comment.