Skip to content

Instantly share code, notes, and snippets.

@furugomu
Last active July 13, 2016 04:50
Show Gist options
  • Save furugomu/a92b794dcf8cd60c723abecbc8ac4419 to your computer and use it in GitHub Desktop.
Save furugomu/a92b794dcf8cd60c723abecbc8ac4419 to your computer and use it in GitHub Desktop.
context for ActiveSupport::TestCase
class ActiveSupport::TestCase
# context 'foo' => class Context_foo < self
def self.context(name, &block)
class_name = "Context_#{name.gsub(/[[:^word:]]+/, '_')}".to_sym
const_set(class_name, Class.new(self, &block))
end
end
require 'test_helper'
class FooTest < ActiveSupport::TestCase
context 'bar' do
test 'returns foobar' do
assert(Foo.bar == 'foobar')
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment