Sha256: 1164aab424bed79825742bdbf48b4bfc9e61658d111493c227272d8555e43709
Contents?: true
Size: 1.98 KB
Versions: 2
Compression:
Stored size: 1.98 KB
Contents
# frozen_string_literal: true require 'spec_helper' require 'windcharger/attributes' describe Windcharger::Attributes do it "attributes is an empty array by default" do transformer_class = Class.new { extend Windcharger::Attributes } expect(transformer_class.attributes).to eq [] end it "attribute is private" do transformer_class = Class.new { extend Windcharger::Attributes } expect { transformer_class.attribute }.to raise_error NoMethodError, /private/ end it "adds attributes to the list, not affecting the next method added, when attribute is called with params" do transformer_class = Class.new do extend Windcharger::Attributes attribute :foo, :bar def baz; end end expect(transformer_class.attributes).to eq [:foo, :bar] end it "does not add a method to attributes when its def is not preceded by a call to attribute" do transformer_class = Class.new do extend Windcharger::Attributes def foo; end end expect(transformer_class.attributes).to eq [] end it "adds a method to attributes when its def is preceded by a call to attribute" do transformer_class = Class.new do extend Windcharger::Attributes attribute def foo; end end expect(transformer_class.attributes).to eq [:foo] end it "appropriately does and does not add multiple methods" do transformer_class = Class.new do extend Windcharger::Attributes attribute def foo; end def bar; end def baz; end attribute def qux; end attribute def foobar; end def barbaz; end end expect(transformer_class.attributes).to eq [:foo, :qux, :foobar] end it "does not permit mutating attributes indirectly" do transformer_class = Class.new do extend Windcharger::Attributes attribute def foo; end end expect { transformer_class.attributes << :bar }.to raise_error FrozenError expect(transformer_class.attributes).to eq [:foo] end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
windcharger-0.5.0 | spec/windcharger/attributes_spec.rb |
windcharger-0.4.0 | spec/windcharger/attributes_spec.rb |