Skip to content

Instantly share code, notes, and snippets.

View everton's full-sized avatar

Everton J. Carpes everton

  • http://www.nutrebem.com.br
  • Rio de Janeiro, RJ - Brasil
View GitHub Profile
module FormTestHelper
def assert_form(action, options = {}, &block)
method = options.delete(:method) || :post
if method == :put || method == :patch || method == :delete
virtual_method, method = method, :post
test_body = -> (*args) {
assert_select "input[type='hidden'][name='_method']",
value: virtual_method
@everton
everton / lisp-conditions-in-ruby.rb
Last active April 21, 2024 18:57
Inspired by Common LISP conditions system, this code here uses continuations to inject "restart" options from the context where an Exception was raised and allowing to resume from the error line. Obs.: since this code relies on continuations, it is not supposed to work on Ruby implementations without this resource (such as JRuby, Ribinius, etc)
require 'continuation'
class Restart < RuntimeError
attr_accessor :menu
def initialize(**menu)
@menu = menu
@menu.each do |name, proc|
define_singleton_method "#{name}!" do