← 返回命令列表

Linux command

rspec 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Run all specs

rspec

Run specific file

rspec [spec/models/user_spec.rb]

Run specific line

rspec [spec/models/user_spec.rb:25]

Run with tag

rspec --tag [focus]

Exclude tag

rspec --tag ~[slow]

Format output

rspec --format documentation

Run failed specs

rspec --only-failures

Random order

rspec --order random

说明

rspec is Ruby's behavior-driven testing framework. It provides readable test syntax. Spec files describe expected behavior. Examples verify code meets expectations. Matchers provide expressive assertions. Should, expect, and various comparison methods. Tags organize and filter tests. Focus on specific categories or skip slow tests. Failure tracking enables running only failed tests. Speeds up debugging cycles. Formatters output results in various styles. Documentation format shows nested describe blocks.

参数

--format _FORMAT_
Output format.
--tag _TAG_
Run tagged examples.
--only-failures
Run previously failed.
--order _ORDER_
Execution order.
--fail-fast
Stop on first failure.
--profile _N_
Show slowest examples.
--dry-run
Show without running.
-e, --example _PATTERN_
Match example name.

FAQ

What is the rspec command used for?

rspec is Ruby's behavior-driven testing framework. It provides readable test syntax. Spec files describe expected behavior. Examples verify code meets expectations. Matchers provide expressive assertions. Should, expect, and various comparison methods. Tags organize and filter tests. Focus on specific categories or skip slow tests. Failure tracking enables running only failed tests. Speeds up debugging cycles. Formatters output results in various styles. Documentation format shows nested describe blocks.

How do I run a basic rspec example?

Run `rspec` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does --format _FORMAT_ do in rspec?

Output format.