Sha256: 8a51f563d4d5a6dfe0f45815bc47d5e33c6e733452c94cd7d46782ca061844d1

Contents?: true

Size: 635 Bytes

Versions: 1

Compression:

Stored size: 635 Bytes

Contents

RSpec::Matchers.define :have_attribute do |attribute|
  match do |model|
    if model.respond_to?(attribute) and model.respond_to?("#{attribute}=")
      obj = Object.new
      old = model.send(attribute)
      model.send("#{attribute}=", obj)
      result = (model.attributes[attribute] == obj)
      model.send("#{attribute}=", old)
      result
    else
      false
    end
  end

  failure_message_for_should do |model|
    "#{model.class} should have attribute accessor #{attribute.inspect}"
  end

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

Version data entries

1 entries across 1 versions & 1 rubygems

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