Sha256: 5e8ef9dcca0228bad68bc97d0b206d201a33512d4373de8ffaceee1a2ef5e5c7

Contents?: true

Size: 1.01 KB

Versions: 20

Compression:

Stored size: 1.01 KB

Contents

require "stringio"

module Roger
  # Module with some helper functions for testing Roger CLI commands
  module TestCli
    # Capture stdout/stderr output
    def capture
      @_orig_stdout = $stdout
      @_orig_stderr = $stderr

      $stdout = StringIO.new
      $stderr = StringIO.new

      yield

      return [$stdout.string, $stderr.string]
    ensure
      $stdout = @_orig_stdout
      $stderr = @_orig_stderr
    end

    def run_command(args, &_block)
      out, err = capture do
        Cli::Base.start(args, debug: true)
      end
      [out, err]
    end

    def run_command_with_rogerfile(args, &_block)
      project = Project.new(
        @base_path || File.dirname(__FILE__) + "/../../project",
        rogerfile_path: false
      )

      rogerfile = Roger::Rogerfile.new(project)

      yield(rogerfile) if block_given?

      project.rogerfile = rogerfile

      Cli::Base.project = project

      out, err = capture do
        Cli::Base.start(args, debug: true)
      end
      [out, err]
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
roger-1.10.0 test/helpers/cli.rb
roger-1.9.1 test/helpers/cli.rb
roger-1.9.0 test/helpers/cli.rb
roger-1.8.0 test/helpers/cli.rb
roger-1.7.2 test/helpers/cli.rb
roger-1.7.1 test/helpers/cli.rb
roger-1.7.0 test/helpers/cli.rb
roger-1.6.4 test/helpers/cli.rb
roger-1.6.3 test/helpers/cli.rb
roger-1.6.2 test/helpers/cli.rb
roger-1.6.1 test/helpers/cli.rb
roger-1.6.0 test/helpers/cli.rb
roger-1.5.0 test/helpers/cli.rb
roger-1.4.6 test/helpers/cli.rb
roger-1.4.5 test/helpers/cli.rb
roger-1.4.4 test/helpers/cli.rb
roger-1.4.3 test/helpers/cli.rb
roger-1.4.2 test/helpers/cli.rb
roger-1.4.1 test/helpers/cli.rb
roger-1.4.0 test/helpers/cli.rb