安裝 RSpec

安裝 RSpec gem 的最常用方法是使用 Bundler 。將此行新增到你的應用程式的 Gemfile

gem 'rspec'

然後執行 bundle 來安裝依賴項:

$ bundle

或者,你可以手動安裝 gem:

$ gem install rspec

安裝 gem 後,執行以下命令:

rspec --init

這將為你的測試建立一個 spec 資料夾,以及以下配置檔案:

  • 一個 spec 目錄,用於放置 spec 檔案
  • 帶有預設配置選項的 spec/spec_helper.rb 檔案
  • 帶有預設命令列標誌的 .rspec 檔案