Sha256: c351e9f1b07322e9e5e50212e193830684d6df36196c930d7ac7fb7c8e9a02fd

Contents?: true

Size: 693 Bytes

Versions: 4

Compression:

Stored size: 693 Bytes

Contents

# frozen_string_literal: true

module Clowne
  module RSpec
    module Helpers # :nodoc: all
      attr_reader :cloner

      def with_traits(*traits)
        @traits = traits
        self
      end

      def matches?(actual)
        raise ArgumentError, non_cloner_message unless actual <= ::Clowne::Cloner

        @cloner = actual
        super
      end

      def plan
        @plan ||=
          if @traits.nil?
            cloner.default_plan
          else
            cloner.plan_with_traits(@traits)
          end
      end

      def non_cloner_message
        "expected a cloner to be passed to `expect(...)`, " \
        "but got #{actual_formatted}"
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
clowne-1.5.0 lib/clowne/rspec/helpers.rb
clowne-1.4.0 lib/clowne/rspec/helpers.rb
clowne-1.3.0 lib/clowne/rspec/helpers.rb
clowne-1.2.0 lib/clowne/rspec/helpers.rb