codependency 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. data/Guardfile +4 -4
  2. data/README.md +7 -4
  3. data/codependency.gemspec +6 -4
  4. data/lib/codependency.rb +1 -0
  5. data/lib/codependency/graph.rb +27 -34
  6. data/lib/codependency/parser.rb +11 -15
  7. data/lib/codependency/path.rb +53 -0
  8. data/lib/codependency/version.rb +1 -1
  9. data/spec/codependency/graph_spec.rb +89 -51
  10. data/spec/codependency/graph_spec/codependency_graph/files/assets/application.txt +6 -0
  11. data/spec/codependency/graph_spec/codependency_graph/files/assets/templates_account.txt +3 -0
  12. data/spec/codependency/graph_spec/codependency_graph/files/assets/templates_history.txt +3 -0
  13. data/spec/codependency/graph_spec/codependency_graph/files/assets/templates_user.txt +5 -0
  14. data/spec/codependency/graph_spec/codependency_graph/files/breakfast/butter.txt +3 -0
  15. data/spec/codependency/graph_spec/codependency_graph/files/breakfast/egg.txt +4 -0
  16. data/spec/codependency/graph_spec/codependency_graph/files/breakfast/sandwich.txt +6 -0
  17. data/spec/codependency/graph_spec/codependency_graph/files/breakfast/toast.txt +4 -0
  18. data/spec/codependency/graph_spec/codependency_graph/files/solar_system/body.txt +3 -0
  19. data/spec/codependency/graph_spec/codependency_graph/files/solar_system/earth.txt +5 -0
  20. data/spec/codependency/graph_spec/codependency_graph/files/solar_system/mars.txt +5 -0
  21. data/spec/codependency/graph_spec/codependency_graph/files/solar_system/phobos.txt +6 -0
  22. data/spec/codependency/graph_spec/codependency_graph/files/solar_system/planet.txt +4 -0
  23. data/spec/codependency/graph_spec/codependency_graph/require/assets/application.txt +11 -0
  24. data/spec/codependency/graph_spec/codependency_graph/require/assets/templates_account.txt +3 -0
  25. data/spec/codependency/graph_spec/codependency_graph/require/assets/templates_history.txt +3 -0
  26. data/spec/codependency/graph_spec/codependency_graph/require/assets/templates_user.txt +8 -0
  27. data/spec/codependency/graph_spec/codependency_graph/require/breakfast/butter.txt +3 -0
  28. data/spec/codependency/graph_spec/codependency_graph/require/breakfast/egg.txt +6 -0
  29. data/spec/codependency/graph_spec/codependency_graph/require/breakfast/sandwich.txt +13 -0
  30. data/spec/codependency/graph_spec/codependency_graph/require/breakfast/toast.txt +6 -0
  31. data/spec/codependency/graph_spec/codependency_graph/require/lox/money.txt +11 -0
  32. data/spec/codependency/graph_spec/codependency_graph/require/lox/power.txt +11 -0
  33. data/spec/codependency/graph_spec/codependency_graph/require/lox/respect.txt +11 -0
  34. data/spec/codependency/graph_spec/codependency_graph/require/solar_system/body.txt +3 -0
  35. data/spec/codependency/graph_spec/codependency_graph/require/solar_system/earth.txt +9 -0
  36. data/spec/codependency/graph_spec/codependency_graph/require/solar_system/mars.txt +9 -0
  37. data/spec/codependency/graph_spec/codependency_graph/require/solar_system/phobos.txt +13 -0
  38. data/spec/codependency/graph_spec/codependency_graph/require/solar_system/planet.txt +6 -0
  39. data/spec/codependency/graph_spec/codependency_graph/tsort/assets/application.txt +6 -0
  40. data/spec/codependency/graph_spec/codependency_graph/tsort/assets/templates_account.txt +3 -0
  41. data/spec/codependency/graph_spec/codependency_graph/tsort/assets/templates_history.txt +3 -0
  42. data/spec/codependency/graph_spec/codependency_graph/tsort/assets/templates_user.txt +5 -0
  43. data/spec/codependency/graph_spec/codependency_graph/tsort/breakfast/butter.txt +3 -0
  44. data/spec/codependency/graph_spec/codependency_graph/tsort/breakfast/egg.txt +4 -0
  45. data/spec/codependency/graph_spec/codependency_graph/tsort/breakfast/sandwich.txt +6 -0
  46. data/spec/codependency/graph_spec/codependency_graph/tsort/breakfast/toast.txt +4 -0
  47. data/spec/codependency/graph_spec/codependency_graph/tsort/solar_system/body.txt +3 -0
  48. data/spec/codependency/graph_spec/codependency_graph/tsort/solar_system/earth.txt +5 -0
  49. data/spec/codependency/graph_spec/codependency_graph/tsort/solar_system/mars.txt +5 -0
  50. data/spec/codependency/graph_spec/codependency_graph/tsort/solar_system/phobos.txt +6 -0
  51. data/spec/codependency/graph_spec/codependency_graph/tsort/solar_system/planet.txt +4 -0
  52. data/spec/codependency/parser_spec.rb +48 -40
  53. data/spec/codependency/path_spec.rb +55 -0
  54. data/spec/fixtures/assets/application.js +1 -0
  55. data/spec/fixtures/assets/templates/account.js +1 -0
  56. data/spec/fixtures/assets/templates/history.js +1 -0
  57. data/spec/fixtures/assets/templates/user.js +4 -0
  58. data/spec/fixtures/breakfast/butter.js +1 -0
  59. data/spec/fixtures/breakfast/egg.js +3 -0
  60. data/spec/fixtures/breakfast/sandwich.js +4 -0
  61. data/spec/fixtures/breakfast/toast.js +3 -0
  62. data/spec/fixtures/lox/money.rb +4 -0
  63. data/spec/fixtures/lox/power.rb +4 -0
  64. data/spec/fixtures/lox/respect.rb +4 -0
  65. data/spec/fixtures/solar_system/body.rb +2 -0
  66. data/spec/fixtures/solar_system/earth.rb +4 -0
  67. data/spec/fixtures/solar_system/mars.rb +4 -0
  68. data/spec/fixtures/solar_system/phobos.rb +5 -0
  69. data/spec/fixtures/solar_system/planet.rb +4 -0
  70. data/spec/spec_helper.rb +5 -2
  71. data/spec/support/approvals.rb +1 -0
  72. metadata +146 -17
  73. data/spec/support/breakfasts_context.rb +0 -24
  74. data/spec/support/circular_context.rb +0 -25
  75. data/spec/support/file_system_stubs.rb +0 -10
  76. data/spec/support/planets_context.rb +0 -38
  77. data/spec/support/subdirectories_context.rb +0 -21
@@ -0,0 +1,4 @@
1
+ [
2
+ [0] #<Pathname:../../fixtures/breakfast/butter.js>,
3
+ [1] #<Pathname:../../fixtures/breakfast/egg.js>
4
+ ]
@@ -0,0 +1,6 @@
1
+ [
2
+ [0] #<Pathname:../../fixtures/breakfast/butter.js>,
3
+ [1] #<Pathname:../../fixtures/breakfast/egg.js>,
4
+ [2] #<Pathname:../../fixtures/breakfast/toast.js>,
5
+ [3] #<Pathname:../../fixtures/breakfast/sandwich.js>
6
+ ]
@@ -0,0 +1,4 @@
1
+ [
2
+ [0] #<Pathname:../../fixtures/breakfast/butter.js>,
3
+ [1] #<Pathname:../../fixtures/breakfast/toast.js>
4
+ ]
@@ -0,0 +1,3 @@
1
+ [
2
+ [0] #<Pathname:../../fixtures/solar_system/body.rb>
3
+ ]
@@ -0,0 +1,5 @@
1
+ [
2
+ [0] #<Pathname:../../fixtures/solar_system/body.rb>,
3
+ [1] #<Pathname:../../fixtures/solar_system/planet.rb>,
4
+ [2] #<Pathname:../../fixtures/solar_system/earth.rb>
5
+ ]
@@ -0,0 +1,5 @@
1
+ [
2
+ [0] #<Pathname:../../fixtures/solar_system/body.rb>,
3
+ [1] #<Pathname:../../fixtures/solar_system/planet.rb>,
4
+ [2] #<Pathname:../../fixtures/solar_system/mars.rb>
5
+ ]
@@ -0,0 +1,6 @@
1
+ [
2
+ [0] #<Pathname:../../fixtures/solar_system/body.rb>,
3
+ [1] #<Pathname:../../fixtures/solar_system/planet.rb>,
4
+ [2] #<Pathname:../../fixtures/solar_system/mars.rb>,
5
+ [3] #<Pathname:../../fixtures/solar_system/phobos.rb>
6
+ ]
@@ -0,0 +1,4 @@
1
+ [
2
+ [0] #<Pathname:../../fixtures/solar_system/body.rb>,
3
+ [1] #<Pathname:../../fixtures/solar_system/planet.rb>
4
+ ]
@@ -0,0 +1,11 @@
1
+ {
2
+ "assets/application" => [
3
+ [0] "assets/templates/user"
4
+ ],
5
+ "assets/templates/user" => [
6
+ [0] "assets/templates/history",
7
+ [1] "assets/templates/account"
8
+ ],
9
+ "assets/templates/history" => [],
10
+ "assets/templates/account" => []
11
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "assets/templates/user" => [
3
+ [0] "assets/templates/history",
4
+ [1] "assets/templates/account"
5
+ ],
6
+ "assets/templates/history" => [],
7
+ "assets/templates/account" => []
8
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "breakfast/egg" => [
3
+ [0] "breakfast/butter"
4
+ ],
5
+ "breakfast/butter" => []
6
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "breakfast/sandwich" => [
3
+ [0] "breakfast/egg",
4
+ [1] "breakfast/toast"
5
+ ],
6
+ "breakfast/egg" => [
7
+ [0] "breakfast/butter"
8
+ ],
9
+ "breakfast/butter" => [],
10
+ "breakfast/toast" => [
11
+ [0] "breakfast/butter"
12
+ ]
13
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "breakfast/toast" => [
3
+ [0] "breakfast/butter"
4
+ ],
5
+ "breakfast/butter" => []
6
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "lox/money" => [
3
+ [0] "lox/power"
4
+ ],
5
+ "lox/power" => [
6
+ [0] "lox/respect"
7
+ ],
8
+ "lox/respect" => [
9
+ [0] "lox/money"
10
+ ]
11
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "lox/power" => [
3
+ [0] "lox/respect"
4
+ ],
5
+ "lox/respect" => [
6
+ [0] "lox/money"
7
+ ],
8
+ "lox/money" => [
9
+ [0] "lox/power"
10
+ ]
11
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "lox/respect" => [
3
+ [0] "lox/money"
4
+ ],
5
+ "lox/money" => [
6
+ [0] "lox/power"
7
+ ],
8
+ "lox/power" => [
9
+ [0] "lox/respect"
10
+ ]
11
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "solar_system/earth" => [
3
+ [0] "solar_system/planet"
4
+ ],
5
+ "solar_system/planet" => [
6
+ [0] "solar_system/body"
7
+ ],
8
+ "solar_system/body" => []
9
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "solar_system/mars" => [
3
+ [0] "solar_system/planet"
4
+ ],
5
+ "solar_system/planet" => [
6
+ [0] "solar_system/body"
7
+ ],
8
+ "solar_system/body" => []
9
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "solar_system/phobos" => [
3
+ [0] "solar_system/body",
4
+ [1] "solar_system/mars"
5
+ ],
6
+ "solar_system/body" => [],
7
+ "solar_system/mars" => [
8
+ [0] "solar_system/planet"
9
+ ],
10
+ "solar_system/planet" => [
11
+ [0] "solar_system/body"
12
+ ]
13
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "solar_system/planet" => [
3
+ [0] "solar_system/body"
4
+ ],
5
+ "solar_system/body" => []
6
+ }
@@ -0,0 +1,6 @@
1
+ [
2
+ [0] "assets/templates/history",
3
+ [1] "assets/templates/account",
4
+ [2] "assets/templates/user",
5
+ [3] "assets/application"
6
+ ]
@@ -0,0 +1,5 @@
1
+ [
2
+ [0] "assets/templates/history",
3
+ [1] "assets/templates/account",
4
+ [2] "assets/templates/user"
5
+ ]
@@ -0,0 +1,4 @@
1
+ [
2
+ [0] "breakfast/butter",
3
+ [1] "breakfast/egg"
4
+ ]
@@ -0,0 +1,6 @@
1
+ [
2
+ [0] "breakfast/butter",
3
+ [1] "breakfast/egg",
4
+ [2] "breakfast/toast",
5
+ [3] "breakfast/sandwich"
6
+ ]
@@ -0,0 +1,4 @@
1
+ [
2
+ [0] "breakfast/butter",
3
+ [1] "breakfast/toast"
4
+ ]
@@ -0,0 +1,5 @@
1
+ [
2
+ [0] "solar_system/body",
3
+ [1] "solar_system/planet",
4
+ [2] "solar_system/earth"
5
+ ]
@@ -0,0 +1,5 @@
1
+ [
2
+ [0] "solar_system/body",
3
+ [1] "solar_system/planet",
4
+ [2] "solar_system/mars"
5
+ ]
@@ -0,0 +1,6 @@
1
+ [
2
+ [0] "solar_system/body",
3
+ [1] "solar_system/planet",
4
+ [2] "solar_system/mars",
5
+ [3] "solar_system/phobos"
6
+ ]
@@ -0,0 +1,4 @@
1
+ [
2
+ [0] "solar_system/body",
3
+ [1] "solar_system/planet"
4
+ ]
@@ -1,49 +1,57 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Codependency::Parser do
4
- context 'planets', :files => :planets do
5
- let( :parser ){ Codependency::Parser.new }
4
+ let( :dirname ){ example.example_group.description }
5
+ let( :basename ){ example.description }
6
+ let( :filename ){ "./spec/fixtures/#{dirname}/#{basename}" }
7
+ let( :file ){ Pathname( filename ) }
6
8
 
7
- context 'body' do
8
- subject { parser.parse( './body.rb' ) }
9
- it { should eq( [ ] ) }
10
- end
11
- context 'earth' do
12
- subject { parser.parse( './earth.rb' ) }
13
- it { should eq( [ './planet.rb' ] ) }
14
- end
15
- context 'mars' do
16
- subject { parser.parse( './mars.rb' ) }
17
- it { should eq( [ './planet.rb' ] ) }
18
- end
19
- context 'phobos' do
20
- subject { parser.parse( './phobos.rb' ) }
21
- it { should eq( [ './body.rb', './mars.rb' ] ) }
22
- end
23
- context 'planet' do
24
- subject { parser.parse( './planet.rb' ) }
25
- it { should eq( [ './body.rb' ] ) }
9
+ # TODO convert these to approvals?
10
+ context 'solar_system' do
11
+ example 'body.rb' do
12
+ subject.parse( file ).should == [ ]
13
+ end
14
+ example 'earth.rb' do
15
+ subject.parse( file ).should == [
16
+ 'solar_system/planet'
17
+ ]
18
+ end
19
+ example 'mars.rb' do
20
+ subject.parse( file ).should == [
21
+ 'solar_system/planet'
22
+ ]
23
+ end
24
+ example 'phobos.rb' do
25
+ subject.parse( file ).should == [
26
+ 'solar_system/body',
27
+ 'solar_system/mars'
28
+ ]
29
+ end
30
+ example 'planet.rb' do
31
+ subject.parse( file ).should == [
32
+ 'solar_system/body'
33
+ ]
26
34
  end
27
35
  end
28
-
29
- context 'breakfasts', :files => :breakfasts do
30
- let( :parser ){ Codependency::Parser.new :comment => '//', :extname => '.js' }
31
-
32
- context 'butter' do
33
- subject { parser.parse( './butter.js' ) }
34
- it { should eq( [ ] ) }
35
- end
36
- context 'egg' do
37
- subject { parser.parse( './egg.js' ) }
38
- it { should eq( [ './butter.js' ] ) }
39
- end
40
- context 'toast' do
41
- subject { parser.parse( './toast.js' ) }
42
- it { should eq( [ './butter.js' ] ) }
43
- end
44
- context 'sandwich' do
45
- subject { parser.parse( './sandwich.js' ) }
46
- it { should eq( [ './egg.js', './toast.js' ] ) }
36
+ context 'breakfast' do
37
+ example 'butter.js' do
38
+ subject.parse( file ).should == [ ]
39
+ end
40
+ example 'egg.js' do
41
+ subject.parse( file ).should == [
42
+ 'breakfast/butter'
43
+ ]
44
+ end
45
+ example 'toast.js' do
46
+ subject.parse( file ).should == [
47
+ 'breakfast/butter'
48
+ ]
49
+ end
50
+ example 'sandwich.js' do
51
+ subject.parse( file ).should == [
52
+ 'breakfast/egg',
53
+ 'breakfast/toast'
54
+ ]
47
55
  end
48
56
  end
49
57
  end
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+
3
+ describe Codependency::Path do
4
+ it { should be_an( Array ) }
5
+
6
+ describe '#extensions' do
7
+ it 'contains ".rb" by default' do
8
+ subject.extensions.should == [ '.rb' ]
9
+ end
10
+ it 'accepts an array' do
11
+ subject = described_class.new [ '.rb', '.js' ]
12
+ subject.extensions.should == [ '.rb', '.js' ]
13
+ end
14
+ it 'accepts a string and turns it into an array' do
15
+ subject = described_class.new '.js'
16
+ subject.extensions.should == [ '.js' ]
17
+ end
18
+ end
19
+
20
+ describe '#<<' do
21
+ it 'turns paths into pathnames' do
22
+ subject << './spec/fixtures'
23
+ subject[ 0 ].should be_a( Pathname )
24
+ end
25
+ it 'expands paths as they are added' do
26
+ subject << './spec/fixtures'
27
+ subject[ 0 ].to_path.should == File.expand_path( './spec/fixtures' )
28
+ end
29
+ it 'raises an exception if the path does not exist' do
30
+ expect { subject << './spec/mixtures' }.to raise_error( Errno::ENOENT )
31
+ end
32
+ it 'raises an exception if the path is not a directory' do
33
+ expect { subject << __FILE__ }.to raise_error( Errno::ENOTDIR )
34
+ end
35
+ end
36
+
37
+ describe '#[]' do
38
+ subject { described_class.new %w| .rb | }
39
+ before { subject << './spec/fixtures' }
40
+
41
+ it 'behaves normally if given an integer' do
42
+ subject[ 0 ].should_not be_nil
43
+ subject[ 1 ].should be_nil
44
+ end
45
+ it 'returns a pathname if given a string' do
46
+ subject[ 'solar_system/body' ].should be_a( Pathname )
47
+ end
48
+ it 'raises an exception of the file does not exist' do
49
+ expect { subject[ 'solar_system/pluto' ] }.to raise_error( Errno::ENOENT )
50
+ end
51
+ it 'raises an exception of the extension does not match' do
52
+ expect { subject[ 'breakfast/butter' ] }.to raise_error( Errno::ENOENT )
53
+ end
54
+ end
55
+ end
@@ -0,0 +1 @@
1
+ //= require assets/templates/user