class CallbacksTest::CallbackProcTest

Public Instance Methods

build_class(callback) click to toggle source
# File activesupport/test/callbacks_test.rb, line 940
def build_class(callback)
  Class.new {
    include ActiveSupport::Callbacks
    define_callbacks :foo
    set_callback :foo, :before, callback
    def run; run_callbacks :foo; end
  }
end
run() click to toggle source
# File activesupport/test/callbacks_test.rb, line 945
def run; run_callbacks :foo; end
test_proc_arity_0() click to toggle source
# File activesupport/test/callbacks_test.rb, line 949
def test_proc_arity_0
  calls = []
  klass = build_class(->() { calls << :foo })
  klass.new.run
  assert_equal [:foo], calls
end
test_proc_arity_1() click to toggle source
# File activesupport/test/callbacks_test.rb, line 956
def test_proc_arity_1
  calls = []
  klass = build_class(->(o) { calls << o })
  instance = klass.new
  instance.run
  assert_equal [instance], calls
end
test_proc_arity_2() click to toggle source
# File activesupport/test/callbacks_test.rb, line 964
def test_proc_arity_2
  assert_raises(ArgumentError) do
    klass = build_class(->(x, y) {})
    klass.new.run
  end
end
test_proc_negative_called_with_empty_list() click to toggle source
# File activesupport/test/callbacks_test.rb, line 971
def test_proc_negative_called_with_empty_list
  calls = []
  klass = build_class(->(*args) { calls << args })
  klass.new.run
  assert_equal [[]], calls
end