module Librarian::RSpec::Support::CliMacro

Public Class Methods

included(base) click to toggle source
# File lib/librarian/rspec/support/cli_macro.rb, line 51
def self.included(base)
  base.instance_exec do
    let(:project_path) do
      project_path = Pathname.pwd.expand_path
      project_path = project_path.dirname until project_path.join("Rakefile").exist?
      project_path
    end
    let(:tmp) { project_path.join("tmp/spec/cli") }
    let(:pwd) { tmp + SecureRandom.hex(8) }

    before { tmp.mkpath }
    before { pwd.mkpath }

    after  { tmp.rmtree }
  end
end

Public Instance Methods

cli!(*args) click to toggle source
# File lib/librarian/rspec/support/cli_macro.rb, line 68
def cli!(*args)
  @shell = FakeShell.new
  @exit_status = Dir.chdir(pwd) do
    described_class.with_environment do
      described_class.returning_status do
        described_class.start args, :shell => @shell
      end
    end
  end
end
exit_status() click to toggle source
# File lib/librarian/rspec/support/cli_macro.rb, line 105
def exit_status
  @exit_status
end
have_file(rel_path, content = nil) click to toggle source
# File lib/librarian/rspec/support/cli_macro.rb, line 109
def have_file(rel_path, content = nil)
  FileMatcher.new(rel_path, content)
end
have_json_file(rel_path, content) click to toggle source
# File lib/librarian/rspec/support/cli_macro.rb, line 113
def have_json_file(rel_path, content)
  FileMatcher.new(rel_path, content, :type => :json)
end
shell() click to toggle source
# File lib/librarian/rspec/support/cli_macro.rb, line 93
def shell
  @shell
end
stderr() click to toggle source
# File lib/librarian/rspec/support/cli_macro.rb, line 101
def stderr
  shell.stderr.string
end
stdout() click to toggle source
# File lib/librarian/rspec/support/cli_macro.rb, line 97
def stdout
  shell.stdout.string
end
strip_heredoc(text) click to toggle source
# File lib/librarian/rspec/support/cli_macro.rb, line 89
def strip_heredoc(text)
  Librarian::Helpers.strip_heredoc(text)
end
write_file!(path, content) click to toggle source
# File lib/librarian/rspec/support/cli_macro.rb, line 79
def write_file!(path, content)
  path = pwd.join(path)
  path.dirname.mkpath
  path.open("wb"){|f| f.write(content)}
end
write_json_file!(path, content) click to toggle source
# File lib/librarian/rspec/support/cli_macro.rb, line 85
def write_json_file!(path, content)
  write_file! path, JSON.dump(content)
end