Skip to content

Instantly share code, notes, and snippets.

@delba
Created July 22, 2013 11:29
Show Gist options
  • Save delba/6053176 to your computer and use it in GitHub Desktop.
Save delba/6053176 to your computer and use it in GitHub Desktop.
get tested_class in rails test
require 'test_helper'
class ArticleTest < ActiveSupport::TestCase
test 'tested_class is Article' do
assert_same Article, tested_class
end
private
def tested_class
@tested_class ||= begin
/(?<klass>.+)Test/ =~ self.class.name
klass.constantize
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment