Sha256: 5648c91e2ebd930d4e939e452c83543d643548ccb4094c15eced40e53c9eb3c1

Contents?: true

Size: 860 Bytes

Versions: 7

Compression:

Stored size: 860 Bytes

Contents

module CustomMatchers
  rspec = defined?(RSpec) ? RSpec : Spec

  rspec::Matchers.define :contain_with_wildcards do |expected_string|
    match do |field_value|
      @field_value = field_value.to_s
      @expected_string = expected_string
      regex_parts = expected_string.to_s.split('*', -1).collect { |part| Regexp.escape(part) }

      @field_value =~ /\A#{regex_parts.join(".*")}\z/m
    end

    failure_message_for_should do
      "The field's content #{@field_value.inspect} did not match #{@expected_string.inspect}"
    end

    failure_message_for_should_not do
      "The field's content #{@field_value.inspect} matches #{@expected_string.inspect}"
    end
  end

  rspec::Matchers.define :be_sorted do
  match do |array|
    sort_method = defined?(array.natural_sort) ? :natural_sort : :sort

    array == array.send(sort_method)
  end
end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
spreewald-1.2.6 lib/spreewald_support/custom_matchers.rb
spreewald-1.2.5 lib/spreewald_support/custom_matchers.rb
spreewald-1.2.4 lib/spreewald_support/custom_matchers.rb
spreewald-1.2.3 lib/spreewald_support/custom_matchers.rb
spreewald-1.2.2 lib/spreewald_support/custom_matchers.rb
spreewald-1.2.1 lib/spreewald_support/custom_matchers.rb
spreewald-1.2.0 lib/spreewald_support/custom_matchers.rb