2016-07-16 1 views
0

나는 약간의 레이즈 에러 예외에 대한 간단한 rspec 테스트를 작성하려고한다. 오류 메시지 ALREADY_A_BITLY_LINK - '500'raise_error(BitlyError)을 일치시킬 예상을 작성하려면 어떻게해야합니까? 이 rspec 실제로 전달합니다. 하지만 잘못된 URL에 동일한 raise_error를 사용해야하는 경우. 그것은 또한 통과 할 것이다. 특정 예외 메시지를 테스트하려면 어떻게해야합니까?bitly raise error exception rspec 테스트

bitly_spec.rb

require 'rails_helper' 

describe Bitly do 
    before do 
    @bitly = Bitly.new(username, api_key) 
    end 
    let(:bitly_url) { 'bitly_url' } #stackoverflow doesn't allow URL shortener 

    it 'should return exception error if given url is bitly' do 
    expect { @bitly.shorten(bitly_url) }.to raise_error(BitlyError) 
    end 
end 

디버거

@bitly.shorten(bitly_url) 반환 *** BitlyError Exception: ALREADY_A_BITLY_LINK - '500'

raise_error(BitlyError) 반환 #<RSpec::Matchers::BuiltIn::RaiseError:0x007fa229c56f48 @block=nil, @actual_error=nil, @warn_about_bare_error=false, @expected_error=BitlyError, @expected_message=nil>

답변