Permalink
Browse files

Replace rspec rake task and add SimpleCov support

New specs task avoids printing the lengthy file list only if tests fail
(or if --trace is used), and sort the file list so there are no more
env-specific test failures related to file load order. Tests should no
longer fail due to the way the underlying file system returns globs
to Ruby.
  • Loading branch information...
1 parent 0be9f16 commit d0f0d5a567f8fee2ec06e6d1eaa6243e0b74e837 @lsegal committed Oct 14, 2012
Showing with 32 additions and 51 deletions.
  1. +1 −0 Gemfile
  2. +18 −51 Rakefile
  3. +13 −0 spec/spec_helper.rb
View
@@ -4,6 +4,7 @@ group :development do
gem 'rspec'
gem 'rake'
gem 'rvm-tester'
+ gem 'simplecov'
end
group :markdown do
View
@@ -27,67 +27,34 @@ rescue LoadError
end
task :travis_ci do
- status = 0
ENV['SUITE'] = '1'
ENV['CI'] = '1'
- system "bundle exec rake specs"
- status = 1 if $?.to_i != 0
+ ENV['LEGACY'] = nil
+ Rake::Task['specs'].execute
if RUBY_VERSION >= '1.9' && RUBY_PLATFORM != 'java'
puts ""
puts "Running specs with in legacy mode"
- system "bundle exec rake specs LEGACY=1"
- status = 1 if $?.to_i != 0
+ ENV['LEGACY'] = '1'
+ Rake::Task['specs'].execute
end
- exit(status)
end
-begin
- hide = '_spec\.rb$,spec_helper\.rb$,ruby_lex\.rb$,autoload\.rb$'
- if YARD::Parser::SourceParser.parser_type == :ruby
- hide += ',legacy\/.+_handler'
- else
- hide += ',ruby_parser\.rb$,ast_node\.rb$,handlers\/ruby\/[^\/]+\.rb$'
- end
-
- require 'rspec'
- require 'rspec/core/rake_task'
-
- desc "Run all specs"
- RSpec::Core::RakeTask.new("specs") do |t|
- $DEBUG = true if ENV['DEBUG']
- t.rspec_opts = ENV['SUITE'] ? [] : ['-c']
- t.rspec_opts += ["--require", File.join(File.dirname(__FILE__), 'spec', 'spec_helper')]
- t.rspec_opts += ['-I', YARD::ROOT]
- t.pattern = "spec/**/*_spec.rb"
- t.verbose = $DEBUG ? true : false
-
- if ENV['RCOV']
- t.rcov = true
- t.rcov_opts = ['-x', hide]
- end
- end
- task :spec => :specs
-rescue LoadError
- begin # Try for rspec 1.x
- require 'spec'
- require 'spec/rake/spectask'
-
- Spec::Rake::SpecTask.new("specs") do |t|
- $DEBUG = true if ENV['DEBUG']
- t.spec_opts = ["--format", "specdoc", "--colour"]
- t.spec_opts += ["--require", File.join(File.dirname(__FILE__), 'spec', 'spec_helper')]
- t.pattern = "spec/**/*_spec.rb"
-
- if ENV['RCOV']
- t.rcov = true
- t.rcov_opts = ['-x', hide]
- end
- end
- task :spec => :specs
- rescue LoadError
- warn "warn: RSpec tests not available. `gem install rspec` to enable them."
+desc "Run all specs"
+task :specs do
+ opts = ['rspec', '-c']
+ opts += ["--require", File.join(File.dirname(__FILE__), 'spec', 'spec_helper')]
+ opts += ['-I', YARD::ROOT]
+ if ENV['DEBUG']
+ $DEBUG = true
+ opts += ['-d']
end
+ opts += FileList["spec/**/*_spec.rb"].sort
+ cmd = opts.join(' ')
+ puts cmd if Rake.application.options.trace
+ system(cmd)
+ raise "Command failed with status (#{$?.to_i}): #{cmd}" if $?.to_i != 0
end
+task :spec => :specs
YARD::Rake::YardocTask.new do |t|
t.options += ['--title', "YARD #{YARD::VERSION} Documentation"]
View
@@ -11,6 +11,19 @@
rescue LoadError
end
+begin
+ require 'simplecov'
+ SimpleCov.start
+ # TODO: hide some rb files from cov report
+ # hide = '_spec\.rb$,spec_helper\.rb$,ruby_lex\.rb$,autoload\.rb$'
+ # if YARD::Parser::SourceParser.parser_type == :ruby
+ # hide += ',legacy\/.+_handler'
+ # else
+ # hide += ',ruby_parser\.rb$,ast_node\.rb$,handlers\/ruby\/[^\/]+\.rb$'
+ # end
+rescue LoadError
+end if ENV['COVERAGE']
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'yard'))
unless defined?(HAVE_RIPPER)

0 comments on commit d0f0d5a

Please sign in to comment.