class RSpec::Core::RakeTask

def bundler

def bundler
  File.exist?("./Gemfile") ? "bundle exec " : ""
end

def define # :nodoc:

:nodoc:
def define # :nodoc:
  actual_name = Hash === name ? name.keys.first : name
  desc("Run RSpec code examples") unless ::Rake.application.last_comment
  task name do
    RakeFileUtils.send(:verbose, verbose) do
      if files_to_run.empty?
        puts "No examples matching #{pattern} could be found"
      else
        puts spec_command.inspect if verbose
        unless ruby("-S #{spec_command}")
          STDERR.puts failure_message if failure_message
          raise("#{spec_command} failed") if fail_on_error
        end
      end
    end
  end
  self
end

def files_to_run # :nodoc:

:nodoc:
def files_to_run # :nodoc:
  FileList[ pattern ].to_a
end

def initialize(*args)

def initialize(*args)
  @name = args.shift || :spec
  @pattern, @rcov_path, @rcov_opts, @ruby_opts = nil, nil, nil, nil
  @warning, @rcov = false, false
  @fail_on_error = true
  @spec_opts = []
  yield self if block_given?
  @rcov_path ||= 'rcov'
  @pattern ||= './spec/**/*_spec.rb'
  define
end

def runner

def runner
  rcov ? rcov_path : RUBY
end

def runner_options

def runner_options
  rcov ? [rcov_opts] : [ruby_opts]
end

def spec_command

def spec_command
  @spec_command ||= begin
                      cmd_parts = %w[-Ilib -Ispec]
                      cmd_parts << "-w" if warning
                      cmd_parts.unshift runner_options
                      cmd_parts.unshift runner
                      cmd_parts.unshift bundler
                      cmd_parts += files_to_run.map { |fn| %["#{fn}"] }
                      cmd_parts << spec_opts.join(" ")
                      cmd_parts.join(" ")
                    end
end