`

spectask.rb (/usr/lib/ruby/gems/1.8/gems/rspec-1.2.8/lib/spec/rake$ )

阅读更多
#!/usr/bin/env ruby

# Define a task library for running RSpec contexts.

require 'rake'
require 'rake/tasklib'
[size=large][/size]
module Spec
  module Rake

    # A Rake task that runs a set of specs.
    #
    # Example:
    #
    #   Spec::Rake::SpecTask.new do |t|
    #     t.warning = true
    #     t.rcov = true
    #   end
    #
    # This will create a task that can be run with:
    #
    #   rake spec
    #
    # If rake is invoked with a "SPEC=filename" command line option,
    # then the list of spec files will be overridden to include only the
    # filename specified on the command line.  This provides an easy way
    # to run just one spec.
    #
    # If rake is invoked with a "SPEC_OPTS=options" command line option,
    # then the given options will override the value of the +spec_opts+
    # attribute.
    #
    # If rake is invoked with a "RCOV_OPTS=options" command line option,
    # then the given options will override the value of the +rcov_opts+
    # attribute.
    #
    # Examples:
    #
    #   rake spec                                      # run specs normally
    #   rake spec SPEC=just_one_file.rb                # run just one spec file.
    #   rake spec SPEC_OPTS="--diff"                   # enable diffing
    #   rake spec RCOV_OPTS="--aggregate myfile.txt"   # see rcov --help for details
    #
    # Each attribute of this task may be a proc. This allows for lazy evaluation,
    # which is sometimes handy if you want to defer the evaluation of an attribute value
    # until the task is run (as opposed to when it is defined).
    #
    # This task can also be used to run existing Test::Unit tests and get RSpec
    # output, for example like this:
    #
    #   require 'spec/rake/spectask'
    #   Spec::Rake::SpecTask.new do |t|
    #     t.ruby_opts = ['-rtest/unit']
    #     t.spec_files = FileList['test/**/*_test.rb']
    #   end
    #
    class SpecTask < ::Rake::TaskLib
      def self.attr_accessor(*names)
        super(*names)
        names.each do |name|
          module_eval "def #{name}() evaluate(@#{name}) end" # Allows use of procs
        end
      end

      # Name of spec task. (default is :spec)
      attr_accessor :name

      # Array of directories to be added to $LOAD_PATH before running the
      # specs. Defaults to ['<the absolute path to RSpec's lib directory>']
      attr_accessor :libs

      # If true, requests that the specs be run with the warning flag set.
      # E.g. warning=true implies "ruby -w" used to run the specs. Defaults to false.
      attr_accessor :warning

      # Glob pattern to match spec files. (default is 'spec/**/*_spec.rb')
      # Setting the SPEC environment variable overrides this.
      attr_accessor :pattern

      # Array of commandline options to pass to RSpec. Defaults to [].
      # Setting the SPEC_OPTS environment variable overrides this.
      attr_accessor :spec_opts

      # Whether or not to use RCov (default is false)
      # See http://eigenclass.org/hiki.rb?rcov
      attr_accessor :rcov

      # Array of commandline options to pass to RCov. Defaults to ['--exclude', 'lib\/spec,bin\/spec'].
      # Ignored if rcov=false
      # Setting the RCOV_OPTS environment variable overrides this.
      attr_accessor :rcov_opts

      # Directory where the RCov report is written. Defaults to "coverage"
      # Ignored if rcov=false
      attr_accessor :rcov_dir

      # Array of commandline options to pass to ruby. Defaults to [].
      attr_accessor :ruby_opts

      # Whether or not to fail Rake when an error occurs (typically when specs fail).
      # Defaults to true.
      attr_accessor :fail_on_error

      # A message to print to stderr when there are failures.
      attr_accessor :failure_message

      # Where RSpec's output is written. Defaults to $stdout.
      # DEPRECATED. Use --format FORMAT:WHERE in spec_opts.
      attr_accessorut

      # Explicitly define the list of spec files to be included in a
      # spec.  +spec_files+ is expected to be an array of file names (a
      # FileList is acceptable).  If both +pattern+ and +spec_files+ are
      # used, then the list of spec files is the union of the two.
      # Setting the SPEC environment variable overrides this.
      attr_accessor :spec_files

      # Use verbose output. If this is set to true, the task will print
      # the executed spec command to stdout. Defaults to false.
      attr_accessor :verbose
     
      # Explicitly define the path to the ruby binary, or its proxy (e.g. multiruby)
      attr_accessor :ruby_cmd

      # Defines a new task, using the name +name+.
      def initialize(name=:spec)
        @name = name
        @libs = [File.expand_path(File.dirname(__FILE__) + '/../../../lib')]
        @pattern = nil
        @spec_files = nil
        @spec_opts = []
        @warning = false
        @ruby_opts = []
        @fail_on_error = true
        @rcov = false
        @rcov_opts = ['--exclude', 'lib\/spec,bin\/spec,config\/boot.rb']
        @rcov_dir = "coverage"

        yield self if block_given?
        @pattern = 'spec/**/*_spec.rb' if pattern.nil? && spec_files.nil?
        define
      end

      def define # :nodoc:
        spec_script = File.expand_path(File.dirname(__FILE__) + '/../../../bin/spec')

        lib_path = libs.join(File::PATH_SEPARATOR)
        actual_name = Hash === name ? name.keys.first : name
        unless ::Rake.application.last_comment
          desc "Run specs" + (rcov ? " using RCov" : "")
        end
        task name do
          RakeFileUtils.verbose(verbose) do
            unless spec_file_list.empty?
              # ruby [ruby_opts] -Ilib -S rcov [rcov_opts] bin/spec -- examples [spec_opts]
              # or
              # ruby [ruby_opts] -Ilib bin/spec examples [spec_opts]
              cmd_parts = [ruby_cmd || RUBY]
              cmd_parts += ruby_opts
              cmd_parts << %[-I"#{lib_path}"]
              cmd_parts << "-S rcov" if rcov
              cmd_parts << "-w" if warning
              cmd_parts << rcov_option_list
              cmd_parts << %[-o "#{rcov_dir}"] if rcov
              cmd_parts << %["#{spec_script}"]
              cmd_parts << "--" if rcov
              cmd_parts += spec_file_list.collect { |fn| %["#{fn}"] }
              cmd_parts << spec_option_list
              if out
                cmd_parts << %[> "#{out}"]
                STDERR.puts "The Spec::Rake::SpecTask#out attribute is DEPRECATED and will be removed in a future version. Use --format FORMAT:WHERE instead."
              end
              cmd = cmd_parts.join(" ")
              puts cmd if verbose
              unless system(cmd)
                STDERR.puts failure_message if failure_message
                raise("Command #{cmd} failed") if fail_on_error
              end
            end
          end
        end

        if rcov
          desc "Remove rcov products for #{actual_name}"
          task paste("clobber_", actual_name) do
            rm_r rcov_dir rescue nil
          end

          clobber_task = paste("clobber_", actual_name)
          task :clobber => [clobber_task]

          task actual_name => clobber_task
        end
        self
      end

      def rcov_option_list # :nodoc:
        if rcov
          ENV['RCOV_OPTS'] || rcov_opts.join(" ") || ""
        else
          ""
        end
      end

      def spec_option_list # :nodoc:
        STDERR.puts "RSPECOPTS is DEPRECATED and will be removed in a future version. Use SPEC_OPTS instead." if ENV['RSPECOPTS']
        ENV['SPEC_OPTS'] || ENV['RSPECOPTS'] || spec_opts.join(" ") || ""
      end

      def evaluate(o) # :nodoc:
        case o
          when Proc then o.call
          else o
        end
      end

      def spec_file_list # :nodoc:
        if ENV['SPEC']
          FileList[ ENV['SPEC'] ]
        else
          result = []
          result += spec_files.to_a if spec_files
          result += FileList[ pattern ].to_a if pattern
          FileList[result]
        end
      end

    end
  end
end
分享到:
评论

相关推荐

    arm-linux-gnueabi-5.4.0.tar

    /usr/local/arm/5.4.0/usr/bin/../libexec/gcc/arm-none-linux-gnueabi/5.4.0/cc1: error while loading shared libraries: libmpfr.so.4: cannot open shared object file: No such file or directory 解决方法: ...

    runtime library [libssl.so.1.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:/home/

    runtime library [libssl.so.1.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in: /home/rw/anaconda3/lib 首先查看路径,可以看到返回结果中,第一个查找路径是anaconda的。 export $PATH bash: export...

    libpaho-mqtt3as.so.zip

    v2x@ubuntu:~/Desktop$ sudo cp ./libpaho-mqtt3as.so/libpaho-mqtt3as.so /usr/lib/ v2x@ubuntu:~/Desktop$ sudo cp ./libpaho-mqtt3as.so/libpaho-mqtt3as.so.1 /usr/lib/ v2x@ubuntu:~/Desktop$ sudo cp ./...

    libgda5.0.0

    /usr/lib64/libgda-5.0.so.4 /usr/lib64/libgda-5.0.so.4.1.1 /usr/lib64/libgda-report-5.0.so.4 /usr/lib64/libgda-report-5.0.so.4.1.1 /usr/lib64/libgda-xslt-5.0.so.4 /usr/lib64/libgda-xslt-5.0.so.4.1.1 /...

    centos安装jdk1.8时出现没有/lib/ld-linux.so.2:这个文件的原因分析

    -bash: /usr/local/jdk/jdk1.8.0_181/bin/java: /lib/ld-linux.so.2: bad ELF interpreter: No such file or directory 安装完后 java -version 查看版本出现: 原因是:没有那个文件或目录,找了很久发现需要...

    linux 下liblzo库文件(64位系统编译32位软件时用)

    拷贝: /usr/lib/i386-linux-gnu/liblzo2.a /usr/lib/i386-linux-gnu/liblzo2.so.2.0.0 建立符号链接: ln -s /usr/lib/i386-...ln -s /usr/lib/i386-linux-gnu/liblzo2.so.2.0.0 /usr/lib/i386-linux-gnu/liblzo2.so

    java-1.7.0-openjdk-1.7.0.261-2.6.22.2.el7-8.aarch64.tar.gz

    基于arm64架构CentOS 7.9.2009 (AltArch)版本系统 ...打包/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.261-2.6.22.2.el7_8.aarch64 openEuler 20.04 LTS安装GConf2-devel后,可启动apache-tomcat-8.5.91

    cocoapods ruby error

    /usr/local/rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/pathname.rb:422:in `open': No such file or directory @ dir_initialize – /Users/David/.cocoapods/repos (Errno::ENOENT) from /usr/local/rvm/rubies/ruby-...

    main函数关联的crt目标文件

    /usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/crt1.o /usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/4.7/crtbegin.o /tmp/ccNY9dhT.o /usr/...

    解决usrlib64libstdc++.so.6和lib64libc.so.6版本过低问题

    ./bin/mysqld: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.15' not found (required by ./bin/mysqld) ./bin/mysqld: /lib64/libc.so.6: version `GLIBC_2.14' not found (required by ./bin/mysqld) ``` 这...

    java-1.8.0-openjdk-1.8.0.402.b06-1.el7-9.x86-64.rpm离线升级包

    使用`yum localinstall`命令,你可以指定路径来安装这些本地的`.rpm`包,例如 `yum localinstall ./*.rpm`,这将安装当前目录下所有`.rpm`文件。 对于Linux用户,尤其是系统管理员而言,理解如何处理这样的离线升级...

    jsoncpp-src-0.5.0.rar

    $ sudo cp ./libs/linux-gcc-7/* /usr/local/lib $ sudo cp -r ./include/json /usr/local/include/ $ cd /usr/local/lib $ sudo mv libjson_linux-gcc-7_libmt.a libjson.a $ sudo mv libjson_linux-gcc-7_...

    pcre-8.37.tar.gz和zlib-1.2.8.tar.gz

    2. 配置时,可能需要指定安装路径或者处理与其他库的依赖关系,例如`./configure --prefix=/usr/local`。 这两个库在源码安装时,需要确保系统具有必要的编译工具,如GCC编译器、make工具等。同时,如果在多版本...

    编译QT, version 'GLIBCXX_3.4.9' not found 的解决

    os.system("cp ./libstdc++.so.6.0.10 /usr/lib") os.system("ln -s /usr/lib/libstdc++.so.6.0.10 /usr/lib/libstdc++.so.6") 在64位linux操作系统上编译QT, 出现如上问题,请提取64bit文件夹下的libstdc++.so....

    php-rdkafka-3.1.2.tar.gz

    tar -zxvf librdkafka-1.2.0.tar.gz -C /usr/local/ && cd /usr/local/librdkafka-1.2.0 && ./configure && make && make install && ln -s /usr/local/lib/librdkafka.so.1 /usr/lib/ 安装php-rdkafka ...

    php-5.6.29.tar.gz

    编译 ./configure --prefix=/usr/local/...-with-config-file-path=/usr/local/php/etc --with-mysql-sock=/var/run/mysql/mysql.sock --with-mcrypt=/usr /i nclude --with-mhash --with-openssl --with-mysql=shared,...

    PHP 7的 librdkafka-1.2.0.tar.gz 扩展安装

    tar -zxvf librdkafka-1.2.0.tar.gz -C /usr/local/ && cd /usr/local/librdkafka-1.2.0 && ./configure && make && make install && ln -s /usr/local/lib/librdkafka.so.1 /usr/lib/ 安装php-rdkafka ...

    ubuntu 工具源码和安装说明-2

    ./configure --prefix=/usr/local/gcc --enable-threads=posix --disable-checking --disable-multilib --enable-languages=c,c++ --with-gmp=/usr/local/gmp --with-mpfr=/usr/local/mpfr --with-mpc=/usr/local/...

    libm.so.6 放到/usr/lib64/

    centos7 64位 import tensorflow 报错 ‘GLIBC_2.23' not found

    ubuntu 工具源码和安装说明

    ./configure --prefix=/usr/local/gcc --enable-threads=posix --disable-checking --disable-multilib --enable-languages=c,c++ --with-gmp=/usr/local/gmp --with-mpfr=/usr/local/mpfr --with-mpc=/usr/local/...

Global site tag (gtag.js) - Google Analytics