Skip to content

Commit e045ee0

Browse files
Merge pull request #8 from billhorsman/master
Stub any_instance of Interceptor
2 parents 3e3ae6a + bcfdb9e commit e045ee0

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

test/mail_interceptor_test.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class MailInterceptorTest < Minitest::Test
1010

1111
def setup
1212
@message = OpenStruct.new
13+
stub_env_methods('test')
1314
end
1415

1516
def test_normalized_deliver_emails_to
@@ -37,7 +38,6 @@ def test_no_subject_prefix_in_test
3738
interceptor = ::MailInterceptor::Interceptor.new forward_emails_to: 'test@example.com',
3839
subject_prefix: nil
3940
@message.subject = 'Forgot password'
40-
stub_env_methods(interceptor, 'test')
4141

4242
interceptor.delivering_email @message
4343
assert_equal "Forgot password", @message.subject
@@ -47,17 +47,16 @@ def test_subject_prefix_in_test
4747
interceptor = ::MailInterceptor::Interceptor.new forward_emails_to: 'test@example.com',
4848
subject_prefix: 'wheel'
4949
@message.subject = 'Forgot password'
50-
stub_env_methods(interceptor, 'test')
5150

5251
interceptor.delivering_email @message
5352
assert_equal "[wheel TEST] Forgot password", @message.subject
5453
end
5554

5655
def test_subject_prefix_in_production
56+
stub_env_methods('production')
5757
interceptor = ::MailInterceptor::Interceptor.new forward_emails_to: 'test@example.com',
5858
subject_prefix: 'wheel'
5959
@message.subject = 'Forgot password'
60-
stub_env_methods(interceptor, 'production')
6160

6261
interceptor.delivering_email @message
6362
assert_equal "[wheel] Forgot password", @message.subject
@@ -90,8 +89,8 @@ def test_error_if_forward_emails_to_is_empty
9089

9190
private
9291

93-
def stub_env_methods(interceptor, env)
94-
interceptor.stubs(:env).returns(env)
95-
interceptor.stubs(:production?).returns(env == 'production')
92+
def stub_env_methods(env)
93+
::MailInterceptor::Interceptor.any_instance.stubs(:env).returns(env)
94+
::MailInterceptor::Interceptor.any_instance.stubs(:production?).returns(env == 'production')
9695
end
9796
end

0 commit comments

Comments
 (0)