Class: Lookout::Rake::Tasks::Test
- Inherits:
-
Object
- Object
- Lookout::Rake::Tasks::Test
- Includes:
- Rake::DSL
- Defined in:
- lib/lookout-rake-3.0/tasks/test.rb
Overview
Rake task for running expectation tests.
Constant Summary collapse
- LoaderPath =
File.join(File.dirname(__FILE__), 'test/loader.rb')
- Paths =
%w'lib'
Instance Attribute Summary collapse
-
#files ⇒ Array<String>
The expectation files to load, defaulting to ‘FileList[’test/unit/*/.rb]‘.
-
#inventory ⇒ Inventory
The inventory to use.
-
#name ⇒ Symbol
The name of the task.
-
#options ⇒ Array<String>
The options to pass to ruby.
-
#paths ⇒ Array<String>
The paths to add to ‘$LOAD_PATH`; may load #specification.
-
#requires ⇒ Array<String>
The libraries to require; may load #specification.
Instance Method Summary collapse
- #define ⇒ Object
-
#initialize(options = {}) {|?| ... } ⇒ Test
constructor
Defines a Rake task for running expectation tests named NAME.
-
#specification ⇒ Gem::Specification
The specification to use; will try to find one by looking for ‘*.gemspec` in the current directory.
- #specification=(specification) ⇒ Gem::Specification
Constructor Details
#initialize(options = {}) {|?| ... } ⇒ Test
Defines a Rake task for running expectation tests named NAME. Also defines a task for running expectations with coverage checking named NAME:coverage. The default task is set to depend on the NAME task, unless the default task has already been defined. The ‘:check` task is likewise set to depend on NAME. The NAME task itself and its NAME:coverage counterpart are set to depend on the `:compile` task if it’s been defined.
Optionally yields the TASK being created so that it may be adjusted further before being defined.
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/lookout-rake-3.0/tasks/test.rb', line 37 def initialize( = {}) self.name = .fetch(:name, :test) self.paths = .fetch(:paths, Paths) self.requires = .fetch(:requires, []) self.files = .fetch(:files){ ENV.include?('TEST') ? FileList[ENV['TEST']] : nil } inventory = [:inventory] || ((provided? 'inventory/rake-1.0' or provided? 'inventory-rake-1.0') and Inventory::Rake::Tasks.inventory) and self.inventory = inventory self.specification = .fetch(:specification) if .include? :specification self. = .fetch(:options, %w'-w') yield self if block_given? define end |
Instance Attribute Details
#files ⇒ Array<String>
Returns The expectation files to load, defaulting to ‘FileList[’test/unit/*/.rb]‘.
83 84 85 |
# File 'lib/lookout-rake-3.0/tasks/test.rb', line 83 def files @files ||= FileList['test/unit/**/*.rb'] end |
#inventory ⇒ Inventory
Returns The inventory to use.
92 93 94 |
# File 'lib/lookout-rake-3.0/tasks/test.rb', line 92 def inventory @inventory end |
#name ⇒ Symbol
Returns The name of the task.
52 53 54 |
# File 'lib/lookout-rake-3.0/tasks/test.rb', line 52 def name @name end |
#options ⇒ Array<String>
Returns The options to pass to ruby.
127 128 129 |
# File 'lib/lookout-rake-3.0/tasks/test.rb', line 127 def @options end |
#paths ⇒ Array<String>
Returns The paths to add to ‘$LOAD_PATH`; may load #specification.
60 61 62 63 64 |
# File 'lib/lookout-rake-3.0/tasks/test.rb', line 60 def paths return @paths if @paths and not @paths.equal? Paths self.specification = specification @paths end |
#requires ⇒ Array<String>
Returns The libraries to require; may load #specification.
71 72 73 74 75 |
# File 'lib/lookout-rake-3.0/tasks/test.rb', line 71 def requires return @requires unless @requires.empty? self.specification = specification @requires end |
Instance Method Details
#define ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/lookout-rake-3.0/tasks/test.rb', line 133 def define desc @name == :test ? 'Run tests' : 'Run tests for %s' % @name task @name do run end coverage = :"#{@name}:coverage" desc @name == :test ? 'Check test coverage' : 'Check test coverage for %s' % @name task coverage do run %w'-c' end [@name, coverage].each do |name| task name => :compile if Rake::Task.task_defined? :compile end task :default => @name unless Rake::Task.task_defined? :default task :check => @name end |
#specification ⇒ Gem::Specification
Returns The specification to use; will try to find one by looking for ‘*.gemspec` in the current directory.
108 109 110 111 112 113 114 115 |
# File 'lib/lookout-rake-3.0/tasks/test.rb', line 108 def specification return @specification if defined? @specification return nil unless defined? ::Gem gemspec = Dir['*.gemspec'].first fail 'gem specification was not given and could not be found in project root: %s' % Dir.pwd unless gemspec @specification = Gem::Specification.load(gemspec) end |
#specification=(specification) ⇒ Gem::Specification
120 121 122 123 124 |
# File 'lib/lookout-rake-3.0/tasks/test.rb', line 120 def specification=(specification) self.paths = specification.require_paths self.requires = [specification.name.gsub('-', '/')] specification end |