Sha256: 37de3f2f7a7c848c36be482aaed495ef3bd389cb855341e42bb3c1685f97b829
Contents?: true
Size: 1.66 KB
Versions: 1
Compression:
Stored size: 1.66 KB
Contents
require 'spec_helper' describe Arbre::HTML::Tag, "Attributes" do let(:tag){ Arbre::HTML::Tag.new } describe "attributes" do before { tag.build :id => "my_id" } it "should have an attributes hash" do expect(tag.attributes).to eq({:id => "my_id"}) end it "should render the attributes to html" do expect(tag.to_s).to eq "<tag id=\"my_id\"></tag>\n" end it "shouldn't render attributes that are empty" do tag.class_list # initializes an empty ClassList tag.set_attribute :foo, '' tag.set_attribute :bar, nil expect(tag.to_s).to eq "<tag id=\"my_id\"></tag>\n" end it "should get an attribute value" do expect(tag.attr(:id)).to eq("my_id") end describe "#has_attribute?" do context "when the attribute exists" do it "should return true" do expect(tag.has_attribute?(:id)).to eq(true) end end context "when the attribute does not exist" do it "should return false" do expect(tag.has_attribute?(:class)).to eq(false) end end end it "should remove an attribute" do expect(tag.attributes).to eq({:id => "my_id"}) expect(tag.remove_attribute(:id)).to eq("my_id") expect(tag.attributes).to eq({}) end end describe "rendering attributes" do it "should html safe the attribute values" do tag.set_attribute(:class, '">bad things!') expect(tag.to_s).to eq "<tag class=\"">bad things!\"></tag>\n" end it "should should escape the attribute names" do tag.set_attribute(">bad", "things") expect(tag.to_s).to eq "<tag >bad=\"things\"></tag>\n" end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
arbre-1.0.2 | spec/arbre/unit/html/tag_attributes_spec.rb |