lookout-rake 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README ADDED
@@ -0,0 +1,66 @@
1
+ Lookout-Rake
2
+
3
+ Lookout-Rake provides Rake tasks for testing using Lookout.
4
+
5
+ § Installation
6
+
7
+ Install Lookout-Rake with
8
+
9
+ % gem install lookout
10
+
11
+ § Usage
12
+
13
+ Include the following code in your ‹Rakefile›:
14
+
15
+ require 'lookout/rake-3.0'
16
+
17
+ Lookout::Rake::Tasks::Test.new
18
+
19
+ If the ‹:default› task hasn’t been defined it’ll be set to depend on the
20
+ ‹:test› task. The ‹:check› task will also depend on the ‹:test› task.
21
+ There’s also a ‹:test:coverage› task that gets defined that uses the
22
+ coverage library that comes with Ruby 1.9 to check the test coverage when
23
+ the tests are run.
24
+
25
+ You can hook up your test task to use your Inventory¹:
26
+
27
+ require 'library/version.rb'
28
+
29
+ Lookout::Rake::Tasks::Test.new :inventory => Library::Version
30
+
31
+ Also, if you use the tasks that come with Inventory, the test task will
32
+ hook into the inventory you tell them to use automatically.
33
+
34
+ To use Lookout together with Vim², place ‹contrib/rakelookout.vim› in
35
+ ‹~/.vim/compiler› and add
36
+
37
+ compiler rakelookout
38
+
39
+ to ‹~/.vim/after/ftplugin/ruby.vim›. Executing ‹:make› from inside Vim
40
+ will now run your tests and an errors and failures can be visited with
41
+ ‹:cnext›. Execute ‹:help quickfix› for additional information.
42
+
43
+ Another useful addition to your ‹~/.vim/after/ftplugin/ruby.vim› file may
44
+ be
45
+
46
+ nnoremap <buffer> <silent> <Leader>M <Esc>:call <SID>run_test()<CR>
47
+ let b:undo_ftplugin .= ' | nunmap <buffer> <Leader>M'
48
+
49
+ function! s:run_test()
50
+ let test = expand('%')
51
+ let line = 'LINE=' . line('.')
52
+ if test =~ '^lib/'
53
+ let test = substitute(test, '^lib/', 'test/', '')
54
+ let line = ""
55
+ endif
56
+ execute 'make' 'TEST=' . shellescape(test) line
57
+ endfunction
58
+
59
+ Now, pressing ‹<Leader>M› will either run all tests for a given class, if
60
+ the implementation file is active, or run the test at or just before the
61
+ cursor, if the test file is active. This is useful if you’re currently
62
+ receiving a lot of errors and/or failures and want to focus on those
63
+ associated with a specific class or on a specific test.
64
+
65
+ ¹ Get information on Inventory at http://disu.se/software/inventory/
66
+ ² Find out more about Vim at http://www.vim.org/
@@ -0,0 +1,13 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'inventory/rake-1.0'
4
+
5
+ $:.unshift File.expand_path('../lib', __FILE__)
6
+ require 'lookout/rake-3.0'
7
+
8
+ Inventory::Rake::Tasks.define Lookout::Rake::Version, :gem => proc{ |_, s|
9
+ s.author = 'Nikolai Weibull'
10
+ s.email = 'now@bitwi.se'
11
+ s.homepage = 'https://github.com/now/lookout-rake'
12
+ }
13
+ Lookout::Rake::Tasks::Test.new
@@ -0,0 +1,10 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ # Namespace for Lookout.
4
+ module Lookout end
5
+
6
+ # Namespace for Rake integration of Lookout.
7
+ module Lookout::Rake
8
+ load File.expand_path('../rake/version.rb', __FILE__)
9
+ Version.load
10
+ end
@@ -0,0 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ # Namespace for Rake tasks.
4
+ module Lookout::Rake::Tasks
5
+ end
@@ -0,0 +1,170 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ # Rake task for running expectation tests.
4
+ class Lookout::Rake::Tasks::Test
5
+ include Rake::DSL
6
+
7
+ LoaderPath = File.join(File.dirname(__FILE__), 'test/loader.rb')
8
+ Paths = %w'lib'
9
+
10
+ # Defines a Rake task for running expectation tests named _:name_. Also
11
+ # defines a task for running expectations with coverage name
12
+ # _:name_:coverage. If _:name_ `#==` `:test`, then the default task is set
13
+ # to depend on it, unless the default task has already been defined, as well
14
+ # as the `:check` task.
15
+ #
16
+ # Optionally yields the _task_ being created so that it may be adjusted
17
+ # further before being defined.
18
+ # @param [Hash] options
19
+ # @option options [Symbol] :name (:test) The name of the task
20
+ # @option options [Array<String>] :paths (['lib']) The paths to add to
21
+ # `$LOAD_PATH`
22
+ # @option options [Array<String>] :requires ([]) The libraries to require
23
+ # @option options [Array<String>] :files (FileList[ENV['TEST']]) The
24
+ # expectation files to load
25
+ # @option options [Inventory] :inventory (Inventory::Rake::Tasks.inventory)
26
+ # The Inventory to look for :paths, :requires, and :files in, see
27
+ # {#inventory=} (the default is only used if `inventory/rake-1.0` has
28
+ # been required)
29
+ # @option options [Gem::Specification] :specification The Gem specification
30
+ # to look for :paths and :requires in, see {#specification=}
31
+ # @option options [Array<String>] :options (['-w']) The options to pass to
32
+ # ruby
33
+ # @yield [?]
34
+ # @yieldparam [Test] task
35
+ def initialize(options = {})
36
+ self.name = options.fetch(:name, :test)
37
+ self.paths = options.fetch(:paths, Paths)
38
+ self.requires = options.fetch(:requires, [])
39
+ self.files = options.fetch(:files){ ENV.include?('TEST') ? FileList[ENV['TEST']] : nil }
40
+ inventory = options[:inventory] ||
41
+ (provided?('inventory/rake-1.0') and Inventory::Rake::Tasks.inventory) and
42
+ self.inventory = inventory
43
+ self.specification = options.fetch(:specification) if options.include? :specification
44
+ self.options = options.fetch(:options, %w'-w')
45
+ yield self if block_given?
46
+ define
47
+ end
48
+
49
+ # @return [Symbol] The name of the task
50
+ attr_reader :name
51
+
52
+ # @param [Symbol] value
53
+ # @return [Symbol] The new name of the task: _value_
54
+ attr_writer :name
55
+
56
+ # @return [Array<String>] The paths to add to `$LOAD_PATH`; may load
57
+ # {#specification}
58
+ def paths
59
+ return @paths if @paths and not @paths.equal? Paths
60
+ self.specification = specification
61
+ @paths
62
+ end
63
+
64
+ # @param [Array<String>] value
65
+ # @return [Array<String>] The new paths to add to `$LOAD_PATH`: _value_
66
+ attr_writer :paths
67
+
68
+ # @return [Array<String>] The libraries to require; may load {#specification}
69
+ def requires
70
+ return @requires unless @requires.empty?
71
+ self.specification = specification
72
+ @requires
73
+ end
74
+
75
+ # @param [Array<String>] value
76
+ # @return [Array<String>] The new libraries to require: _value_
77
+ attr_writer :requires
78
+
79
+ # @return [Array<String>] The expectation files to load; defaults to
80
+ # `FileList['test/unit/**/*.rb]`
81
+ def files
82
+ @files ||= FileList['test/unit/**/*.rb']
83
+ end
84
+
85
+ # @param [Array<String>] value
86
+ # @return [Array<String>] The new expectation files to load: _value_
87
+ attr_writer :files
88
+
89
+ # @return [Inventory] The inventory to use
90
+ attr_reader :inventory
91
+
92
+ # @param [Inventory] inventory
93
+ # @return [Inventory] The new inventory to use for {#paths}, {#requires}, and
94
+ # {#files}: _inventory_
95
+ def inventory=(inventory)
96
+ self.paths = inventory.lib_directories
97
+ self.requires = [inventory.package_require]
98
+ @files ||= inventory.unit_test_files
99
+ inventory
100
+ end
101
+
102
+ # @return [Gem::Specification] The specification to use; will try to find one
103
+ # by looking for `*.gemspec` in the current directory
104
+ # @raise [RuntimeError] If no specification has been set and one can’t be
105
+ # found in the current directory (the project root directory)
106
+ def specification
107
+ return @specification if defined? @specification
108
+ return nil unless defined? ::Gem
109
+ gemspec = Dir['*.gemspec'].first
110
+ fail 'gem specification was not given and could not be found in project root: %s' %
111
+ Dir.pwd unless gemspec
112
+ @specification = Gem::Specification.load(gemspec)
113
+ end
114
+
115
+ # @param [Gem::Specification] specification
116
+ # @return [Gem::Specification] The new specification to use for {#paths} and
117
+ # {#requires}: _specification_
118
+ def specification=(specification)
119
+ self.paths = specification.require_paths
120
+ self.requires = [specification.name.gsub('-', '/')]
121
+ specification
122
+ end
123
+
124
+ # @return [Array<String>] The options to pass to ruby
125
+ attr_reader :options
126
+
127
+ # @param [Array<String>] value
128
+ # @return [Array<String>] The new options to pass to ruby: _value_
129
+ attr_writer :options
130
+
131
+ def define
132
+ desc @name == :test ? 'Run tests' : 'Run tests for %s' % @name
133
+ task @name do
134
+ run
135
+ end
136
+
137
+ desc @name == :test ? 'Check test coverage' : 'Check test coverage for %s' % @name
138
+ task :"#{@name}:coverage" do
139
+ run %w'-c'
140
+ end
141
+
142
+ task :default => @name unless Rake::Task.task_defined? :default
143
+
144
+ task :check => :test if @name == :test
145
+ end
146
+
147
+ private
148
+
149
+ def run(arguments = [])
150
+ ruby '%s -- %s %s' % [(options + paths.uniq.map{ |e| '-I%s' % e }).join(' '),
151
+ escape(LoaderPath),
152
+ requires.uniq.map{ |r| '-r%s' % r }.
153
+ concat(line).concat(arguments).
154
+ push('--').
155
+ concat(files.map{ |e| escape(e) }).join(' ')]
156
+ end
157
+
158
+ def line
159
+ return [] unless ENV['LINE'] and not ENV['LINE'].empty?
160
+ ['-l%d' % ENV['LINE'].to_i]
161
+ end
162
+
163
+ def escape(path)
164
+ path.gsub(/([^A-Za-z0-9_\-.,:\/@\n])/n, '\\\\\\1').gsub(/\n/, "'\n'")
165
+ end
166
+
167
+ def provided?(path)
168
+ $LOADED_FEATURES.any?{ |e| e.end_with? path + File.extname(e) }
169
+ end
170
+ end
@@ -0,0 +1,4 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'lookout-3.0'
4
+ exit false unless Lookout::Interface::Commandline.new.call
@@ -0,0 +1,39 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'inventory-1.0'
4
+
5
+ module Lookout::Rake
6
+ Version = Inventory.new(3, 0, 0){
7
+ def dependencies
8
+ super + Inventory::Dependencies.new{
9
+ development 'inventory-rake', 1, 2, 0
10
+ optional 'rake', 0, 9, 2
11
+ }
12
+ end
13
+
14
+ def requires
15
+ %w'
16
+ rake
17
+ '
18
+ end
19
+
20
+ def libs
21
+ %w'
22
+ lookout/rake/tasks.rb
23
+ lookout/rake/tasks/test.rb
24
+ '
25
+ end
26
+
27
+ def additional_libs
28
+ super + %w'
29
+ lookout/rake/tasks/test/loader.rb
30
+ '
31
+ end
32
+
33
+ def unit_tests
34
+ super - %w'
35
+ lookout/rake/tasks/test/loader.rb
36
+ '
37
+ end
38
+ }
39
+ end
@@ -0,0 +1,4 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ Expectations do
4
+ end
@@ -0,0 +1,4 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ Expectations do
4
+ end
@@ -0,0 +1,106 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ Expectations do
4
+ expect '-w -Ilib -- %s -rtest-1.0 -- test/unit/test-1.0.rb test/unit/test/version.rb' %
5
+ Lookout::Rake::Tasks::Test::LoaderPath do
6
+ command = nil
7
+ Rake.application = Rake::Application.new
8
+ Lookout::Rake::Tasks::Test.new(:inventory => Inventory.new(1, 0, 0, 'test/lib/test/version.rb')){ |t|
9
+ stub(t).ruby{ |s| command = s }
10
+ }
11
+ Rake.application[:test].invoke
12
+ command
13
+ end
14
+
15
+ expect '-w -Ilib -- %s -rtest-1.0 -l123 -- test/unit/test-1.0.rb test/unit/test/version.rb' %
16
+ Lookout::Rake::Tasks::Test::LoaderPath do
17
+ command = nil
18
+ Rake.application = Rake::Application.new
19
+ Lookout::Rake::Tasks::Test.new(:inventory => Inventory.new(1, 0, 0, 'test/lib/test/version.rb')){ |t|
20
+ stub(t).ruby{ |s| command = s }
21
+ }
22
+ with_environment 'LINE' => '123' do
23
+ Rake.application[:test].invoke
24
+ end
25
+ command
26
+ end
27
+
28
+ expect '-w -Ilib -- %s -rtest-1.0 -c -- test/unit/test-1.0.rb test/unit/test/version.rb' %
29
+ Lookout::Rake::Tasks::Test::LoaderPath do
30
+ command = nil
31
+ Rake.application = Rake::Application.new
32
+ Lookout::Rake::Tasks::Test.new(:inventory => Inventory.new(1, 0, 0, 'test/lib/test/version.rb')){ |t|
33
+ stub(t).ruby{ |s| command = s }
34
+ }
35
+ Rake.application[:'test:coverage'].invoke
36
+ command
37
+ end
38
+
39
+ expect '-w -Ilib -- %s -rtest-1.0 -- test/unit/test-1.0.rb test/unit/test/version.rb' %
40
+ Lookout::Rake::Tasks::Test::LoaderPath do
41
+ with_constant 'Inventory::Rake::Tasks', Module.new do
42
+ stub(Inventory::Rake::Tasks).inventory{
43
+ Inventory.new(1, 0, 0, 'test/lib/test/version.rb')
44
+ }
45
+ stub($LOADED_FEATURES).any?{ true }
46
+ command = nil
47
+ Rake.application = Rake::Application.new
48
+ Lookout::Rake::Tasks::Test.new{ |t|
49
+ stub(t).ruby{ |s| command = s }
50
+ }
51
+ Rake.application[:test].invoke
52
+ command
53
+ end
54
+ end
55
+
56
+ expect RuntimeError.new(/\Agem specification was not given/) do
57
+ stub(Dir).[]{ [] }
58
+ Rake.application = Rake::Application.new
59
+ Lookout::Rake::Tasks::Test.new
60
+ Rake.application[:test].invoke
61
+ command
62
+ end
63
+
64
+ expect '-w -Ilib -- %s -rtest -- test/unit/test.rb test/unit/test/version.rb' %
65
+ Lookout::Rake::Tasks::Test::LoaderPath do
66
+ stub(Dir).[]{ %w'test.gemspec' }
67
+ stub(Gem::Specification).load{ Gem::Specification.new{ |s| s.name = 'test' } }
68
+ command = nil
69
+ Rake.application = Rake::Application.new
70
+ Lookout::Rake::Tasks::Test.new(:files => %w'test/unit/test.rb test/unit/test/version.rb'){ |t|
71
+ stub(t).ruby{ |s| command = s }
72
+ }
73
+ Rake.application[:test].invoke
74
+ command
75
+ end
76
+
77
+ expect '-w -Ilib -- %s -rtest -- test/unit/test.rb test/unit/test/version.rb' %
78
+ Lookout::Rake::Tasks::Test::LoaderPath do
79
+ command = nil
80
+ Rake.application = Rake::Application.new
81
+ Lookout::Rake::Tasks::Test.new(:specification => Gem::Specification.new{ |s|
82
+ s.name = 'test'
83
+ },
84
+ :files => %w'test/unit/test.rb test/unit/test/version.rb'){ |t|
85
+ stub(t).ruby{ |s| command = s }
86
+ }
87
+ Rake.application[:test].invoke
88
+ command
89
+ end
90
+
91
+ expect %w'lib' do
92
+ stub(Dir).[]{ %w'test.gemspec' }
93
+ stub(Gem::Specification).load{ Gem::Specification.new{ |s| s.name = 'test' } }
94
+ Rake.application = Rake::Application.new
95
+ Lookout::Rake::Tasks::Test.new(:paths => nil,
96
+ :files => %w'test/unit/test.rb test/unit/test/version.rb').paths
97
+ end
98
+
99
+ expect %w'test' do
100
+ stub(Dir).[]{ %w'test.gemspec' }
101
+ stub(Gem::Specification).load{ Gem::Specification.new{ |s| s.name = 'test' } }
102
+ Rake.application = Rake::Application.new
103
+ Lookout::Rake::Tasks::Test.new(:paths => nil,
104
+ :files => %w'test/unit/test.rb test/unit/test/version.rb').requires
105
+ end
106
+ end
@@ -0,0 +1,4 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ Expectations do
4
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lookout-rake
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Nikolai Weibull
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: inventory
16
+ requirement: &15797340 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.2'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *15797340
25
+ - !ruby/object:Gem::Dependency
26
+ name: inventory-rake
27
+ requirement: &15796764 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '1.2'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *15796764
36
+ - !ruby/object:Gem::Dependency
37
+ name: rake
38
+ requirement: &15796212 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 0.9.2
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *15796212
47
+ description: ! " Lookout-Rake\n\n Lookout-Rake provides
48
+ Rake tasks for testing using Lookout.\n\n§ Installation\n\n Install Lookout-Rake
49
+ with\n\n % gem install lookout\n\n§ Usage\n\n Include the following code in
50
+ your ‹Rakefile›:\n\n require 'lookout/rake-3.0'\n\n Lookout::Rake::Tasks::Test.new\n\n
51
+ \ If the ‹:default› task hasn’t been defined it’ll be set to depend on the\n ‹:test›
52
+ task. The ‹:check› task will also depend on the ‹:test› task.\n There’s also
53
+ a ‹:test:coverage› task that gets defined that uses the\n coverage library that
54
+ comes with Ruby 1.9 to check the test coverage when\n the tests are run.\n\n
55
+ \ You can hook up your test task to use your Inventory¹:\n\n require 'library/version.rb'\n\n
56
+ \ Lookout::Rake::Tasks::Test.new :inventory => Library::Version\n\n Also,
57
+ if you use the tasks that come with Inventory, the test task will\n hook into
58
+ the inventory you tell them to use automatically.\n\n To use Lookout together
59
+ with Vim², place ‹contrib/rakelookout.vim› in\n ‹~/.vim/compiler› and add\n\n
60
+ \ compiler rakelookout\n\n to ‹~/.vim/after/ftplugin/ruby.vim›. Executing
61
+ ‹:make› from inside Vim\n will now run your tests and an errors and failures
62
+ can be visited with\n ‹:cnext›. Execute ‹:help quickfix› for additional information.\n\n
63
+ \ Another useful addition to your ‹~/.vim/after/ftplugin/ruby.vim› file may\n
64
+ \ be\n\n nnoremap <buffer> <silent> <Leader>M <Esc>:call <SID>run_test()<CR>\n
65
+ \ let b:undo_ftplugin .= ' | nunmap <buffer> <Leader>M'\n\n function! s:run_test()\n
66
+ \ let test = expand('%')\n let line = 'LINE=' . line('.')\n if
67
+ test =~ '^lib/'\n let test = substitute(test, '^lib/', 'test/', '')\n let
68
+ line = \"\"\n endif\n execute 'make' 'TEST=' . shellescape(test) line\n
69
+ \ endfunction\n\n Now, pressing ‹<Leader>M› will either run all tests for
70
+ a given class, if\n the implementation file is active, or run the test at or
71
+ just before the\n cursor, if the test file is active. This is useful if you’re
72
+ currently\n receiving a lot of errors and/or failures and want to focus on those\n
73
+ \ associated with a specific class or on a specific test.\n\n¹ Get information
74
+ on Inventory at http://disu.se/software/inventory/\n² Find out more about Vim at
75
+ http://www.vim.org/\n"
76
+ email: now@bitwi.se
77
+ executables: []
78
+ extensions: []
79
+ extra_rdoc_files: []
80
+ files:
81
+ - lib/lookout/rake/tasks.rb
82
+ - lib/lookout/rake/tasks/test.rb
83
+ - lib/lookout/rake-3.0.rb
84
+ - lib/lookout/rake/version.rb
85
+ - lib/lookout/rake/tasks/test/loader.rb
86
+ - test/unit/lookout/rake/tasks.rb
87
+ - test/unit/lookout/rake/tasks/test.rb
88
+ - test/unit/lookout/rake-3.0.rb
89
+ - test/unit/lookout/rake/version.rb
90
+ - README
91
+ - Rakefile
92
+ homepage: https://github.com/now/lookout-rake
93
+ licenses: []
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 1.8.10
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Lookout-Rake provides Rake tasks for testing using Lookout.
117
+ test_files: []