Sha256: 5557576fcfe08d42ea251e445791afde2869427a767ba64ddf0f64064b951ebc

Contents?: true

Size: 1.06 KB

Versions: 23

Compression:

Stored size: 1.06 KB

Contents

require 'pathway/rspec/matchers/form_schema_helpers'

RSpec::Matchers.define :require_fields do |*fields|
  match do |form|
    @form, @fields = form, fields

    not_defined.empty? && not_required.empty?
  end

  match_when_negated do |form|
    @form, @fields = form, fields

    not_defined.empty? && required.empty?
  end

  description do
    "require #{field_list} as #{pluralize_fields}"
  end

  failure_message do
    "Expected to require #{field_list} as #{pluralize_fields} but " +
      [not_required_list, not_defined_list].compact.join("; and ")
  end

  failure_message_when_negated do
    "Did not expect to require #{field_list} as #{pluralize_fields} but " +
      [required_list, not_defined_list].compact.join("; and ")
  end

  include Pathway::Rspec::FormSchemaHelpers

  def required_list
    "#{as_list(required)} #{were_was(required)} required" if required.any?
  end

  def not_required_list
    "#{as_list(not_required)} #{were_was(not_required)} not required" if not_required.any?
  end
end

RSpec::Matchers.alias_matcher :require_field, :require_fields

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
pathway-0.10.0 lib/pathway/rspec/matchers/require_fields.rb
pathway-0.9.1 lib/pathway/rspec/matchers/require_fields.rb
pathway-0.9.0 lib/pathway/rspec/matchers/require_fields.rb
pathway-0.8.0 lib/pathway/rspec/matchers/require_fields.rb
pathway-0.7.0 lib/pathway/rspec/matchers/require_fields.rb
pathway-0.6.2 lib/pathway/rspec/matchers/require_fields.rb
pathway-0.6.1 lib/pathway/rspec/matchers/require_fields.rb
pathway-0.6.0 lib/pathway/rspec/matchers/require_fields.rb
pathway-0.5.1 lib/pathway/rspec/matchers/require_fields.rb
pathway-0.5.0 lib/pathway/rspec/matchers/require_fields.rb
pathway-0.4.0 lib/pathway/rspec/matchers/require_fields.rb
pathway-0.0.20 lib/pathway/rspec/matchers/require_fields.rb
pathway-0.0.19 lib/pathway/rspec/matchers/require_fields.rb
pathway-0.0.18 lib/pathway/rspec/matchers/require_fields.rb
pathway-0.0.17 lib/pathway/rspec/matchers/require_fields.rb
pathway-0.0.16 lib/pathway/rspec/matchers/require_fields.rb
pathway-0.0.15 lib/pathway/rspec/matchers/require_fields.rb
pathway-0.0.14 lib/pathway/rspec/matchers/require_fields.rb
pathway-0.0.13 lib/pathway/rspec/matchers/require_fields.rb
pathway-0.0.12 lib/pathway/rspec/matchers/require_fields.rb