Sha256: dfe1b46a3ee22d6b40d1a526f2b95eab231dc4b03f3b99241147be883083e653

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

require 'rspec/matchers'
require 'rspec/expectations'
require 'rspec/collection_matchers'
require 'smart_rspec/support/regexes'

include SmartRspec::Support::Regexes

module SmartRspec
  module Matchers
    extend RSpec::Matchers::DSL

    matcher :be_boolean do
      match { |actual| [true, false].include?(actual) }
    end

    matcher :be_email do
      match { |actual| actual =~ build_regex(:email) }
    end

    matcher :be_url do
      match { |actual| actual =~ build_regex(:uri) }
    end

    matcher :be_image_url do |*types|
      match { |actual| actual =~ build_regex(:image, types) }
    end

    matcher :have_error_on do |attr|
      match { |actual| actual.errors.keys.include?(attr) }
    end

    matcher :include_items do |*items|
      match { |actual| (items.flatten - [actual].flatten).empty? }
    end

    matcher :be_ascending do
      match { |actual| actual == actual.sort  }
    end

    matcher :be_descending do
      match { |actual| actual.each_cons(2).all? { |i, j| i >= j  } }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
smart_rspec-0.0.1 lib/smart_rspec/matchers.rb