0
나는 시험 블록이 있습니다리팩토링 테스트는
describe 'without' do
describe 'author' do
let(:author) {nil}
it('fails') {assert_raises(ArgumentError) { excerpt }}
end
describe 'title' do
# same content as above, but testing title
end
describe 'content' do
# same content as above, but testing content
end
end
이 잘 작동하고 테스트를 통과 -하지만 많은 반복이 여기있어 이후로, 내가 리팩토링 원 :
describe 'without' do
describe 'author' do
let(:author) {nil}
it('fails') {assert_failure(excerpt} # added a method in this line
end
describe 'title' do
# same content as above, but testing title
end
describe 'content' do
# same content as above, but testing content
end
# and the method here
def assert_failure(instance)
assert_raises(ArgumentError) { instance }
end
end
그러나이 작동하지 않습니다 - 내 테스트는 다음 오류와 함께 실패합니다.
construction::without::author#test_0001_fails:
ArgumentError: Excerpt cannot be built: Author missing
내가 예상 한 오류는 어느 것입니까? 누락 된 정보로 생겨 났으며 정확하게 테스트하고 있습니다. 따라서이 어설 션을 추출 할 때 ArgumentError
이 제기되어서 assert_raises
이 모든 종류의 비교를 수행 할 수 있기 전에 테스트를 중지하는 것으로 보입니다. 나는이 어설 션을 위해 code을 조사했지만 코드가 다른 방법으로 추출 될 때 이것이 일어날 이유를 알 수는 없다.
좋은 답변, 감사 : 위의 동작을 복제 할 경우
, 당신은
assert_failure
에게 블록을 통과해야! – dax