Class: Assert::RakeTasks::Scope
- Inherits:
-
Object
- Object
- Assert::RakeTasks::Scope
- Defined in:
- lib/assert/rake_tasks/scope.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(path) ⇒ Scope
constructor
A new instance of Scope.
- #namespace ⇒ Object
-
#nested_files ⇒ Object
nested test files under the path.
-
#path_file_list ⇒ Object
a list with the path test file “#path_test.rb” (if it exists).
-
#scopes ⇒ Object
a collection of scopes for every child test dir or test dir/file combo.
-
#test_tasks ⇒ Object
a collection of test tasks for every standalone child test file.
-
#to_test_task ⇒ Object
return a test task covering the scopes nested files plus path file but only if there are nested files.
Constructor Details
#initialize(path) ⇒ Scope
Returns a new instance of Scope.
11 12 13 |
# File 'lib/assert/rake_tasks/scope.rb', line 11 def initialize(path) @path = path end |
Class Method Details
.test_file_suffix ⇒ Object
7 8 9 |
# File 'lib/assert/rake_tasks/scope.rb', line 7 def self.test_file_suffix "_test.rb" end |
Instance Method Details
#namespace ⇒ Object
15 16 17 |
# File 'lib/assert/rake_tasks/scope.rb', line 15 def namespace File.basename(@path).to_sym end |
#nested_files ⇒ Object
nested test files under the path
20 21 22 |
# File 'lib/assert/rake_tasks/scope.rb', line 20 def nested_files nested_files = Rake::FileList["#{@path}/**/*#{self.class.test_file_suffix}"] end |
#path_file_list ⇒ Object
a list with the path test file “#path_test.rb” (if it exists)
25 26 27 28 |
# File 'lib/assert/rake_tasks/scope.rb', line 25 def path_file_list path_file_name = @path+self.class.test_file_suffix (File.exists?(path_file_name) ? Rake::FileList[path_file_name] : []) end |
#scopes ⇒ Object
a collection of scopes for every child test dir or test dir/file combo
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/assert/rake_tasks/scope.rb', line 58 def scopes # get immediate child paths Dir.glob("#{@path}/*").collect do |p| # get just the path name for each dir/file and uniq it File.join(File.dirname(p), File.basename(p, self.class.test_file_suffix)) end.uniq.select do |p| # select any that have deeply nested test files !Dir.glob("#{p}/**/*#{self.class.test_file_suffix}").empty? end.collect do |p| # build a scope for each path self.class.new(p) end end |
#test_tasks ⇒ Object
a collection of test tasks for every standalone child test file
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/assert/rake_tasks/scope.rb', line 41 def test_tasks # get immediate child test files Dir.glob("#{@path}/*#{self.class.test_file_suffix}").collect do |f| # get just the path name for each file File.join(File.dirname(f), File.basename(f, self.class.test_file_suffix)) end.reject do |p| # reject any that have deeply nested test files !Dir.glob("#{p}/**/*#{self.class.test_file_suffix}").empty? end.collect do |p| # build a test task for the standalone test file of the path TestTask.new(p) do |tt| tt.files = Rake::FileList[p+self.class.test_file_suffix] end end end |
#to_test_task ⇒ Object
return a test task covering the scopes nested files plus path file but only if there are nested files
32 33 34 35 36 37 38 |
# File 'lib/assert/rake_tasks/scope.rb', line 32 def to_test_task if !self.nested_files.empty? TestTask.new(@path) do |tt| tt.files = self.path_file_list + self.nested_files end end end |