spec/branch_shared_examples.rb in compo-0.4.0 vs spec/branch_shared_examples.rb in compo-0.5.0

- old
+ new

@@ -1,10 +1,10 @@ require 'url_finder_shared_examples' require 'url_referenceable_shared_examples' require 'movable_shared_examples' -shared_examples 'a branch' do +RSpec.shared_examples 'a branch' do it_behaves_like 'a URL referenceable object' it_behaves_like 'a movable object' describe '#initialize' do it 'initialises with a Parentless as parent' do @@ -14,31 +14,34 @@ it 'initialises with an ID function returning nil' do expect(subject.id).to be_nil end end + shared_context 'the branch has a parent' do + let(:parent) { Compo::Branches::Hash.new } + before(:each) { subject.move_to(parent, :id) } + end + describe '#url' do context 'when the Branch has no parent' do it 'returns the empty string' do expect(subject.url).to eq('') end end context 'when the Branch is the child of a root' do - let(:parent) { Compo::Branches::Hash.new } - before(:each) { subject.move_to(parent, :id) } + include_context 'the branch has a parent' it 'returns /ID, where ID is the ID of the Branch' do expect(subject.url).to eq('/id') end end end describe '#move_to' do context 'when the Branch has a parent' do context 'when the new parent is nil' do - let(:parent) { Compo::Branches::Hash.new } - before(:each) { subject.move_to(parent, :id) } + include_context 'the branch has a parent' it 'loses its previous parent' do expect(subject.move_to(nil, :id).parent).to be_a( Compo::Composites::Parentless ) @@ -51,10 +54,10 @@ end end end end -shared_examples 'a branch with children' do +RSpec.shared_examples 'a branch with children' do it_behaves_like 'a branch' describe '#find_url' do it_behaves_like 'a URL finding' do let(:target) { Compo::Branches::Leaf.new }