Sha256: fbdb1c76382d644ccda1b7e3af72846415ca35c1758b4e31930604fdd617ab13

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

module RSpec
  module Grape
    module Entity
      module Matchers
        module HaveFormattingMatcher
          extend RSpec::Matchers::DSL

          matcher :have_formatting do |expected|
            include MatcherHelpers

            match do |actual|
              if actual.is_a? ::Grape::Entity::Exposure::FormatterBlockExposure
                instance = entity.new object
                actual.value(instance, {}) == expected
              else
                exposure_attribute(actual, :format_with) == expected
              end
            end

            description { "have the formatting #{expected}" }

            failure_message do |actual|
              if actual.is_a? ::Grape::Entity::Exposure::FormatterBlockExposure
                instance = entity.new object
                "expect that \"#{actual.value instance, {}}\" would have the formatting \"#{expected}\""
              else
                "expect that \"#{actual}\" would have the formatting \"#{expected}\""
              end
            end

            chain :with_object, :object
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rspec-grape-entity-0.1.0 lib/rspec_grape_entity/matchers/have_formatting_matcher.rb