Skip to content

Instantly share code, notes, and snippets.

@halostatue
Last active September 18, 2018 03:11
Show Gist options
  • Save halostatue/0a49732a888f1bed325a1df98663b199 to your computer and use it in GitHub Desktop.
Save halostatue/0a49732a888f1bed325a1df98663b199 to your computer and use it in GitHub Desktop.
Concern: Sample
# -*- ruby encoding: utf-8 -*-
module MockConcernClass
def mock_concern_class(mod)
klass = Class.new
klass.__send__(:include, mod)
klass
end
def toggle_private_instance_methods_on(klass)
klass.tap do
if (pim = klass.instance_variable_get(:@__private_instance_methods__))
klass.__send__(:private, *pim)
klass.instance_variable_set(:@__private_instance_methods__, nil)
else
pim = klass.private_instance_methods
klass.instance_variable_set(:@__private_instance_methods__, pim)
klass.__send__(:public, *pim)
end
end
end
Minitest::Test.send(:include, self)
end
# -*- ruby encoding: utf-8 -*-
module SampleConcern
extend ActiveSupport::Concern
included do
# Things to be run when this is included, such as:
#
# include OtherConcern
# validates …
# validate …
end
module ClassMethods
# Class methods to be defined against the class when this concern is
# included. This allows those methods to be used as if they were Rails
# 'keywords' (e.g., validates).
end
# Define methods and constants provided by the concern here.
end
# -*- ruby encoding: utf-8 -*-
require 'spec_helper'
describe SampleConcern do
let(:klass) { toggle_private_instance_methods(mock_concern_class(SampleConcern)) }
let(:subject) { klass.new }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment