lib/loquor/resource_mock.rb in loquor-0.5.4 vs lib/loquor/resource_mock.rb in loquor-0.6.0
- old
+ new
@@ -7,11 +7,11 @@
if name[-1] == "="
if self.class.attributes.keys.map{ |k| :"#{k}=" }.include?(name)
attr = name.to_s[0..-2].to_sym
@data[attr] = args[0]
else
- raise NameError.new("undefined local variable or method '#{name}' for Resource Mock")
+ raise NameError.new("undefined local variable or method '#{name}' for #{self.class.name}")
end
else
super(name, *args)
end
end
@@ -25,9 +25,13 @@
def attributes=(attrs)
@attributes = attrs
end
def sample(overrides = {})
+ arbitary_attributes = (overrides.keys - attributes.keys)
+ unless arbitary_attributes.empty?
+ raise NameError.new("undefined local variable or method '#{arbitary_attributes.first}' for #{self.name}")
+ end
self.new(attributes.merge(overrides))
end
def find(id)
self.new(attributes.merge(id: id))