decko-commons/decko

View on GitHub
card/spec/support/helper/card_helper.rb

Summary

Maintainability
A
0 mins
Test Coverage
class Card
  module SpecHelper
    # to be included in Card
    module CardHelper
      module ClassMethods
        cattr_accessor :rspec_binding
      end

      # rubocop:disable Lint/Eval
      def method_missing m, *args, &block
        return super unless Card.rspec_binding

        suppress_name_error do
          method = eval("method(%s)" % m.inspect, Card.rspec_binding)
          return method.call(*args, &block)
        end
        suppress_name_error do
          return eval(m.to_s, Card.rspec_binding)
        end
        super
      end
      # rubocop:enable Lint/Eval

      def suppress_name_error
        yield
      rescue NameError
      end
    end
  end
end