Sha256: 223cddf6e8b6d798a3ab60e96759e1daa93bdde54bb22af76ef797892ea30953

Contents?: true

Size: 827 Bytes

Versions: 1

Compression:

Stored size: 827 Bytes

Contents

require 'object_protocol'

require 'rspec/core'
require 'rspec/expectations'

class SatisfactionAttemptVerifier
  def initialize(&blk)
    @blk = blk
  end

  def matches?(protocol)
    @protocol = protocol
    @attempt  = ObjectProtocol::SatisfactionAttempt.new(protocol, &blk)

    attempt.to_bool
  end

  def failure_message
    [
      "expected",
      protocol.to_rspec_matcher_failure_message_lines.map(&"  ".method(:+)).flatten,
      "to be satisfied by",
      attempt.to_rspec_matcher_failure_message_lines.map(&"  ".method(:+)).flatten,
    ].join("\n")
  end

  private

  attr_reader :blk, :protocol, :attempt
end

module ObjectProtocol::RSpecMatchers
  def be_satisfied_by(&blk)
    SatisfactionAttemptVerifier.new(&blk)
  end
end

RSpec.configure do |config|
  config.include ObjectProtocol::RSpecMatchers
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
object_protocol-0.1.0 lib/object_protocol/rspec.rb