@@ -169,6 +169,64 @@ def puts(content)
169169 end
170170 end
171171
172+ describe 'when the output filename has been customized' do
173+ before do
174+ allow ( Dir ) . to receive ( :pwd ) . and_return ( '/default_path' )
175+ end
176+
177+ it 'writes to the specified location if provided in jasmine_junitxml_formatter.yml' do
178+ config_path = File . join ( '/default_path' , 'spec' , 'javascripts' , 'support' , 'jasmine_junitxml_formatter.yml' )
179+ allow ( File ) . to receive ( :exist? ) . with ( config_path ) . and_return ( true )
180+ allow ( File ) . to receive ( :read ) . with ( config_path ) . and_return <<-YAML
181+ ---
182+ junit_xml_filename: "custom_filename.junit.xml"
183+ YAML
184+ allow ( File ) . to receive ( :open ) . and_call_original
185+ allow ( File ) . to receive ( :open ) . with ( '/default_path/custom_filename.junit.xml' , 'w' ) . and_yield ( file_stub )
186+
187+ results = [ passing_result ( 'fullName' => 'Passing test' , 'description' => 'test' ) ]
188+ subject = Jasmine ::Formatters ::JunitXml . new
189+
190+ subject . format ( results )
191+ subject . done ( { } )
192+ expect ( file_stub . content ) . to_not eq ''
193+ end
194+
195+ it 'writes to default location if junit_xml_filename is not provided in jasmine_junitxml_formatter.yml' do
196+ allow ( File ) . to receive ( :open ) . and_call_original
197+ allow ( File ) . to receive ( :open ) . with ( '/default_path/junit_results.xml' , 'w' ) . and_yield ( file_stub )
198+
199+ results = [ passing_result ( 'fullName' => 'Passing test' , 'description' => 'test' ) ]
200+ subject = Jasmine ::Formatters ::JunitXml . new
201+
202+ subject . format ( results )
203+ subject . done ( { } )
204+ expect ( file_stub . content ) . to_not eq ''
205+ end
206+ end
207+
208+ describe 'when both the output directory and output filename has been customized' do
209+ it 'writes to the customized location using the customized filename if provided in jasmine_junitxml_formatter.yml' do
210+ allow ( Dir ) . to receive ( :pwd ) . and_return ( '/default_path' )
211+ config_path = File . join ( '/default_path' , 'spec' , 'javascripts' , 'support' , 'jasmine_junitxml_formatter.yml' )
212+ allow ( File ) . to receive ( :exist? ) . with ( config_path ) . and_return ( true )
213+ allow ( File ) . to receive ( :read ) . with ( config_path ) . and_return <<-YAML
214+ ---
215+ junit_xml_path: "/custom_path"
216+ junit_xml_filename: "custom_filename.junit.xml"
217+ YAML
218+ allow ( File ) . to receive ( :open ) . and_call_original
219+ allow ( File ) . to receive ( :open ) . with ( '/custom_path/custom_filename.junit.xml' , 'w' ) . and_yield ( file_stub )
220+
221+ results = [ passing_result ( 'fullName' => 'Passing test' , 'description' => 'test' ) ]
222+ subject = Jasmine ::Formatters ::JunitXml . new
223+
224+ subject . format ( results )
225+ subject . done ( { } )
226+ expect ( file_stub . content ) . to_not eq ''
227+ end
228+ end
229+
172230 describe 'with a custom config file path' do
173231 before do
174232 allow ( Dir ) . to receive ( :pwd ) . and_return ( '/default_path' )
0 commit comments