pluginfactory 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,16 +1,22 @@
1
1
  #
2
2
  # Rake tasklib for testing tasks
3
- # $Id: testing.rb 14 2008-07-23 23:16:30Z deveiant $
3
+ # $Id: testing.rb 80 2008-12-20 19:50:19Z deveiant $
4
4
  #
5
5
  # Authors:
6
6
  # * Michael Granger <ged@FaerieMUD.org>
7
7
  #
8
8
 
9
- COVERAGE_MINIMUM = 85.0 unless defined?( COVERAGE_MINIMUM )
9
+ unless defined?( COVERAGE_MINIMUM )
10
+ if ENV['COVVERAGE_MINIMUM']
11
+ COVERAGE_MINIMUM = Float( ENV['COVERAGE_MINIMUM'] )
12
+ else
13
+ COVERAGE_MINIMUM = 85.0
14
+ end
15
+ end
10
16
  SPEC_FILES = [] unless defined?( SPEC_FILES )
11
17
  TEST_FILES = [] unless defined?( TEST_FILES )
12
18
 
13
- COMMON_SPEC_OPTS = ['-c', '-f', 's'] unless defined?( COMMON_SPEC_OPTS )
19
+ COMMON_SPEC_OPTS = ['-Du', '-b'] unless defined?( COMMON_SPEC_OPTS )
14
20
 
15
21
  COVERAGE_TARGETDIR = BASEDIR + 'coverage' unless defined?( COVERAGE_TARGETDIR )
16
22
  RCOV_EXCLUDES = 'spec,tests,/Library/Ruby,/var/lib,/usr/local/lib' unless
@@ -34,15 +40,12 @@ end
34
40
  ### RSpec specifications
35
41
  begin
36
42
  gem 'rspec', '>= 1.1.3'
43
+
44
+ require 'spec'
37
45
  require 'spec/rake/spectask'
38
46
 
39
47
  ### Task: spec
40
- Spec::Rake::SpecTask.new( :spec ) do |task|
41
- task.spec_files = SPEC_FILES
42
- task.libs += [LIBDIR]
43
- task.spec_opts = COMMON_SPEC_OPTS
44
- end
45
-
48
+ task :spec => 'spec:doc'
46
49
 
47
50
  namespace :spec do
48
51
  desc "Run rspec every time there's a change to one of the files"
@@ -50,28 +53,33 @@ begin
50
53
  require 'autotest/rspec'
51
54
 
52
55
  autotester = Autotest::Rspec.new
53
- autotester.exceptions = %r{\.svn|\.skel}
54
56
  autotester.run
55
57
  end
56
58
 
59
+ desc "Generate regular color 'doc' spec output"
60
+ Spec::Rake::SpecTask.new( :doc ) do |task|
61
+ task.spec_files = SPEC_FILES
62
+ task.spec_opts = COMMON_SPEC_OPTS + ['-f', 's', '-c']
63
+ end
57
64
 
58
- desc "Generate quiet output"
59
- Spec::Rake::SpecTask.new( :quiet ) do |task|
65
+ desc "Generate spec output with profiling"
66
+ Spec::Rake::SpecTask.new( :profile ) do |task|
60
67
  task.spec_files = SPEC_FILES
61
- task.spec_opts = ['-f', 'p', '-D']
68
+ task.spec_opts = COMMON_SPEC_OPTS + ['-f', 'o']
62
69
  end
63
70
 
64
- desc "Generate HTML output for a spec run"
65
- Spec::Rake::SpecTask.new( :html ) do |task|
71
+ desc "Generate quiet non-colored plain-text output"
72
+ Spec::Rake::SpecTask.new( :quiet ) do |task|
66
73
  task.spec_files = SPEC_FILES
67
- task.spec_opts = ['-f','h', '-D']
74
+ task.spec_opts = COMMON_SPEC_OPTS + ['-f', 'p']
68
75
  end
69
76
 
70
- desc "Generate plain-text output for a CruiseControl.rb build"
71
- Spec::Rake::SpecTask.new( :text ) do |task|
77
+ desc "Generate HTML output"
78
+ Spec::Rake::SpecTask.new( :html ) do |task|
72
79
  task.spec_files = SPEC_FILES
73
- task.spec_opts = ['-f','p']
80
+ task.spec_opts = COMMON_SPEC_OPTS + ['-f', 'h']
74
81
  end
82
+
75
83
  end
76
84
  rescue LoadError => err
77
85
  task :no_rspec do
@@ -81,9 +89,10 @@ rescue LoadError => err
81
89
  task :spec => :no_rspec
82
90
  namespace :spec do
83
91
  task :autotest => :no_rspec
92
+ task :doc => :no_rspec
93
+ task :profile => :no_rspec
84
94
  task :quiet => :no_rspec
85
95
  task :html => :no_rspec
86
- task :text => :no_rspec
87
96
  end
88
97
  end
89
98
 
@@ -112,8 +121,10 @@ begin
112
121
  gem 'rcov'
113
122
  gem 'rspec', '>= 1.1.3'
114
123
 
124
+ require 'spec'
125
+ require 'rcov'
126
+
115
127
  ### Task: coverage (via RCov)
116
- ### Task: rcov
117
128
  desc "Build test coverage reports"
118
129
  unless SPEC_FILES.empty?
119
130
  Spec::Rake::SpecTask.new( :coverage ) do |task|
@@ -124,19 +135,20 @@ begin
124
135
  task.rcov = true
125
136
  end
126
137
  end
127
- unless TEST_FILES.empty?
128
- require 'rcov/rcovtask'
138
+ # unless TEST_FILES.empty?
139
+ # require 'rcov/rcovtask'
129
140
 
130
- Rcov::RcovTask.new do |task|
131
- task.libs += [LIBDIR]
132
- task.test_files = TEST_FILES
133
- task.verbose = true
134
- task.rcov_opts = RCOV_OPTS
135
- end
136
- end
141
+ # Rcov::RcovTask.new do |task|
142
+ # task.libs += [LIBDIR]
143
+ # task.test_files = TEST_FILES
144
+ # task.verbose = true
145
+ # task.rcov_opts = RCOV_OPTS
146
+ # end
147
+ # end
137
148
 
138
149
 
139
- task :rcov => [:coverage] do; end
150
+ ### Task: rcov
151
+ task :rcov => :coverage
140
152
 
141
153
  ### Other coverage tasks
142
154
  namespace :coverage do
@@ -150,7 +162,8 @@ begin
150
162
  desc "Show differences in coverage from last run"
151
163
  Spec::Rake::SpecTask.new( :diff ) do |task|
152
164
  task.spec_files = SPEC_FILES
153
- task.rcov_opts = ['--text-coverage-diff']
165
+ task.spec_opts = ['-f', 'p', '-b']
166
+ task.rcov_opts = RCOV_OPTS - ['--save'] + ['--text-coverage-diff']
154
167
  task.rcov = true
155
168
  end
156
169
 
@@ -168,9 +181,7 @@ begin
168
181
  end
169
182
  end
170
183
 
171
- task :clobber_coverage do
172
- rmtree( COVERAGE_TARGETDIR )
173
- end
184
+ CLOBBER.include( COVERAGE_TARGETDIR )
174
185
 
175
186
  rescue LoadError => err
176
187
  task :no_rcov do
@@ -0,0 +1,94 @@
1
+ #
2
+ # Win32-specific tasks (cross-compiling, etc.)
3
+ #
4
+ # Thanks to some people that understand this stuff better than me for
5
+ # posting helpful blog posts. This stuff is an amalgam of stuff they did:
6
+ #
7
+ # * Mauricio Fernandez
8
+ # http://eigenclass.org/hiki/cross+compiling+rcovrt
9
+ #
10
+ # * Jeremy Hinegardner
11
+ # http://www.copiousfreetime.org/articles/2008/10/12/building-gems-for-windows.html
12
+ #
13
+ # * Aaron Patterson
14
+ # http://tenderlovemaking.com/2008/11/21/cross-compiling-ruby-gems-for-win32/
15
+
16
+ require 'pathname'
17
+ require 'rbconfig'
18
+
19
+ HOMEDIR = Pathname( '~' ).expand_path
20
+ RUBYVERSION = '1.8.6-p287'
21
+ RUBY_DL_BASE = 'ftp://ftp.ruby-lang.org/pub/ruby/1.8/'
22
+ RUBY_DL_URI = RUBY_DL_BASE + "ruby-#{RUBYVERSION}.tar.gz"
23
+
24
+ XCOMPILER_DIR = HOMEDIR + '.ruby_mingw32'
25
+
26
+ XCOMPILER_DL = XCOMPILER_DIR + "ruby-#{RUBYVERSION}.tar.gz"
27
+ XCOMPILER_SRC = XCOMPILER_DIR + "ruby-#{RUBYVERSION}"
28
+
29
+ XCOMPILER_BIN = XCOMPILER_DIR + 'bin'
30
+ XCOMPILER_RUBY = XCOMPILER_BIN + 'ruby.exe'
31
+
32
+ NEW_ALT_SEPARATOR = '"\\\\\" ' + ?\
33
+
34
+ CONFIGURE_CMD = %w[
35
+ env
36
+ ac_cv_func_getpgrp_void=no
37
+ ac_cv_func_setpgrp_void=yes
38
+ rb_cv_negative_time_t=no
39
+ ac_cv_func_memcmp_working=yes
40
+ rb_cv_binary_elf=no
41
+ ./configure
42
+ --host=i386-mingw32
43
+ --target=i386-mingw32
44
+ --build=#{RUBY_PLATFORM}
45
+ --prefix=#{XCOMPILER_DIR}
46
+ ]
47
+
48
+ begin
49
+ require 'archive/tar'
50
+
51
+ namespace :win32 do
52
+ directory XCOMPILER_DIR
53
+
54
+ file XCOMPILER_DL => XCOMPILER_DIR do
55
+ download RUBY_DL_URI, XCOMPILER_DL
56
+ end
57
+
58
+ directory XCOMPILER_SRC
59
+ task XCOMPILER_SRC => [ XCOMPILER_DIR, XCOMPILER_DL ] do
60
+ Archive::Tar.extract( XCOMPILER_DL, XCOMPILER_DIR, :compression => :gzip ) or
61
+ fail "Extraction of %s failed." % [ XCOMPILER_DL ]
62
+ end
63
+
64
+ file XCOMPILER_RUBY => XCOMPILER_SRC do
65
+ Dir.chdir( XCOMPILER_SRC ) do
66
+ File.open( 'Makefile.in.new', IO::CREAT|IO::WRONLY|IO::EXCL ) do |ofh|
67
+ File.each_line( 'Makefile.in' ) do |line|
68
+ line.sub!( /ALT_SEPARATOR = "\\\\"/, NEW_ALT_SEPARATOR )
69
+ ofh.write( line )
70
+ end
71
+ end
72
+
73
+ mv 'Makefile.in.new', 'Makefile.in'
74
+
75
+ run *CONFIGURE_CMD
76
+ end
77
+ end
78
+
79
+ task :build => XCOMPILER_RUBY do
80
+ log "Building..."
81
+ end
82
+ end
83
+
84
+ rescue LoadError => err
85
+ task :no_win32_build do
86
+ fatal "No win32 build: %s: %s" % [ err.class.name, err.message ]
87
+ end
88
+
89
+ namespace :win32 do
90
+ task :build => :no_win32_build
91
+ end
92
+
93
+ end
94
+
@@ -0,0 +1,247 @@
1
+ #!/usr/bin/ruby
2
+ # coding: utf-8
3
+
4
+ BEGIN {
5
+ require 'pathname'
6
+ basedir = Pathname.new( __FILE__ ).dirname.parent
7
+
8
+ libdir = basedir + "lib"
9
+ extdir = basedir + "ext"
10
+
11
+ $LOAD_PATH.unshift( libdir.to_s ) unless $LOAD_PATH.include?( libdir.to_s )
12
+ $LOAD_PATH.unshift( extdir.to_s ) unless $LOAD_PATH.include?( extdir.to_s )
13
+ }
14
+
15
+ require 'erb'
16
+
17
+ ### RSpec helper functions.
18
+ module PluginFactory::SpecHelpers
19
+
20
+ unless defined?( LEVEL )
21
+ LEVEL = {
22
+ :debug => Logger::DEBUG,
23
+ :info => Logger::INFO,
24
+ :warn => Logger::WARN,
25
+ :error => Logger::ERROR,
26
+ :fatal => Logger::FATAL,
27
+ }
28
+ end
29
+
30
+ ###############
31
+ module_function
32
+ ###############
33
+
34
+ ### Reset the logging subsystem to its default state.
35
+ def reset_logging
36
+ PluginFactory.reset_logger
37
+ end
38
+
39
+
40
+
41
+ ### Alter the output of the default log formatter to be pretty in SpecMate output
42
+ def setup_logging( level=Logger::FATAL )
43
+
44
+ # Turn symbol-style level config into Logger's expected Fixnum level
45
+ if LEVEL.key?( level )
46
+ level = LEVEL[ level ]
47
+ end
48
+
49
+ logger = Logger.new( $stderr )
50
+ PluginFactory.logger = logger
51
+ PluginFactory.logger.level = level
52
+
53
+ # Only do this when executing from a spec in TextMate
54
+ if ENV['HTML_LOGGING'] || (ENV['TM_FILENAME'] && ENV['TM_FILENAME'] =~ /_spec\.rb/)
55
+ PluginFactory.logger.formatter = HtmlLogFormatter.new( logger )
56
+ end
57
+ end
58
+
59
+
60
+ end
61
+
62
+
63
+ ### Make Logger output stuff in a form that looks nice(er) in SpecMate output.
64
+ class HtmlLogFormatter < Logger::Formatter
65
+ include ERB::Util # for html_escape()
66
+
67
+ unless defined?( HTML_LOG_FORMAT )
68
+ HTML_LOG_FORMAT = %q{
69
+ <dd class="log-message %5$s">
70
+ <span class="log-time">%1$s.%2$06d</span>
71
+ [
72
+ <span class="log-pid">%3$d</span>
73
+ /
74
+ <span class="log-tid">%4$s</span>
75
+ ]
76
+ <span class="log-level">%5$s</span>
77
+ :
78
+ <span class="log-name">%6$s</span>
79
+ <span class="log-message-text">%7$s</span>
80
+ </dd>
81
+ }
82
+ end
83
+
84
+ ### Override the logging formats with ones that generate HTML fragments
85
+ def initialize( logger, format=HTML_LOG_FORMAT ) # :notnew:
86
+ @logger = logger
87
+ @format = format
88
+ super()
89
+ end
90
+
91
+
92
+ ######
93
+ public
94
+ ######
95
+
96
+ # The HTML fragment that will be used as a format() string for the log
97
+ attr_accessor :format
98
+
99
+
100
+ ### Return a log message composed out of the arguments formatted using the
101
+ ### formatter's format string
102
+ def call( severity, time, progname, msg )
103
+ args = [
104
+ time.strftime( '%Y-%m-%d %H:%M:%S' ), # %1$s
105
+ time.usec, # %2$d
106
+ Process.pid, # %3$d
107
+ Thread.current == Thread.main ? 'main' : Thread.object_id, # %4$s
108
+ severity, # %5$s
109
+ progname, # %6$s
110
+ html_escape( msg ).gsub(/\n/, '<br />') # %7$s
111
+ ]
112
+
113
+ return self.format % args
114
+ end
115
+
116
+ end
117
+
118
+
119
+ # Override the badly-structured output of the RSpec HTML formatter
120
+ require 'spec/runner/formatter/html_formatter'
121
+
122
+ class Spec::Runner::Formatter::HtmlFormatter
123
+ def example_failed( example, counter, failure )
124
+ failure_style = failure.pending_fixed? ? 'pending_fixed' : 'failed'
125
+
126
+ unless @header_red
127
+ @output.puts " <script type=\"text/javascript\">makeRed('rspec-header');</script>"
128
+ @header_red = true
129
+ end
130
+
131
+ unless @example_group_red
132
+ css_class = 'example_group_%d' % [current_example_group_number || 0]
133
+ @output.puts " <script type=\"text/javascript\">makeRed('#{css_class}');</script>"
134
+ @example_group_red = true
135
+ end
136
+
137
+ move_progress()
138
+
139
+ @output.puts " <dd class=\"spec #{failure_style}\">",
140
+ " <span class=\"failed_spec_name\">#{h(example.description)}</span>",
141
+ " <div class=\"failure\" id=\"failure_#{counter}\">"
142
+ if failure.exception
143
+ backtrace = format_backtrace( failure.exception.backtrace )
144
+ message = failure.exception.message
145
+
146
+ @output.puts " <div class=\"message\"><code>#{h message}</code></div>",
147
+ " <div class=\"backtrace\"><pre>#{backtrace}</pre></div>"
148
+ end
149
+
150
+ if extra = extra_failure_content( failure )
151
+ @output.puts( extra )
152
+ end
153
+
154
+ @output.puts " </div>",
155
+ " </dd>"
156
+ @output.flush
157
+ end
158
+
159
+
160
+ if instance_methods.include?('global_styles') || instance_methods.include?(:global_styles)
161
+ alias_method :default_global_styles, :global_styles
162
+ else
163
+ def default_global_styles
164
+ "/* No default global_styles (methods: %p)?!? */" % [ instance_methods ]
165
+ end
166
+ end
167
+
168
+ def global_styles
169
+ css = default_global_styles()
170
+ css << %Q{
171
+ /* Stuff added by #{__FILE__} */
172
+
173
+ /* Overrides */
174
+ #rspec-header {
175
+ -webkit-box-shadow: #333 0 2px 5px;
176
+ margin-bottom: 1em;
177
+ }
178
+
179
+ .example_group dt {
180
+ -webkit-box-shadow: #333 0 2px 3px;
181
+ }
182
+
183
+ /* Style for log output */
184
+ dd.log-message {
185
+ background: #eee;
186
+ padding: 0 2em;
187
+ margin: 0.2em 1em;
188
+ border-bottom: 1px dotted #999;
189
+ border-top: 1px dotted #999;
190
+ text-indent: -1em;
191
+ }
192
+
193
+ /* Parts of the message */
194
+ dd.log-message .log-time {
195
+ font-weight: bold;
196
+ }
197
+ dd.log-message .log-time:after {
198
+ content: ": ";
199
+ }
200
+ dd.log-message .log-level {
201
+ font-variant: small-caps;
202
+ border: 1px solid #ccc;
203
+ padding: 1px 2px;
204
+ }
205
+ dd.log-message .log-name {
206
+ font-size: 1.2em;
207
+ color: #1e51b2;
208
+ }
209
+ dd.log-message .log-name:before { content: "«"; }
210
+ dd.log-message .log-name:after { content: "»"; }
211
+
212
+ dd.log-message .log-message-text {
213
+ padding-left: 4px;
214
+ font-family: Monaco, "Andale Mono", "Vera Sans Mono", mono;
215
+ }
216
+
217
+
218
+ /* Distinguish levels */
219
+ dd.log-message.debug { color: #666; }
220
+ dd.log-message.info {}
221
+
222
+ dd.log-message.warn,
223
+ dd.log-message.error {
224
+ background: #ff9;
225
+ }
226
+ dd.log-message.error .log-level,
227
+ dd.log-message.error .log-message-text {
228
+ color: #900;
229
+ }
230
+ dd.log-message.fatal {
231
+ background: #900;
232
+ color: white;
233
+ font-weight: bold;
234
+ border: 0;
235
+ }
236
+ dd.log-message.fatal .log-name {
237
+ color: white;
238
+ }
239
+ }
240
+
241
+ return css
242
+ end
243
+ end # module PluginFactory::SpecHelpers
244
+
245
+
246
+ # vim: set nosta noet ts=4 sw=4:
247
+