thoughtbot / shoulda-context

Shoulda Context makes it easy to write understandable and maintainable tests under Minitest and Test::Unit within Rails projects or plain Ruby projects.
MIT License
239 stars 58 forks source link

Add support for Ruby 3.0.z #86

Open vsppedro opened 1 year ago

vsppedro commented 1 year ago

TODO:

Error in CI:

Error:
RerunSnippetTest#test_: A Rails application with shoulda-context added to it should display the correct rerun snippet when a test fails. :
NoMethodError: undefined method `scan' for {:env=>{:TESTOPTS=>"-v"}}:Hash
    /home/pedro/.rbenv/versions/3.0.6/lib/ruby/3.0.0/shellwords.rb:91:in `shellsplit'
    /home/pedro/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/snowglobe-0.3.0/lib/snowglobe/command_runner.rb:145:in `block in command'
    /home/pedro/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/snowglobe-0.3.0/lib/snowglobe/command_runner.rb:144:in `each'
    /home/pedro/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/snowglobe-0.3.0/lib/snowglobe/command_runner.rb:144:in `flat_map'
    /home/pedro/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/snowglobe-0.3.0/lib/snowglobe/command_runner.rb:144:in `command'
    /home/pedro/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/snowglobe-0.3.0/lib/snowglobe/command_runner.rb:154:in `run'
    /home/pedro/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/snowglobe-0.3.0/lib/snowglobe/command_runner.rb:38:in `call'
    /home/pedro/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/snowglobe-0.3.0/lib/snowglobe/command_runner.rb:38:in `block in initialize'
    /home/pedro/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/snowglobe-0.3.0/lib/snowglobe/command_runner.rb:160:in `run_with_wrapper'
    /home/pedro/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/snowglobe-0.3.0/lib/snowglobe/command_runner.rb:167:in `run_with_debugging'
    /home/pedro/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/snowglobe-0.3.0/lib/snowglobe/command_runner.rb:73:in `block (2 levels) in call'
    /home/pedro/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/snowglobe-0.3.0/lib/snowglobe/command_runner.rb:188:in `possibly_running_quickly'
    /home/pedro/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/snowglobe-0.3.0/lib/snowglobe/command_runner.rb:72:in `block in call'
    /home/pedro/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/snowglobe-0.3.0/lib/snowglobe/command_runner.rb:194:in `possibly_retrying'
    /home/pedro/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/snowglobe-0.3.0/lib/snowglobe/command_runner.rb:71:in `call'
    <internal:kernel>:90:in `tap'
    /home/pedro/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/snowglobe-0.3.0/lib/snowglobe/command_runner.rb:12:in `run'
    /home/pedro/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/snowglobe-0.3.0/lib/snowglobe/project_command_runner.rb:57:in `run'
    /home/pedro/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/snowglobe-0.3.0/lib/snowglobe/project_command_runner.rb:31:in `run_rake_tasks'
    /home/pedro/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/snowglobe-0.3.0/lib/snowglobe/project_command_runner.rb:16:in `run_n_unit_test_suite'
    /home/pedro/.rbenv/versions/3.0.6/lib/ruby/3.0.0/forwardable.rb:238:in `run_n_unit_test_suite'
    /media/pedro/b6676fde-69fd-45ee-a934-d39abc17cec44/pedro/tempo-livre/collaborator/shoulda-context/test/shoulda/rerun_snippet_test.rb:20:in `block (2 levels) in <class:RerunSnippetTest>'
    /media/pedro/b6676fde-69fd-45ee-a934-d39abc17cec44/pedro/tempo-livre/collaborator/shoulda-context/test/shoulda/rerun_snippet_test.rb:13:in `instance_exec'
    /media/pedro/b6676fde-69fd-45ee-a934-d39abc17cec44/pedro/tempo-livre/collaborator/shoulda-context/test/shoulda/rerun_snippet_test.rb:13:in `block in create_test_from_should_hash'
corincerami commented 1 year ago

I think you may need to change method_missing here to:

      def method_missing(method, *args, **kwargs, &blk)
        test_unit_class.send(method, *args, **kwargs, &blk)
      end

We had to monkeypatch this in our application as Ruby 3 no longer supports passing keyword arguments as regular arguments or a Hash.