spec/codependency/graph_spec.rb in codependency-1.0.0 vs spec/codependency/graph_spec.rb in codependency-2.0.0
- old
+ new
@@ -1,74 +1,112 @@
require 'spec_helper'
describe Codependency::Graph do
- describe 'accessors' do
- subject { described_class.new 'planets/phobos.rb' }
- its( :path ){ should eq( 'planets/phobos.rb' ) }
- its( :dirname ){ should eq( 'planets' ) }
- its( :extname ){ should eq( '.rb' ) }
- its( :options ){ should eq( { } ) }
+ it { should be_a( Hash ) }
+
+ describe '#path' do
+ its( :path ){ should be_a( Codependency::Path ) }
+ its( :path ){ should be_empty }
end
- describe 'populate', :files => :planets do
- subject { described_class.new './phobos.rb' }
+ describe '#require' do
+ let( :dirname ){ example.example_group.description }
+ let( :basename ){ example.description }
+ let( :file ){ File.join dirname, basename }
- context 'initially' do
- it { should be_empty }
- end
+ before { subject.path << './spec/fixtures' }
+ before { subject << file }
- context 'after calling populate' do
- before { subject.populate }
-
- it { should include( './phobos.rb' => [ './body.rb', './mars.rb' ] ) }
- it { should include( './mars.rb' => [ './planet.rb' ] ) }
- it { should include( './planet.rb' => [ './body.rb' ] ) }
- it { should include( './body.rb' => [ ] ) }
+ describe 'solar_system' do
+ example( 'body' ){ verify { subject } }
+ example( 'earth' ){ verify { subject } }
+ example( 'mars' ){ verify { subject } }
+ example( 'phobos' ){ verify { subject } }
+ example( 'planet' ){ verify { subject } }
end
-
- it 'should return itself' do
- subject.populate.should == subject
+ describe 'breakfast' do
+ example( 'butter' ){ verify { subject } }
+ example( 'egg' ){ verify { subject } }
+ example( 'sandwich' ){ verify { subject } }
+ example( 'toast' ){ verify { subject } }
end
- end
-
- context 'planets', :files => :planets do
- subject { described_class.new start }
-
- context 'earth' do
- let( :start ){ './earth.rb' }
- its( :files ){ should eq( %w| ./body.rb ./planet.rb ./earth.rb | ) }
+ describe 'lox' do
+ example( 'money' ){ verify { subject } }
+ example( 'power' ){ verify { subject } }
+ example( 'respect' ){ verify { subject } }
end
-
- context 'phobos' do
- let( :start ){ './phobos.rb' }
- its( :files ){ should eq( %w| ./body.rb ./planet.rb ./mars.rb ./phobos.rb | ) }
+ describe 'assets' do
+ example( 'templates/account' ){ verify { subject } }
+ example( 'templates/history' ){ verify { subject } }
+ example( 'templates/user' ){ verify { subject } }
+ example( 'application' ){ verify { subject } }
end
end
- context 'breakfasts', :files => :breakfasts do
- subject { described_class.new start, :comment => '//' }
+ describe '#tsort' do
+ let( :dirname ){ example.example_group.description }
+ let( :basename ){ example.description }
+ let( :file ){ File.join dirname, basename }
- context 'sandwich' do
- let( :start ){ './sandwich.js' }
- its( :files ){ should eq( %w| ./butter.js ./egg.js ./toast.js ./sandwich.js | ) }
+ before { subject.path << './spec/fixtures' }
+ before { subject << file }
+
+ describe 'solar_system' do
+ example( 'body' ){ verify { subject.tsort } }
+ example( 'earth' ){ verify { subject.tsort } }
+ example( 'mars' ){ verify { subject.tsort } }
+ example( 'phobos' ){ verify { subject.tsort } }
+ example( 'planet' ){ verify { subject.tsort } }
end
+ describe 'breakfast' do
+ example( 'butter' ){ verify { subject.tsort } }
+ example( 'egg' ){ verify { subject.tsort } }
+ example( 'sandwich' ){ verify { subject.tsort } }
+ example( 'toast' ){ verify { subject.tsort } }
+ end
+ describe 'lox' do
+ example( 'money' ){ expect { subject.tsort }.to raise_error( TSort::Cyclic ) }
+ example( 'power' ){ expect { subject.tsort }.to raise_error( TSort::Cyclic ) }
+ example( 'respect' ){ expect { subject.tsort }.to raise_error( TSort::Cyclic ) }
+ end
+ describe 'assets' do
+ example( 'templates/account' ){ verify { subject.tsort } }
+ example( 'templates/history' ){ verify { subject.tsort } }
+ example( 'templates/user' ){ verify { subject.tsort } }
+ example( 'application' ){ verify { subject.tsort } }
+ end
end
- context 'circular dependencies', :files => :circular do
- subject { described_class.new start }
+ describe '#files' do
+ let( :dirname ){ example.example_group.description }
+ let( :basename ){ example.description }
+ let( :file ){ File.join dirname, basename }
- let( :start ){ './money.rb' }
+ before { subject.path << './spec/fixtures' }
+ before { subject << file }
- it 'should raise an error' do
- expect { subject.files }.to raise_error( TSort::Cyclic )
+ describe 'solar_system' do
+ example( 'body' ){ verify { subject.files } }
+ example( 'earth' ){ verify { subject.files } }
+ example( 'mars' ){ verify { subject.files } }
+ example( 'phobos' ){ verify { subject.files } }
+ example( 'planet' ){ verify { subject.files } }
end
- end
-
- context 'subdirectories', :files => :subdirectories do
- subject { described_class.new start, :comment => '//' }
-
- context 'application.js' do
- let( :start ){ 'assets/application.js' }
- its( :files ){ should eq( %w| assets/templates/user/history.js assets/templates/user/account.js assets/templates/user.js assets/application.js | ) }
+ describe 'breakfast' do
+ example( 'butter' ){ verify { subject.files } }
+ example( 'egg' ){ verify { subject.files } }
+ example( 'sandwich' ){ verify { subject.files } }
+ example( 'toast' ){ verify { subject.files } }
+ end
+ describe 'lox' do
+ example( 'money' ){ expect { subject.tsort }.to raise_error( TSort::Cyclic ) }
+ example( 'power' ){ expect { subject.tsort }.to raise_error( TSort::Cyclic ) }
+ example( 'respect' ){ expect { subject.tsort }.to raise_error( TSort::Cyclic ) }
+ end
+ describe 'assets' do
+ example( 'templates/account' ){ verify { subject.files } }
+ example( 'templates/history' ){ verify { subject.files } }
+ example( 'templates/user' ){ verify { subject.files } }
+ example( 'application' ){ verify { subject.files } }
end
end
end