cms_scanner 0.0.18 → 0.0.19

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/core.rb +4 -3
  3. data/app/views/cli/core/finished.erb +1 -0
  4. data/app/views/json/core/finished.erb +1 -0
  5. data/cms_scanner.gemspec +13 -3
  6. data/lib/cms_scanner.rb +14 -2
  7. data/lib/cms_scanner/finders/finder.rb +16 -7
  8. data/lib/cms_scanner/finders/finder/enumerator.rb +4 -28
  9. data/lib/cms_scanner/finders/finder/fingerprinter.rb +60 -0
  10. data/lib/cms_scanner/finders/finding.rb +1 -1
  11. data/lib/cms_scanner/target/scope.rb +4 -1
  12. data/lib/cms_scanner/target/server/generic.rb +1 -1
  13. data/lib/cms_scanner/typhoeus/hydra.rb +10 -0
  14. data/lib/cms_scanner/version.rb +1 -1
  15. metadata +5 -203
  16. data/.gitignore +0 -7
  17. data/.rspec +0 -2
  18. data/.rubocop.yml +0 -10
  19. data/.travis.yml +0 -17
  20. data/Gemfile +0 -6
  21. data/Rakefile +0 -9
  22. data/spec/app/controllers/core_spec.rb +0 -167
  23. data/spec/app/controllers/interesting_files_spec.rb +0 -70
  24. data/spec/app/finders/interesting_files/fantastico_fileslist_spec.rb +0 -66
  25. data/spec/app/finders/interesting_files/headers_spec.rb +0 -36
  26. data/spec/app/finders/interesting_files/robots_txt_spec.rb +0 -54
  27. data/spec/app/finders/interesting_files/search_replace_db_2_spec.rb +0 -53
  28. data/spec/app/finders/interesting_files/xml_rpc_spec.rb +0 -136
  29. data/spec/app/finders/interesting_files_spec.rb +0 -12
  30. data/spec/app/formatters/cli_no_colour_spec.rb +0 -14
  31. data/spec/app/formatters/cli_spec.rb +0 -30
  32. data/spec/app/formatters/json_spec.rb +0 -30
  33. data/spec/app/models/fantastico_fileslist_spec.rb +0 -31
  34. data/spec/app/models/headers_spec.rb +0 -51
  35. data/spec/app/models/interesting_file_spec.rb +0 -69
  36. data/spec/app/models/robots_txt_spec.rb +0 -27
  37. data/spec/app/models/version_spec.rb +0 -51
  38. data/spec/app/models/xml_rpc_spec.rb +0 -46
  39. data/spec/app/views_spec.rb +0 -35
  40. data/spec/cache/.gitignore +0 -4
  41. data/spec/dummy_finding.rb +0 -25
  42. data/spec/dummy_independent_finders.rb +0 -26
  43. data/spec/dummy_unique_finders.rb +0 -33
  44. data/spec/fixtures/finders/interesting_files/fantastico_fileslist/fantastico_fileslist.txt +0 -12
  45. data/spec/fixtures/finders/interesting_files/file.txt +0 -4
  46. data/spec/fixtures/finders/interesting_files/headers/interesting.txt +0 -16
  47. data/spec/fixtures/finders/interesting_files/headers/no_interesting.txt +0 -12
  48. data/spec/fixtures/finders/interesting_files/robots_txt/robots.txt +0 -10
  49. data/spec/fixtures/finders/interesting_files/search_replace_db_2/searchreplacedb2.php +0 -188
  50. data/spec/fixtures/finders/interesting_files/xml_rpc/homepage_in_scope_pingback.html +0 -7
  51. data/spec/fixtures/finders/interesting_files/xml_rpc/homepage_out_of_scope_pingback.html +0 -7
  52. data/spec/fixtures/finders/interesting_files/xml_rpc/xmlrpc.php +0 -1
  53. data/spec/fixtures/output.txt +0 -0
  54. data/spec/fixtures/target/comments.html +0 -29
  55. data/spec/fixtures/target/platform/php/debug_log/debug.log +0 -2
  56. data/spec/fixtures/target/platform/php/fpd/wp_rss_functions.php +0 -2
  57. data/spec/fixtures/target/scope/index.html +0 -23
  58. data/spec/fixtures/target/server/apache/directory_listing/2.2.16.html +0 -15
  59. data/spec/fixtures/target/server/generic/server/apache/basic.txt +0 -5
  60. data/spec/fixtures/target/server/generic/server/iis/basic.txt +0 -6
  61. data/spec/fixtures/target/server/generic/server/not_detected.txt +0 -3
  62. data/spec/fixtures/target/server/iis/directory_listing/no_parent.html +0 -3
  63. data/spec/fixtures/target/server/iis/directory_listing/with_parent.html +0 -3
  64. data/spec/fixtures/views/base/ctrl/local.erb +0 -1
  65. data/spec/fixtures/views/base/ctrl/test.erb +0 -3
  66. data/spec/fixtures/views/base/global.erb +0 -1
  67. data/spec/fixtures/views/base/test.erb +0 -2
  68. data/spec/fixtures/views/based_format/test.erb +0 -1
  69. data/spec/fixtures/views/json/render_me.erb +0 -4
  70. data/spec/lib/browser_spec.rb +0 -140
  71. data/spec/lib/cache/file_store_spec.rb +0 -100
  72. data/spec/lib/cache/typhoeus_spec.rb +0 -28
  73. data/spec/lib/cms_scanner_spec.rb +0 -49
  74. data/spec/lib/controller_spec.rb +0 -30
  75. data/spec/lib/controllers_spec.rb +0 -48
  76. data/spec/lib/finders/confidence_spec.rb +0 -39
  77. data/spec/lib/finders/finder/enumerator_spec.rb +0 -89
  78. data/spec/lib/finders/finder/smart_url_checker/findings_spec.rb +0 -39
  79. data/spec/lib/finders/finder/smart_url_checker_spec.rb +0 -50
  80. data/spec/lib/finders/finder_spec.rb +0 -11
  81. data/spec/lib/finders/findings_spec.rb +0 -36
  82. data/spec/lib/finders/independent_finders_spec.rb +0 -134
  83. data/spec/lib/finders/same_type_finder_spec.rb +0 -24
  84. data/spec/lib/finders/same_type_finders_spec.rb +0 -126
  85. data/spec/lib/finders/unique_finder_spec.rb +0 -24
  86. data/spec/lib/finders/unique_finders_spec.rb +0 -222
  87. data/spec/lib/formatter_spec.rb +0 -145
  88. data/spec/lib/public_suffix/domain_spec.rb +0 -49
  89. data/spec/lib/sub_scanner_spec.rb +0 -45
  90. data/spec/lib/target/hashes_spec.rb +0 -90
  91. data/spec/lib/target/platforms_spec.rb +0 -13
  92. data/spec/lib/target/scope_spec.rb +0 -103
  93. data/spec/lib/target/servers_spec.rb +0 -13
  94. data/spec/lib/target_spec.rb +0 -69
  95. data/spec/lib/vulnerability/references_spec.rb +0 -75
  96. data/spec/lib/vulnerability_spec.rb +0 -27
  97. data/spec/lib/web_site_spec.rb +0 -121
  98. data/spec/output/core/finished.cli_no_colour +0 -3
  99. data/spec/output/core/finished.json +0 -5
  100. data/spec/output/core/started.cli_no_colour +0 -3
  101. data/spec/output/core/started.json +0 -5
  102. data/spec/output/interesting_files/empty.cli_no_colour +0 -2
  103. data/spec/output/interesting_files/empty.json +0 -5
  104. data/spec/output/interesting_files/findings.cli_no_colour +0 -30
  105. data/spec/output/interesting_files/findings.json +0 -75
  106. data/spec/shared_examples.rb +0 -11
  107. data/spec/shared_examples/browser_actions.rb +0 -30
  108. data/spec/shared_examples/finding.rb +0 -54
  109. data/spec/shared_examples/formatter_buffer.rb +0 -6
  110. data/spec/shared_examples/formatter_class_methods.rb +0 -26
  111. data/spec/shared_examples/independent_finder.rb +0 -31
  112. data/spec/shared_examples/target/platform/php.rb +0 -56
  113. data/spec/shared_examples/target/server/apache.rb +0 -32
  114. data/spec/shared_examples/target/server/generic.rb +0 -33
  115. data/spec/shared_examples/target/server/iis.rb +0 -37
  116. data/spec/shared_examples/views/core.rb +0 -26
  117. data/spec/shared_examples/views/interesting_files.rb +0 -36
  118. data/spec/spec_helper.rb +0 -43
@@ -1,24 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module CMSScanner
4
- module Finders
5
- # Dummy Class to test the module
6
- class PluginsFinderSpec
7
- include SameTypeFinder
8
-
9
- def initialize(_target)
10
- end
11
- end
12
- end
13
- end
14
-
15
- describe CMSScanner::Finders::PluginsFinderSpec do
16
- it_behaves_like CMSScanner::Finders::IndependentFinder do
17
- let(:expected_finders) { [] }
18
- let(:expected_finders_class) { CMSScanner::Finders::SameTypeFinders }
19
- end
20
-
21
- subject(:plugins) { described_class.new(target) }
22
- let(:target) { CMSScanner::Target.new(url) }
23
- let(:url) { 'http://example.com/' }
24
- end
@@ -1,126 +0,0 @@
1
- require 'spec_helper'
2
- require 'dummy_independent_finders' # will use those for convenience
3
-
4
- describe CMSScanner::Finders::SameTypeFinders do
5
- subject(:finders) { described_class.new }
6
- let(:independent_finders) { CMSScanner::Finders::Independent }
7
-
8
- describe '#run' do
9
- let(:target) { 'target' }
10
- let(:finding) { CMSScanner::DummyFinding }
11
- let(:opts) { {} }
12
-
13
- before do
14
- finders <<
15
- independent_finders::DummyFinder.new(target) <<
16
- independent_finders::NoAggressiveResult.new(target)
17
- end
18
-
19
- after do
20
- result = finders.run(opts)
21
-
22
- expect(result).to be_a CMSScanner::Finders::Findings
23
- expect(result).to eql @expected
24
- end
25
-
26
- # Used to be able to test the calls order and returned result at the same time
27
- let(:dummy_passive) { independent_finders::DummyFinder.new(target).passive(opts) }
28
- let(:dummy_aggresssive) { independent_finders::DummyFinder.new(target).aggressive(opts) }
29
- let(:noaggressive) { independent_finders::NoAggressiveResult.new(target).passive(opts) }
30
-
31
- context 'when :mixed mode' do
32
- let(:opts) { super().merge(mode: :mixed) }
33
-
34
- it 'calls all #passive then #aggressive on finders and returns the results' do
35
- expect(finders[0]).to receive(:passive)
36
- .with(hash_including(found: [])).ordered
37
- .and_return(dummy_passive)
38
-
39
- expect(finders[1]).to receive(:passive)
40
- .with(hash_including(found: [dummy_passive.first])).ordered
41
- .and_return(noaggressive)
42
-
43
- expect(finders[0]).to receive(:aggressive)
44
- .with(hash_including(found: [dummy_passive.first, noaggressive])).ordered
45
- .and_return(dummy_aggresssive)
46
-
47
- expect(finders[1]).to receive(:aggressive)
48
- .with(hash_including(:found))
49
- .ordered
50
-
51
- @expected = []
52
-
53
- @expected << finding.new('test', confidence: 100,
54
- found_by: 'Dummy Finder (Passive Detection)')
55
-
56
- @expected.first.confirmed_by << finding.new('test', confidence: 100, found_by: 'override')
57
-
58
- @expected << finding.new('spotted', confidence: 10,
59
- found_by: 'No Aggressive Result (Passive Detection)')
60
- end
61
- end
62
-
63
- context 'when :passive mode' do
64
- let(:opts) { super().merge(mode: :passive) }
65
-
66
- before do
67
- expect(finders[0]).to receive(:passive)
68
- .with(hash_including(found: [])).ordered
69
- .and_return(dummy_passive)
70
-
71
- expect(finders[1]).to receive(:passive)
72
- .with(hash_including(found: [dummy_passive.first])).ordered
73
- .and_return(noaggressive)
74
-
75
- finders.each { |f| expect(f).to_not receive(:aggressive) }
76
- end
77
-
78
- it 'calls #passive on all finders and returns the results' do
79
- @expected = []
80
- @expected << finding.new('test', found_by: 'Dummy Finder (Passive Detection)')
81
- @expected << finding.new('spotted', confidence: 10,
82
- found_by: 'No Aggressive Result (Passive Detection)')
83
- end
84
-
85
- context 'when :sort used' do
86
- let(:opts) { super().merge(sort: true) }
87
-
88
- it 'returns the sorted results' do
89
- @expected = []
90
- @expected << finding.new('spotted', confidence: 10,
91
- found_by: 'No Aggressive Result (Passive Detection)')
92
- @expected << finding.new('test', found_by: 'Dummy Finder (Passive Detection)')
93
- end
94
- end
95
-
96
- # TODO: make this work
97
- # context 'when :vulnerable used' do
98
- # let(:opts) { super().merge(vulnerable: true) }
99
-
100
- # it 'returns the vulnerable results' do
101
- # expect(dummy_passive).to receive(:vulnerable?).and_return(true)
102
- # expect(noaggressive).to receive(:vulnerable?)
103
-
104
- # @expected = [finding.new('test', found_by: 'Dummy Finder (Passive Detection)')]
105
- # end
106
- # end
107
- end
108
-
109
- context 'when :aggressive mode' do
110
- let(:opts) { super().merge(mode: :aggressive) }
111
-
112
- it 'calls #aggressive on all finders and returns the results' do
113
- finders.each { |f| expect(f).to_not receive(:passive) }
114
-
115
- expect(finders[0]).to receive(:aggressive)
116
- .with(hash_including(found: [])).ordered
117
- .and_return(dummy_aggresssive)
118
-
119
- expect(finders[1]).to receive(:aggressive)
120
- .with(hash_including(found: [dummy_aggresssive])).ordered
121
-
122
- @expected = [finding.new('test', confidence: 100, found_by: 'override')]
123
- end
124
- end
125
- end
126
- end
@@ -1,24 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module CMSScanner
4
- module Finders
5
- # Dummy Class to test the module
6
- class VersionFinderSpec
7
- include UniqueFinder
8
-
9
- def initialize(_target)
10
- end
11
- end
12
- end
13
- end
14
-
15
- describe CMSScanner::Finders::VersionFinderSpec do
16
- it_behaves_like CMSScanner::Finders::IndependentFinder do
17
- let(:expected_finders) { [] }
18
- let(:expected_finders_class) { CMSScanner::Finders::UniqueFinders }
19
- end
20
-
21
- subject(:version) { described_class.new(target) }
22
- let(:target) { CMSScanner::Target.new(url) }
23
- let(:url) { 'http://example.com/' }
24
- end
@@ -1,222 +0,0 @@
1
- require 'spec_helper'
2
- require 'dummy_unique_finders'
3
-
4
- describe CMSScanner::Finders::UniqueFinders do
5
- subject(:finders) { described_class.new }
6
- let(:unique_finders) { CMSScanner::Finders::Unique }
7
-
8
- describe '#best_finding' do
9
- let(:findings) { [] }
10
-
11
- after { expect(finders.best_finding(findings)).to eql @expected }
12
-
13
- context 'when no findings' do
14
- it 'returns nil' do
15
- @expected = false
16
- end
17
- end
18
-
19
- context 'when one finding' do
20
- let(:findings) { [CMSScanner::DummyFinding.new('one', confidence: 40)] }
21
-
22
- it 'returns it' do
23
- @expected = findings[0]
24
- end
25
- end
26
-
27
- context 'when multiple findings' do
28
- let(:findings) do
29
- (1..5).reduce([]) { |a, e| a << CMSScanner::DummyFinding.new(e, confidence: 20) }
30
- end
31
-
32
- context 'when they have the same confidence' do
33
- it 'returns nil' do
34
- @expected = false
35
- end
36
- end
37
-
38
- context 'when there is a best confidence' do
39
- (0..4).each do |position|
40
- context "when at [#{position}]" do
41
- it 'returns it' do
42
- findings[position].confidence = 100
43
-
44
- @expected = findings[position]
45
- end
46
- end
47
- end
48
- end
49
- end
50
- end
51
-
52
- describe '#run' do
53
- let(:target) { 'target' }
54
- let(:finding) { CMSScanner::DummyFinding }
55
- let(:opts) { {} }
56
-
57
- before do
58
- finders <<
59
- unique_finders::Dummy.new(target) <<
60
- unique_finders::NoAggressive.new(target) <<
61
- unique_finders::Dummy2.new(target)
62
- end
63
-
64
- after do
65
- result = finders.run(opts)
66
-
67
- expect(result).to be_a finding if @expected
68
- expect(result).to eql @expected
69
- end
70
-
71
- # Used to be able to test the calls order and returned result at the same time
72
- let(:dummy_passive) { unique_finders::Dummy.new(target).passive(opts) }
73
- let(:dummy_aggresssive) { unique_finders::Dummy.new(target).aggressive(opts) }
74
- let(:noaggressive) { unique_finders::NoAggressive.new(target).passive(opts) }
75
- let(:dummy2_aggressive) { unique_finders::Dummy2.new(target).aggressive }
76
-
77
- context 'when :confidence_threshold <= 0' do
78
- let(:opts) { super().merge(confidence_threshold: 0) }
79
-
80
- context 'when :mixed mode' do
81
- let(:opts) { super().merge(mode: :mixed) }
82
-
83
- it 'calls all #passive then #aggressive on finders and returns the best result' do
84
- # Maybe there is a way to factorise this
85
- expect(finders[0]).to receive(:passive)
86
- .with(hash_including(found: [])).ordered
87
- .and_return(dummy_passive)
88
-
89
- expect(finders[1]).to receive(:passive)
90
- .with(hash_including(found: [dummy_passive.first])).ordered
91
- .and_return(noaggressive)
92
-
93
- expect(finders[2]).to receive(:passive)
94
- .with(hash_including(found: [dummy_passive.first, noaggressive])).ordered
95
-
96
- expect(finders[0]).to receive(:aggressive).with(hash_including(:found)).ordered
97
- .and_return(dummy_aggresssive)
98
-
99
- expect(finders[1]).to receive(:aggressive).with(hash_including(:found)).ordered
100
- expect(finders[2]).to receive(:aggressive).with(hash_including(:found)).ordered
101
- .and_return(dummy2_aggressive)
102
-
103
- @expected = finding.new('v1', confidence: 100, found_by: 'Dummy (Passive Detection)')
104
- @expected.confirmed_by << finding.new('v1', confidence: 100, found_by: 'override')
105
- @expected.confirmed_by << finding.new('v1', confidence: 90)
106
- end
107
- end
108
-
109
- context 'when :passive mode' do
110
- let(:opts) { super().merge(mode: :passive) }
111
-
112
- it 'calls #passive on all finders and returns the best result' do
113
- expect(finders[0]).to receive(:passive)
114
- .with(hash_including(found: [])).ordered
115
- .and_return(dummy_passive)
116
-
117
- expect(finders[1]).to receive(:passive)
118
- .with(hash_including(found: [dummy_passive.first])).ordered
119
- .and_return(noaggressive)
120
-
121
- expect(finders[2]).to receive(:passive)
122
- .with(hash_including(found: [dummy_passive.first, noaggressive])).ordered
123
-
124
- finders.each { |f| expect(f).to_not receive(:aggressive) }
125
-
126
- @expected = finding.new('v2', confidence: 10,
127
- found_by: 'No Aggressive (Passive Detection)')
128
- end
129
- end
130
-
131
- context 'when :aggressive mode' do
132
- let(:opts) { super().merge(mode: :aggressive) }
133
-
134
- it 'calls #aggressive on all finders and returns the best result' do
135
- finders.each { |f| expect(f).to_not receive(:passive) }
136
-
137
- expect(finders[0]).to receive(:aggressive)
138
- .with(hash_including(found: [])).ordered
139
- .and_return(dummy_aggresssive)
140
-
141
- expect(finders[1]).to receive(:aggressive)
142
- .with(hash_including(found: [dummy_aggresssive])).ordered
143
-
144
- expect(finders[2]).to receive(:aggressive)
145
- .with(hash_including(:found)).ordered
146
- .and_return(dummy2_aggressive)
147
-
148
- @expected = finding.new('v1', confidence: 100, found_by: 'override')
149
- @expected.confirmed_by << finding.new('v1', confidence: 90)
150
- end
151
- end
152
- end
153
-
154
- context 'when :confidence_threshold = 100 (default)' do
155
- context 'when :mixed mode' do
156
- let(:opts) { super().merge(mode: :mixed) }
157
-
158
- it 'calls all #passive then #aggressive methods on finders and returns the '\
159
- 'result which reaches 100% confidence during the process' do
160
- expect(finders[0]).to receive(:passive)
161
- .with(hash_including(found: [])).ordered
162
- .and_return(dummy_passive)
163
-
164
- expect(finders[1]).to receive(:passive)
165
- .with(hash_including(found: [dummy_passive.first])).ordered
166
- .and_return(noaggressive)
167
-
168
- expect(finders[2]).to receive(:passive)
169
- .with(hash_including(found: [dummy_passive.first, noaggressive])).ordered
170
-
171
- expect(finders[0]).to receive(:aggressive).with(hash_including(:found)).ordered
172
- .and_return(dummy_aggresssive)
173
-
174
- expect(finders[1]).to_not receive(:aggressive)
175
- expect(finders[2]).to_not receive(:aggressive)
176
-
177
- @expected = finding.new('v1', confidence: 100, found_by: 'Dummy (Passive Detection)')
178
- @expected.confirmed_by << finding.new('v1', confidence: 100, found_by: 'override')
179
- end
180
- end
181
-
182
- context 'when :passive mode' do
183
- let(:opts) { super().merge(mode: :passive) }
184
-
185
- it 'calls all #passive and returns the best result' do
186
- expect(finders[0]).to receive(:passive)
187
- .with(hash_including(found: [])).ordered
188
- .and_return(dummy_passive)
189
-
190
- expect(finders[1]).to receive(:passive)
191
- .with(hash_including(found: [dummy_passive.first])).ordered
192
- .and_return(noaggressive)
193
-
194
- expect(finders[2]).to receive(:passive)
195
- .with(hash_including(found: [dummy_passive.first, noaggressive])).ordered
196
-
197
- finders.each { |f| expect(f).to_not receive(:aggressive) }
198
-
199
- @expected = finding.new('v2', confidence: 10,
200
- found_by: 'No Aggressive (Passive Detection)')
201
- end
202
- end
203
-
204
- context 'when :aggressive mode' do
205
- let(:opts) { super().merge(mode: :aggressive) }
206
-
207
- it 'calls all #aggressive and returns the result which reaches 100% confidence' do
208
- finders.each { |f| expect(f).to_not receive(:passive) }
209
-
210
- expect(finders[0]).to receive(:aggressive)
211
- .with(hash_including(found: [])).ordered
212
- .and_return(dummy_aggresssive)
213
-
214
- expect(finders[1]).to_not receive(:aggressive)
215
- expect(finders[2]).to_not receive(:aggressive)
216
-
217
- @expected = finding.new('v1', confidence: 100, found_by: 'override')
218
- end
219
- end
220
- end
221
- end
222
- end
@@ -1,145 +0,0 @@
1
- require 'spec_helper'
2
-
3
- # Test Module to check the correct inclusion of
4
- # the class methods
5
- module OtherFormatter
6
- include CMSScanner::Formatter
7
- end
8
-
9
- [CMSScanner::Formatter, OtherFormatter].each do |f|
10
- describe "#{f}" do
11
- subject(:formatter) { f }
12
- it_behaves_like CMSScanner::Formatter::ClassMethods
13
- end
14
- end
15
-
16
- module CMSScanner
17
- module Formatter
18
- module Spec
19
- # Base Format Test Class
20
- class BasedFormat < Base
21
- def base_format
22
- 'base'
23
- end
24
- end
25
- end
26
- end
27
- end
28
-
29
- describe CMSScanner::Formatter::Base do
30
- subject(:formatter) { described_class.new }
31
-
32
- describe '#format' do
33
- its(:format) { should eq 'base' }
34
- end
35
-
36
- describe '#user_interaction?' do
37
- context 'when not a cli format' do
38
- its(:user_interaction?) { should be false }
39
- end
40
-
41
- context 'when a cli format' do
42
- before { expect(formatter).to receive(:format).and_return('cli') }
43
-
44
- its(:user_interaction?) { should be true }
45
- end
46
- end
47
-
48
- describe '#render, output' do
49
- before { formatter.views_directories << FIXTURES_VIEWS }
50
-
51
- it 'renders the global template and does not override the @views_directories' do
52
- expect($stdout).to receive(:puts)
53
- .with("It Works!\nViews Dirs: #{formatter.views_directories}")
54
-
55
- formatter.output('@test', test: 'Works!', views_directories: 'owned')
56
- end
57
-
58
- context 'when global and local rendering are used inside a template' do
59
- it 'renders them correcly' do
60
- rendered = formatter.render('test', { var: 'Works' }, 'ctrl')
61
-
62
- expect(rendered).to eq "Test: Works\nLocal View\nGlobal View"
63
- end
64
- end
65
-
66
- it 'raises an error if the controller_name is nil and tpl is not a global one' do
67
- expect { formatter.output('test') }.to raise_error('The controller_name can not be nil')
68
- end
69
- end
70
-
71
- describe '#view_path' do
72
- before do
73
- formatter.views_directories << FIXTURES_VIEWS
74
- formatter.render('local', {}, 'ctrl') # Used to set the @controller_name
75
- end
76
-
77
- context 'when the tpl format is invalid' do
78
- let(:tpl) { '../try-this' }
79
-
80
- it 'raises an error' do
81
- expect { formatter.view_path(tpl) }.to raise_error("Wrong tpl format: 'ctrl/#{tpl}'")
82
- end
83
- end
84
-
85
- context 'when the tpl is not found' do
86
- let(:tpl) { 'not_there' }
87
-
88
- it 'raises an error' do
89
- expect { formatter.view_path(tpl) }.to raise_error("View not found for base/ctrl/#{tpl}")
90
- end
91
- end
92
-
93
- context 'when the tpl is found' do
94
- after { expect(formatter.view_path(@tpl)).to eq @expected }
95
-
96
- context 'if it\'s a global tpl' do
97
- it 'returns its path' do
98
- @expected = File.join(FIXTURES_VIEWS, 'base', 'test.erb')
99
- @tpl = '@test'
100
- end
101
- end
102
-
103
- context 'if it\s a local tpl' do
104
- it 'retuns its path' do
105
- @expected = File.join(FIXTURES_VIEWS, 'base', 'ctrl', 'local.erb')
106
- @tpl = 'local'
107
- end
108
- end
109
- end
110
-
111
- context 'when base_format' do
112
- subject(:formatter) { CMSScanner::Formatter::Spec::BasedFormat.new }
113
-
114
- after { expect(formatter.view_path(@tpl)).to eq @expected }
115
-
116
- context 'when the ovverided view exists' do
117
- it 'returns it' do
118
- @expected = File.join(FIXTURES_VIEWS, 'based_format', 'test.erb')
119
- @tpl = '@test'
120
- end
121
- end
122
-
123
- it 'returns the base views otherwise' do
124
- @expected = File.join(FIXTURES_VIEWS, 'base', 'ctrl', 'local.erb')
125
- @tpl = 'local'
126
- end
127
- end
128
- end
129
-
130
- describe '#views_directories' do
131
- let(:default_directories) { [APP_VIEWS] }
132
-
133
- context 'when default directories' do
134
- its(:views_directories) { should eq(default_directories) }
135
- end
136
-
137
- context 'when adding directories' do
138
- it 'adds them' do
139
- formatter.views_directories << 'testing'
140
-
141
- expect(formatter.views_directories).to eq(default_directories << 'testing')
142
- end
143
- end
144
- end
145
- end