|
2 | 2 |
|
3 | 3 | describe "gf file" do |
4 | 4 |
|
5 | | - def html_file_at(filename) |
6 | | - safe_write_file(filename) |
7 | | - end |
8 | | - |
9 | | - def do_gf_from_directive!(template_url = 'my-customer.html') |
10 | | - write_file('directive.js', <<-EOF) |
11 | | - angular.module('docsTemplateUrlDirective', []) |
12 | | - .controller('Controller', ['$scope', function($scope) { |
13 | | - $scope.customer = { |
14 | | - name: 'Naomi', |
15 | | - address: '1600 Amphitheatre' |
16 | | - }; |
17 | | - }]) |
18 | | - .directive('myCustomer', function() { |
19 | | - return { |
20 | | - templateUrl: '#{template_url}' |
21 | | - }; |
22 | | - }); |
23 | | - EOF |
24 | | - |
25 | | - vim.edit 'directive.js' |
26 | | - current_file_name.should eq "directive.js" |
27 | | - vim.normal '/my-cust<CR>' |
28 | | - #vim.normal 'gf' |
29 | | - vim.command 'AngularGoToFile' |
| 5 | + specify "default behavior for directive" do |
| 6 | + html_file_at('my-customer.html') |
| 7 | + do_gf_from_directive_that_references!('my-customer.html') |
| 8 | + current_file_name.should eq "my-customer.html" |
30 | 9 | end |
31 | 10 |
|
32 | | - specify "default behavior" do |
| 11 | + specify "default behavior for view" do |
33 | 12 | html_file_at('my-customer.html') |
34 | | - do_gf_from_directive! |
| 13 | + do_gf_from_view_that_references!('my-customer.html') |
35 | 14 | current_file_name.should eq "my-customer.html" |
36 | 15 | end |
37 | 16 |
|
38 | 17 | specify "when html in app/templates and directive references full path" do |
39 | 18 | html_file_at('app/templates/my-customer.html') |
40 | | - do_gf_from_directive!('app/templates/my-customer.html') |
| 19 | + do_gf_from_directive_that_references!('app/templates/my-customer.html') |
41 | 20 | current_file_name.should eq "app/templates/my-customer.html" |
42 | 21 | end |
43 | 22 |
|
44 | 23 | specify "when html in app/templates and directive references path minus app" do |
45 | 24 | html_file_at('app/templates/my-customer.html') |
46 | | - do_gf_from_directive!('templates/my-customer.html') |
| 25 | + do_gf_from_directive_that_references!('templates/my-customer.html') |
47 | 26 | current_file_name.should eq "app/templates/my-customer.html" |
48 | 27 | end |
49 | 28 |
|
50 | | - specify "when html in app subdirectory" do |
| 29 | + specify "when html in app/templates and view references path minus app" do |
| 30 | + html_file_at('app/templates/my-customer.html') |
| 31 | + do_gf_from_view_that_references!('templates/my-customer.html') |
| 32 | + current_file_name.should eq "app/templates/my-customer.html" |
| 33 | + end |
| 34 | + |
| 35 | + specify "when html in app/views and view references path minus app" do |
| 36 | + html_file_at('app/views/my-customer.html') |
| 37 | + do_gf_from_view_that_references!('views/my-customer.html') |
| 38 | + current_file_name.should eq "app/views/my-customer.html" |
| 39 | + end |
| 40 | + |
| 41 | + specify "when html in app subdirectory and directive references path minus app" do |
51 | 42 | html_file_at('app/my-customer.html') |
52 | | - do_gf_from_directive! |
| 43 | + do_gf_from_directive_that_references!('my-customer.html') |
53 | 44 | current_file_name.should eq "app/my-customer.html" |
54 | 45 | end |
55 | 46 |
|
56 | | - specify "when html in random unsupported subdirectory" do |
| 47 | + specify "when html in random unsupported subdirectory that directive is not referencing" do |
57 | 48 | html_file_at('wut/my-customer.html') |
58 | | - do_gf_from_directive! |
| 49 | + do_gf_from_directive_that_references!('my-customer.html') |
59 | 50 | current_file_name.should eq "directive.js" |
60 | 51 | end |
61 | 52 |
|
| 53 | +private |
| 54 | + |
| 55 | + def html_file_at(filename) |
| 56 | + safe_write_file(filename) |
| 57 | + end |
| 58 | + |
| 59 | + def do_gf(starting_file, starting_file_contents) |
| 60 | + write_file(starting_file, starting_file_contents) |
| 61 | + |
| 62 | + vim.edit starting_file |
| 63 | + current_file_name.should eq starting_file |
| 64 | + vim.normal '/my-cust<CR>' |
| 65 | + #vim.normal 'gf' |
| 66 | + vim.command 'AngularGoToFile' |
| 67 | + end |
| 68 | + |
| 69 | + def do_gf_from_directive_that_references!(template_url) |
| 70 | + starting_file = 'directive.js' |
| 71 | + |
| 72 | + do_gf(starting_file, <<-EOF) |
| 73 | + angular.module('docsTemplateUrlDirective', []) |
| 74 | + .controller('Controller', ['$scope', function($scope) { |
| 75 | + $scope.customer = { |
| 76 | + name: 'Naomi', |
| 77 | + address: '1600 Amphitheatre' |
| 78 | + }; |
| 79 | + }]) |
| 80 | + .directive('myCustomer', function() { |
| 81 | + return { |
| 82 | + templateUrl: '#{template_url}' |
| 83 | + }; |
| 84 | + }); |
| 85 | + EOF |
| 86 | + end |
| 87 | + |
| 88 | + def do_gf_from_view_that_references!(template_url) |
| 89 | + starting_file = 'hot.html' |
| 90 | + |
| 91 | + do_gf(starting_file, <<-EOF) |
| 92 | + <div class="totally-awesome" |
| 93 | + ng-if="readyToRock" |
| 94 | + ng-include src="'#{template_url}'"> |
| 95 | + </div |
| 96 | + EOF |
| 97 | + end |
| 98 | + |
62 | 99 | end |
0 commit comments