spec/support/field_matcher.rb in netsuite-0.8.9 vs spec/support/field_matcher.rb in netsuite-0.8.10

- old
+ new

@@ -1,18 +1,20 @@ -RSpec::Matchers.define :have_field do |attribute| +RSpec::Matchers.define :have_field do |attribute, klass| match do |model| - field_can_be_set_and_retrieved?(model, attribute) && field_can_be_set_on_instantiation?(model, attribute) + 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) - obj = Object.new + 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) - obj = Object.new + 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