Created
December 16, 2015 10:02
-
-
Save pinzolo/fa865c59d1c111ccb383 to your computer and use it in GitHub Desktop.
外部gemなしに定数のstub化したい場合
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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