# encoding: utf-8 describe ServiceObjects::Invalid do let(:messages) { double :messages } let(:object) { double :object, messages: messages } subject { described_class.new object } describe ".new" do context "without arguments" do subject { described_class.new } it "fails with ArgumentError" do expect { subject }.to raise_error ArgumentError end end context "with an object that doesn't responds to :messages" do let(:object) { double } subject { described_class.new object } it "fails with TypeError" do expect { subject }.to raise_error TypeError end it "returns a proper message" do begin subject rescue => err expect(err.message) .to eq "#{ object.inspect } doesn't respond to #messages" end end end context "with an object that responds to :messages" do it "doesn't fail" do expect { subject }.not_to raise_error end it "initializes a RuntimeError" do expect(subject).to be_kind_of RuntimeError end end end describe "#object" do it "is initialized" do expect(subject.object).to eq object end end describe "#messages" do it "returns an array" do expect(subject.messages).to be_kind_of Array end it "is delegated to the #object" do expect(subject.messages).to contain_exactly object.messages end end end