【发布时间】:2026-01-11 21:40:01
【问题描述】:
我有一组使用 RSpec2 和 Capybara 编写的请求规范。这是一个例子:
require 'spec_helper'
describe "Product Display and Interactions" do
it "should hide the price and show SOLD OUT in the product listing when appropriate" do
@product = Factory.create(:sold_out_product)
@product.sale = @sale
@product.save!
visit(sale_path(@sale))
@product.sold_out?.should eq(true)
find("#product_#{@product.id}").should have_content('Sold Out')
end
[...]
end
问题是我有几个不同的销售视图模板,每个模板都有自己的产品视图部分。是否有一种简洁的方法来指示 RSpec 每次运行一系列具有不同条件的规范?在这种情况下,我想在@sale 记录上设置一个属性,然后重新运行所有规范。
或者也许有更好的方法来完全测试这个场景?我是 RSpec 的新手,实际上完全是 Rails 的新手。
【问题讨论】:
标签: ruby ruby-on-rails-3 rspec tdd