Sha256: b96b384ccbbeb18a44ff6df3c6c9581f382c53834ae960ad1cc2cd53d88fda8a

Contents?: true

Size: 776 Bytes

Versions: 1

Compression:

Stored size: 776 Bytes

Contents

# http://solnic.eu/2011/01/14/custom-rspec-2-matchers.html
RSpec::Matchers.define :have_errors_on do |attribute|
  chain :with_message do |message|
    @message = message
  end

  match do |model|
    model.valid?

    @has_errors = !(model.errors[attribute].blank?)

    if @message
      @has_errors && model.errors[attribute].include?(@message)
    else
      @has_errors
    end
  end

  failure_message_for_should do |model|
    if @message
      "Validation errors #{model.errors[attribute].inspect} should include #{@message.inspect}"
    else
      "#{model.class} should have errors on attribute #{attribute.inspect}"
    end
  end

  failure_message_for_should_not do |model|
    "#{model.class} should not have an error on attribute #{attribute.inspect}"
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
circuit-0.2.0 spec/support/matchers/have_errors_on_matcher.rb