Skip to content

Instantly share code, notes, and snippets.

@pinzolo
Created December 16, 2015 10:02
Show Gist options
  • Save pinzolo/fa865c59d1c111ccb383 to your computer and use it in GitHub Desktop.
Save pinzolo/fa865c59d1c111ccb383 to your computer and use it in GitHub Desktop.
外部gemなしに定数のstub化したい場合
class Foo
BAR = 'bar'
end
class FooTest < ActiveSupport::TestCase
setup do
@original = Foo.send(:remove_const, :BAR)
Foo.const_set(:BAR, 'new_value')
end
teardown do
Foo.send(:remove_const, :BAR)
Foo.const_set(:BAR, @original)
end
test 'Foo::BARのテスト' do
assert_equal 'new_value', Foo::BAR
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment