Minitest DSL with TestUp

Is it possible to use Minitest::Spec::DLS to write TestUp tests?
most likely to @tt_su

Yes, it’s possible with some diligence. It would probably have looked more prettily with the original reporter, and perhaps one day (which is unlikely) it would turn into a real gem. But it’s working now and if you’re a ‘believer’ in TDD and use tests to write code, I’ll be happy to share it with you.

module Parametric
  module Tools
    module BoxTool
      module Tests
        extend Spec::TestsRoot

        describe BoxTool do
          test_helpers Tools::Helpers

          let(:transformation) { IDENTITY }
          let(:view) { Sketchup.active_model.active_view }
          let(:xyz_tool) { mock_tool(xyz_stage_result, transformation) }
          let(:profile) { Parametric::Geom.rectangle ORIGIN, ::Geom::Vector3d.new(10,20,0) }
          let(:push_pull_tool) { mock_tool(push_pull_stage_result, profile) }
          let(:push_pull_stage_result) do
            {
              view: view,
              vector: ::Geom::Vector3d.new(0, 0, 30)
            }
          end
          let(:xyz_stage_result) do
            {
              view: view,
              vertex: ORIGIN,
              vectors: Geom.decompose_vector(ORIGIN.vector_to([10,20,30]))
            }
          end
          
          before do
            @truly_xyz = Tools.set_default(:xyz_tool, xyz_tool)
            @truly_push_pull = Tools.set_default(:push_pull_tool, push_pull_tool)
          end

          after do
            Tools.set_default(:xyz_tool, @truly_xyz)
            Tools.set_default(:push_pull_tool, @truly_push_pull)
          end

          describe 'workflow' do

            subject do
              tn = transformation
              tool_fixture(BoxTool) do
                @transformation = tn
              end
            end

            before do
              subject.activate
            end

            context 'when first stage returns flat' do
              let(:xyz_stage_result) do
                {
                  view:,
                  vertex: ORIGIN,
                  vectors: [::Geom::Vector3d.new(10, 0, 0), ::Geom::Vector3d.new(0, 20, 0)]
                }
              end
              
              it 'uses xyz_tool' do
                expect(xyz_tool).must_be :used?
              end

              it 'uses push_pull_tool' do
                expect(push_pull_tool).must_be :used?
              end
            end

            context 'when first stage directly returns box' do
              let(:xyz_stage_result) do
                {
                  view: view,
                  vertex: ORIGIN,
                  vectors: Geom.decompose_vector(ORIGIN.vector_to([10,20,30]))
                }
              end
              
              it 'uses xyz_tool' do
                expect(xyz_tool).must_be :used?
              end

              it 'skips push_pull_tool' do
                expect(push_pull_tool).must_be :unused?
              end
            end  
          end

          describe '.as_stage' do
            let(:done_flag) { Minitest::Mock.new.expect(:call, nil, [expected_callback_params]) }
            subject do
              Parametric::Tools::BoxTool.as_stage { |params| done_flag.call params }
            end
            let(:expected_callback_params) do
              { 
                view: view, 
                position: transformation, 
                x: 10, y: 20, z: 30
              }
            end

            it 'returns Stage instance' do
              expect(subject).must_be_instance_of Parametric::Tools::BoxTool::Stage
            end

            it 'activation makes callback with expected params' do
              subject.activate
              done_flag.verify
            end
          end
        end  
      end
    end
  end
end

FYI, it is required to choose and use a unique top-level namespace module that all your extensions will be wrapped within. The word “Parametric” is rather common. (I do understand if this is just an example to get TestUp working. Just saying, so newbs can get this idea in their heads.)