Sha256: 713262560400546e1a5390ebf25492d005b8b9d71082f4b1705eb4c40a7be4c4

Contents?: true

Size: 1.47 KB

Versions: 28

Compression:

Stored size: 1.47 KB

Contents

module OutputHelpers
  extend RSpec::Matchers::DSL

  matcher :return_and_output do |expected, *lines|
    supports_block_expectations

    match do |block|
      stdout = lines.flatten.join("\n") + "\n"

      begin
        expect{@return = block.call}.to output(stdout).to_stdout
      rescue Exception => error
        @error = error

        return false
      else
        return values_match? expected, @return
      end
    end

    failure_message do |block|
      if @error
        return @error
      else
        return "expected #{block} to return #{expected}, but returned #{@return}"
      end
    end
  end

  matcher :output_table do |lines|
    supports_block_expectations

    match do |block|
      stdout = Regexp.new('^' + lines.map{|fields| fields.join('\s+')}.join('\n') + '\n$', Regexp::MULTILINE)


      begin
        expect{@return = block.call}.to output(stdout).to_stdout
      rescue Exception => error
        @error = error

        return false
      else
        return true
      end
    end

    failure_message do |block|
      return @error
    end
  end

  matcher :output_lines do |lines|
    supports_block_expectations

    match do |block|
      stdout = lines.flatten.join("\n") + "\n"

      begin
        expect{@return = block.call}.to output(stdout).to_stdout
      rescue Exception => error
        @error = error

        return false
      else
        return true
      end
    end

    failure_message do |block|
      return @error
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
kontena-cli-1.3.0.pre1 spec/support/output_helpers.rb
kontena-cli-1.2.2 spec/support/output_helpers.rb
kontena-cli-1.2.2.rc2 spec/support/output_helpers.rb
kontena-cli-1.2.2.rc1 spec/support/output_helpers.rb
kontena-cli-1.2.1 spec/support/output_helpers.rb
kontena-cli-1.2.1.rc1 spec/support/output_helpers.rb
kontena-cli-1.2.0 spec/support/output_helpers.rb
kontena-cli-1.2.0.rc3 spec/support/output_helpers.rb
kontena-cli-1.2.0.rc2 spec/support/output_helpers.rb
kontena-cli-1.2.0.rc1 spec/support/output_helpers.rb
kontena-cli-1.2.0.pre3 spec/support/output_helpers.rb
kontena-cli-1.2.0.pre2 spec/support/output_helpers.rb
kontena-cli-1.1.6 spec/support/output_helpers.rb
kontena-cli-1.2.0.pre1 spec/support/output_helpers.rb
kontena-cli-1.1.5 spec/support/output_helpers.rb
kontena-cli-1.1.5.rc3 spec/support/output_helpers.rb
kontena-cli-1.1.5.rc2 spec/support/output_helpers.rb
kontena-cli-1.1.5.rc1 spec/support/output_helpers.rb
kontena-cli-1.1.4 spec/support/output_helpers.rb
kontena-cli-1.2.0.dev1 spec/support/output_helpers.rb