'Run spider with specified settings; return exported data.'

@defer.inlineCallbacks
def run_and_export(self, spider_cls, settings=None):

    tmpdir = tempfile.mkdtemp()
    res_name = (tmpdir + '/res')
    defaults = {'FEED_URI': ('file://' + res_name), 'FEED_FORMAT': 'csv'}
    defaults.update((settings or {}))
    try:
        with MockServer() as s:
            runner = CrawlerRunner(Settings(defaults))
            (yield runner.crawl(spider_cls))
        with open(res_name, 'rb') as f:
            defer.returnValue(f.read())
    finally:
        shutil.rmtree(tmpdir)
