功能规格
功能规格是高级测试,旨在通过应用程序来执行功能片段。它们应该仅通过应用程序的外部接口(通常是网页)来驱动应用程序。
功能规格由 `type: :feature` 标记,或者如果设置了 `config.infer_spec_type_from_file_location!`,则将它们放置在 `spec/features` 中。
功能规格需要 Capybara gem,版本 2.13.0 或更高版本。有关可以在功能规格中使用的方法和匹配器的更多信息,请参阅 capybara API 文档。Capybara 旨在使用 HTTP 模拟浏览器请求。它将主要发送 HTML 内容。
feature
和 scenario
DSL 分别对应于 describe
和 it
。这些方法只是别名,允许功能规格读起来更像是 客户 和 验收 测试。当 capybara 被要求时,它会自动为您设置 `type: :feature`。
指定使用 capybara 驱动应用程序来创建小部件
给定一个名为“spec/features/widgetmanagementspec.rb”的文件,其中包含
require "rails_helper"
RSpec.feature "Widget management", type: :feature do
scenario "User creates a new widget" do
visit "/widgets/new"
click_button "Create Widget"
expect(page).to have_text("Widget was successfully created.")
end
end
当我运行 rspec spec/features/widget_management_spec.rb
时
那么该示例应该通过。