@@ -107,15 +107,24 @@ def test_with_params(target_commitish: nil, previous_tag: nil, configuration_fil
107107 end
108108
109109 describe 'error handling' do
110- def test_with_params ( target_commitish : nil , previous_tag : nil , configuration_file_path : nil , error_msg : 'API Failure' )
111- # Arrange
110+ def stub_failing_api_call ( target_commitish : nil , previous_tag : nil , configuration_file_path : nil , error_msg : 'API Failure' )
112111 allow ( client ) . to receive ( :post ) . with (
113112 "repos/#{ test_repo } /releases/generate-notes" ,
114113 config_file_path : configuration_file_path ,
115114 previous_tag_name : previous_tag ,
116115 tag_name : test_tag_name ,
117116 target_commitish : target_commitish || test_head_ref
118117 ) . and_raise ( StandardError , error_msg )
118+ end
119+
120+ def test_with_params ( target_commitish : nil , previous_tag : nil , configuration_file_path : nil , error_msg : 'API Failure' )
121+ # Arrange
122+ stub_failing_api_call (
123+ target_commitish : target_commitish ,
124+ previous_tag : previous_tag ,
125+ configuration_file_path : configuration_file_path ,
126+ error_msg : error_msg
127+ )
119128
120129 # Act
121130 result = run_described_fastlane_action (
@@ -154,5 +163,42 @@ def test_with_params(target_commitish: nil, previous_tag: nil, configuration_fil
154163 error_msg : '400 - Invalid previous_tag parameter'
155164 )
156165 end
166+
167+ context 'when `fail_on_error` is enabled' do
168+ it 'raises instead of returning the error message as the changelog' do
169+ # Arrange
170+ stub_failing_api_call ( previous_tag : '12.2' , error_msg : 'API Failure' )
171+
172+ # Act & Assert
173+ expect do
174+ run_described_fastlane_action (
175+ github_token : test_token ,
176+ repository : test_repo ,
177+ tag_name : test_tag_name ,
178+ previous_tag : '12.2' ,
179+ fail_on_error : true
180+ )
181+ end . to raise_error ( StandardError , 'API Failure' )
182+ end
183+ end
184+
185+ context 'when `fail_on_error` is explicitly disabled' do
186+ it 'returns the error message as the changelog, like the default does' do
187+ # Arrange
188+ stub_failing_api_call ( previous_tag : '12.2' , error_msg : 'API Failure' )
189+
190+ # Act
191+ result = run_described_fastlane_action (
192+ github_token : test_token ,
193+ repository : test_repo ,
194+ tag_name : test_tag_name ,
195+ previous_tag : '12.2' ,
196+ fail_on_error : false
197+ )
198+
199+ # Assert
200+ expect ( result ) . to eq ( '❌ Error computing the list of PRs since 12.2: `API Failure`' )
201+ end
202+ end
157203 end
158204end
0 commit comments