Sha256: dcee67c7e367c0acb970ba858b1d95abf1ffeeb50f42d7eab53473bb1ee93e8f

Contents?: true

Size: 1020 Bytes

Versions: 33

Compression:

Stored size: 1020 Bytes

Contents

RSpec::Matchers.define :execute_commands_matching do |pattern|

  match do |actual|
    raise(RuntimeError, "Expected #{actual} to be a FakeHost") unless actual.kind_of?(FakeHost)
    @found_count = actual.command_strings.grep(pattern).size
    @times.nil? ?
      @found_count > 0 :
      @found_count == @times
  end

  chain :exactly do |times|
    @times = times
  end

  chain :times do
    # clarity only
  end

  chain :once do
    @times = 1
    # clarity only
  end

  def message(actual, pattern, times, found_count)
      msg = times == 1 ?
        "#{pattern} once" :
        "#{pattern} #{times} times"
      msg += " but instead found a count of #{found_count}" if found_count != times
      msg + " in:\n #{actual.command_strings.pretty_inspect}"
  end

  failure_message_for_should do |actual|
    "Expected to find #{message(actual, pattern, @times, @found_count)}"
  end

  failure_message_for_should_not do |actual|
    "Unexpectedly found #{message(actual, pattern, @times, @found_count)}"
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
beaker-1.16.0 spec/matchers.rb
beaker-1.15.0 spec/matchers.rb
beaker-1.14.1 spec/matchers.rb
beaker-1.14.0 spec/matchers.rb
beaker-1.13.1 spec/matchers.rb
beaker-1.13.0 spec/matchers.rb
beaker-1.12.2 spec/matchers.rb
beaker-1.12.1 spec/matchers.rb
beaker-1.12.0 spec/matchers.rb
beaker-1.11.2 spec/matchers.rb
beaker-1.11.1 spec/matchers.rb
beaker-1.11.0 spec/matchers.rb
beaker-1.10.0 spec/matchers.rb
beaker-1.9.1 spec/matchers.rb
beaker-1.9.0 spec/matchers.rb
beaker-1.8.2 spec/matchers.rb
beaker-1.8.1 spec/matchers.rb
beaker-1.8.0 spec/matchers.rb
beaker-1.7.0 spec/matchers.rb
beaker-1.6.2 spec/matchers.rb