Guard::Minitest 项目教程

Guard::Minitest 项目教程

guard-minitestGuard::Minitest automatically run your tests (much like autotest)项目地址:https://gitcode.com/gh_mirrors/gu/guard-minitest

1. 项目的目录结构及介绍

Guard::Minitest 是一个用于自动运行 Minitest 测试的工具。项目的目录结构如下:

guard-minitest/
├── Gemfile
├── Guardfile
├── LICENSE.txt
├── README.md
├── Rakefile
├── guard-minitest.gemspec
├── lib/
│   ├── guard/
│   │   ├── minitest/
│   │   │   ├── runner.rb
│   │   │   ├── templates/
│   │   │   │   └── Guardfile
│   │   │   └── version.rb
│   │   └── minitest.rb
│   └── guard.rb
└── test/
    ├── guard/
    │   └── minitest/
    │       └── runner_test.rb
    ├── test_helper.rb
    └── minitest_test.rb

目录结构介绍

  • Gemfile:定义了项目所需的依赖。
  • Guardfile:项目的默认配置文件。
  • LICENSE.txt:项目的许可证文件。
  • README.md:项目的说明文档。
  • Rakefile:用于定义 Rake 任务。
  • guard-minitest.gemspec:项目的 gemspec 文件。
  • lib/:包含项目的核心代码。
    • guard/:Guard 插件的核心代码。
      • minitest/:Minitest 插件的具体实现。
        • runner.rb:测试运行器。
        • templates/:模板文件。
        • version.rb:版本信息。
      • minitest.rb:Minitest 插件的入口文件。
    • guard.rb:Guard 的主文件。
  • test/:包含项目的测试代码。
    • guard/:Guard 插件的测试代码。
      • minitest/:Minitest 插件的测试代码。
    • test_helper.rb:测试辅助文件。
    • minitest_test.rb:Minitest 测试文件。

2. 项目的启动文件介绍

Guard::Minitest 的启动文件是 lib/guard/minitest.rb。这个文件是 Minitest 插件的入口文件,负责初始化和启动 Guard::Minitest。

require 'guard/compat/plugin'
require 'guard/minitest/runner'

module Guard
  class Minitest < Plugin
    def initialize(options = {})
      super
      @options = options
      @runner = ::Guard::Minitest::Runner.new(options)
    end

    def start
      run_all if @options[:all_on_start]
    end

    def run_all
      UI.info 'Running all tests'
      @runner.run(['--verbose'])
    end

    def run_on_changes(paths)
      UI.info "Running tests for #{paths.join(' ')}"
      @runner.run(paths)
    end
  end
end

启动文件介绍

  • require 'guard/compat/plugin':引入 Guard 的兼容插件。
  • require 'guard/minitest/runner':引入 Minitest 的运行器。
  • initialize:初始化方法,设置选项和运行器。
  • start:启动方法,如果设置了 all_on_start 选项,则运行所有测试。
  • run_all:运行所有测试的方法。
  • run_on_changes:在文件变化时运行测试的方法。

3. 项目的配置文件介绍

Guard::Minitest 的配置文件是 Guardfile。这个文件定义了 Guard 的行为,包括监视哪些文件和目录,以及在文件变化时执行哪些操作。

标准 Guardfile 配置

使用 Minitest::Unit 的 Guardfile
guard :minitest do
  watch(%r[^test/(.*)\/test_(.*)\.rb$])
  watch(%r[^lib/(.*)/(.*)\.rb$]) { |m| "test/#{m[1]}/test_#{m[2]}.rb" }
  watch(%r[^test/test

guard-minitestGuard::Minitest automatically run your tests (much like autotest)项目地址:https://gitcode.com/gh_mirrors/gu/guard-minitest

  • 13
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

娄祺杏Zebediah

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值