Sha256: cd46cc3b3405e7287255b114533c0497961f8cc9bdaa8b5027494ea4e1962042
Contents?: true
Size: 1.34 KB
Versions: 1
Compression:
Stored size: 1.34 KB
Contents
require "minitest/autorun" require "attr_extras" class Example attr_initialize :foo, :bar attr_private :foo, :bar end class PattrExample pattr_initialize :foo, :bar end class QueryExample attr_id_query :baz?, :boink? attr_accessor :baz_id end describe Object, ".attr_initialize" do it "creates an initializer setting those instance variables" do example = Example.new("Foo", "Bar") example.instance_variable_get("@foo").must_equal "Foo" example.instance_variable_get("@bar").must_equal "Bar" end it "requires all arguments" do lambda { Example.new("Foo") }.must_raise ArgumentError end end describe Object, ".attr_private" do it "creates private readers" do example = Example.new("Foo", "Bar") example.send(:foo).must_equal "Foo" example.send(:bar).must_equal "Bar" lambda { example.foo }.must_raise NoMethodError end end describe Object, ".pattr_initialize" do it "creates both initializer and private readers" do example = PattrExample.new("Foo", "Bar") example.send(:foo).must_equal "Foo" end end describe Object, ".attr_id_query" do it "creates id query methods" do example = QueryExample.new refute example.baz? example.baz_id = 123 assert example.baz? end it "requires a trailing questionmark" do lambda { Object.attr_id_query(:foo) }.must_raise RuntimeError end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
attr_extras-1.1.0 | spec/attr_extras_spec.rb |