Sha256: b0ba5d0efd8436993dc40befcfc06df22befc995fc4dc20b9122a853604e0c41

Contents?: true

Size: 805 Bytes

Versions: 5

Compression:

Stored size: 805 Bytes

Contents

module JsonSpec
  module Matchers
    class HaveJsonSize
      include JsonSpec::Helpers
      include JsonSpec::Messages

      def initialize(size)
        @expected = size
      end

      def matches?(json)
        ruby = parse_json(json, @path)
        @actual = Enumerable === ruby ? ruby.size : 1
        @actual == @expected
      end

      def at_path(path)
        @path = path
        self
      end

      def failure_message_for_should
        message_with_path("Expected JSON value size to be #{@expected}, got #{@actual}")
      end

      def failure_message_for_should_not
        message_with_path("Expected JSON value size to not be #{@expected}, got #{@actual}")
      end

      def description
        message_with_path(%(have JSON size "#{@expected}"))
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
json_spec-1.1.1 lib/json_spec/matchers/have_json_size.rb
json_spec-1.1.0 lib/json_spec/matchers/have_json_size.rb
json_spec-1.0.3 lib/json_spec/matchers/have_json_size.rb
json_spec-1.0.2 lib/json_spec/matchers/have_json_size.rb
json_spec-1.0.0 lib/json_spec/matchers/have_json_size.rb