diaspora_federation/spec/support/shared_entity_specs.rb
2015-09-27 03:17:45 +02:00

39 lines
954 B
Ruby

shared_examples "an Entity subclass" do
it "should be an Entity" do
expect(klass).to be < DiasporaFederation::Entity
end
it "has its properties set" do
expect(klass.class_prop_names).to include(*data.keys)
end
context "behaviour" do
let(:instance) { klass.new(data) }
describe "initialize" do
it "must not create blank instances" do
expect { klass.new({}) }.to raise_error ArgumentError
end
it "fails if nil was given" do
expect { klass.new(nil) }.to raise_error ArgumentError, "expected a Hash"
end
it "should be frozen" do
expect(instance).to be_frozen
end
end
describe "#to_h" do
it "should resemble the input data" do
expect(instance.to_h).to eq(data)
end
end
describe "#to_xml" do
it "produces correct XML" do
expect(instance.to_xml.to_s.strip).to eq(xml.strip) unless xml.nil?
end
end
end
end