首页
/ Combustion 项目技术文档

Combustion 项目技术文档

2024-12-26 12:34:55作者:晏闻田Solitary

1. 安装指南

Combustion 是一个用于测试 Rails 引擎的库,它允许你在引擎的上下文中编写规范,而无需在 spec 或 test 文件夹中创建完整的 Rails 应用程序。

安装步骤:

  1. 将 Combustion 添加到你的 gemspec 或 Gemfile 中,根据你管理引擎依赖的方式:
# gemspec
gem.add_development_dependency 'combustion', '~> 1.3'

# Gemfile
gem 'combustion', '~> 1.3'
  1. 在你的 spec_helper.rb 文件中,让 Combustion 进行设置,这需要在引入 rspec/railscapybara/rails 之前完成:
require 'bundler'

Bundler.require :default, :development

Combustion.initialize! :all
# 或者,仅加载你所需要的部分:
# Combustion.initialize! :active_record, :action_controller

require 'rspec/rails'
  1. 运行以下命令来创建一个最小的文件集:
combust
# 或者,如果你正在使用 git 仓库:
bundle exec combust

2. 项目使用说明

Combustion 允许你在引擎的上下文中编写规范,使用你需要的 Rails 部分来测试你的 Rails 引擎。

  • 使用 Combustion.initialize! 方法来设置需要加载的 Rails 模块。
  • spec/internal 目录下创建所需的 Rails 应用程序文件。
  • 根据需要修改数据库配置和模式。
  • 设置路由和控制器,以便测试引擎的功能。

3. 项目API使用文档

Combustion 提供以下 API 方法:

  • Combustion.initialize!(modules: :all):初始化 Combustion,加载所有关键 Rails 部分。
  • Combustion.initialize!(modules: [:active_record, :action_controller, ...]):初始化 Combustion,仅加载指定的 Rails 部分。
  • Combustion.path = 'spec/dummy':设置内部 Rails 应用程序的路径。
  • Combustion.schema_format = :sql:配置 Combustion 使用 SQL 文件来初始化数据库。

4. 项目安装方式

安装 Combustion 的方式如下:

  1. 将 Combustion 添加到你的 gemspec 或 Gemfile 中。
  2. 运行 bundle install 来安装依赖。
  3. spec_helper.rb 中设置 Combustion。
  4. 运行 combust 命令来创建所需的内部 Rails 应用程序文件。

确保你的项目遵循上述安装步骤,以便正确设置和运行测试。

登录后查看全文
热门项目推荐