Sha256: 94c88dfaa6d690f8fda465ff149b2575340f83a005b5a366868947c7322bab0d
Contents?: true
Size: 1.58 KB
Versions: 1
Compression:
Stored size: 1.58 KB
Contents
require_relative "spec_helper" describe Object, ".attr_implement" do it "creates 0-argument methods that raise" do klass = Class.new do attr_implement :foo, :bar end example = klass.new exception = lambda { example.foo }.must_raise AttrExtras::MethodNotImplementedError exception.message.must_equal "Implement a 'foo()' method" end it "allows specifying arity and argument names" do klass = Class.new do attr_implement :foo, [:name, :age] end example = klass.new exception = lambda { example.foo(1, 2) }.must_raise AttrExtras::MethodNotImplementedError exception.message.must_equal "Implement a 'foo(name, age)' method" lambda { example.foo }.must_raise ArgumentError end it "does not raise if method is implemented in a subclass" do klass = Class.new do attr_implement :foo end subklass = Class.new(klass) do def foo "bar" end end subklass.new.foo.must_equal "bar" end # E.g. when Active Record defines column query methods like "admin?" # higher up in the ancestor chain. it "does not raise if method is implemented in a superclass" do foo_interface = Module.new do attr_implement :foo end superklass = Class.new do def foo "bar" end end klass = Class.new(superklass) do include foo_interface end klass.new.foo.must_equal "bar" end it "does not mess up missing-method handling" do klass = Class.new do attr_implement :foo end lambda { klass.new.some_other_method }.must_raise NoMethodError end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
attr_extras-4.3.0 | spec/attr_implement_spec.rb |