我想在代码不正确时看到错误,但我看到此失败
失败/错误:引发身份验证错误
UserAuthenticator::AuthenticationError:
UserAuthenticator::AuthenticationError
以下代码来自user_authenticator_spec
需要"rails_helper">
describe UserAuthenticator do
describe '#perform' do
context 'when code is incorrect' do
it 'should raise an error' do
authenticator = described_class.new('sample_code')
expect(authenticator.perform).to raise_error(AuthenticationError)
expect(authenticator.user).to be_nil
end
end
end
end
以及以下来自user_authenticator的代码
class UserAuthenticator
class AuthenticationError < StandardError; end
attr_reader :user
def initialize(code)
end
def perform
raise AuthenticationError
end
end
我更改了此行代码
expect(authenticator.perform).to raise_error(AuthenticationError)
自
expect{ authenticator.perform }.to raise_error(UserAuthenticator::AuthenticationError)
这是工作!