Sha256: ac17746e59d5a2092dcb8ac92333ccc69fecfb2038d54efbc10a5167d8ac5c25

Contents?: true

Size: 1.19 KB

Versions: 3

Compression:

Stored size: 1.19 KB

Contents

require 'test_helper'
require 'review/book'

require 'stringio'
require 'tempfile'
require 'tmpdir'

include ReVIEW

module BookTestHelper
  def mktmpbookdir(files = {})
    created_files = {}
    Dir.mktmpdir do |tmpdir|
      Dir.chdir(tmpdir) do
        dir = '.'
        files.each_pair do |filename, content|
          path = File.join(dir, filename)
          FileUtils.mkdir_p(File.dirname(path))
          File.open(path, 'w') { |o| o.print content }
          created_files[filename] = path
        end
        conf_path = File.expand_path('config.yml', dir)
        config = if File.exist?(conf_path)
                   ReVIEW::Configure.create(yamlfile: conf_path)
                 else
                   ReVIEW::Configure.values
                 end
        book = Book::Base.new(dir, config: config)
        yield(dir, book, created_files)
      end
    end
  end

  def get_instance_variables(obj)
    obj.instance_variables.each_with_object({}) do |name, memo|
      value = obj.instance_variable_get(name)
      memo[name] = if value.instance_variables.empty?
                     value
                   else
                     get_instance_variables(value)
                   end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
review-5.6.0 test/book_test_helper.rb
review-5.5.0 test/book_test_helper.rb
review-5.4.0 test/book_test_helper.rb