cells icon indicating copy to clipboard operation
cells copied to clipboard

Ruby 3.0 ArgumentError: wrong number of arguments error with keyword args for Cell::Testing

Open taketo1113 opened this issue 2 years ago • 0 comments

It raises the error of wrong number of arguments when exec Cell::Testing#call with keyword args in ruby 3.0.

Steps to reproduce

ref: https://github.com/taketo1113/cells/commit/4505a537579325f826d83c84fa4200a56dde48c2

# test/testing_test.rb
class CapybaraTest < MiniTest::Spec
  class CapybaraCell < Cell::ViewModel
    def show_with_keyargs(text: '')
      "<p>text</p>"
    end
  end

  describe "capybara support" do
    subject { cell("capybara_test/capybara", nil) }

    it { _(subject.(:show_with_keyargs, text: 'with keyargs').has_selector?('p')).must_equal true }
  end
end

Expected behavior

It will pass test show_with_keyargs cell with keyword args.

Actual behavior

It raises the below error.

  1) Error:
capybara support#test_0002_anonymous:
ArgumentError: wrong number of arguments (given 1, expected 0)
    /path/cells/test/testing_test.rb:50:in `show_with_keyargs'
    /path/cells/lib/cell/view_model.rb:114:in `render_state'
    /path/cells/lib/cell/caching.rb:48:in `render_state'
    /path/cells/lib/cell/view_model.rb:92:in `call'
    /path/cells/lib/cell/testing.rb:47:in `call'
    /path/cells/test/testing_test.rb:63:in `block (2 levels) in <class:CapybaraTest>'

114 runs, 156 assertions, 0 failures, 1 errors, 0 skips

Focus on failing tests:
ruby test/testing_test.rb -l 63

It can't get show_with_keyargs args of keyword args in CapybaraCell#show_with_keyargs. Because Cell::Testing#call does not support keyword args.

https://github.com/trailblazer/cells/blob/master/lib/cell/testing.rb#L46-L48

System configuration

  • ruby: 3.0.5
  • cells: (github master branch)

taketo1113 avatar Feb 07 '23 03:02 taketo1113