Sha256: 5dc1dc2b30f5d05e9097a92b66d57108fcee1d2115f0b2d2f75b02ffc26573e3

Contents?: true

Size: 588 Bytes

Versions: 7

Compression:

Stored size: 588 Bytes

Contents

RSpec::Matchers.define :have_field do |attribute, klass|

  match do |model|
    klass = klass || Object

    field_can_be_set_and_retrieved?(model, attribute, klass) && field_can_be_set_on_instantiation?(model, attribute, klass)
  end

  def field_can_be_set_and_retrieved?(model, attribute, klass)
    obj = klass.new
    model.send("#{attribute}=".to_sym, obj)
    model.send(attribute) == obj
  end

  def field_can_be_set_on_instantiation?(model, attribute, klass)
    obj = klass.new
    new_model = model.class.new(attribute => obj)
    new_model.send(attribute) == obj
  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
netsuite-0.9.3 spec/support/field_matcher.rb
netsuite-0.9.2 spec/support/field_matcher.rb
netsuite-0.9.1 spec/support/field_matcher.rb
netsuite-0.9.0 spec/support/field_matcher.rb
netsuite-0.8.12 spec/support/field_matcher.rb
netsuite-0.8.11 spec/support/field_matcher.rb
netsuite-0.8.10 spec/support/field_matcher.rb