diff --git a/bin/pdd b/bin/pdd index ead2c3c..f60ad4e 100755 --- a/bin/pdd +++ b/bin/pdd @@ -38,6 +38,6 @@ end if opts.help? puts opts else - file = opts.file? ? opts[:file] : STDOUT - File.write(file, PDD::Base.new(opts).xml) + file = opts.file? ? File.new(opts[:file], 'w') : STDOUT + file << PDD::Base.new(opts).xml end diff --git a/features/cli.feature b/features/cli.feature index 7b0d283..d898ded 100644 --- a/features/cli.feature +++ b/features/cli.feature @@ -33,6 +33,6 @@ Feature: Command Line Processing ~~ and second ~~ """ - When I run bin/pdd with " " + When I run bin/pdd with "> out.xml" Then Exit code is zero - And Stdout contains "" + And XML file "out.xml" matches "/puzzles[count(puzzle)=1]" diff --git a/features/step_definitions/steps.rb b/features/step_definitions/steps.rb index 19c0d96..0a9dc0b 100644 --- a/features/step_definitions/steps.rb +++ b/features/step_definitions/steps.rb @@ -81,6 +81,7 @@ end Then(/^XML file "([^"]+)" matches "([^"]+)"$/) do |file, xpath| + fail "File #{file} doesn't exit" unless File.exist?(file) xml = Nokogiri::XML.parse(File.read(file)) if xml.xpath(xpath).empty? fail "XML file #{file} doesn't match \"#{xpath}\":\n#{xml}"