你会如何测试这个?我想在不同条件下多次测试一组规格
我有一组使用 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 的新手。
I have a set of request specs written using RSpec2 and Capybara. Here's one example:
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
The issue is that I have several different view templates for Sale, each with their own view partials for products. Is there a clean easy way to instruct RSpec to run a series of specs with a varying condition each time? I'd like to set an attribute on the @sale record in this case and then run all the specs over again.
Or maybe there is a better approach to testing this scenario altogether? I'm new to RSpec and actually to Rails altogether.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有“更好”的方法来测试这一点,但是,目前,如果您是新手,我建议您习惯测试和轨道,而不要混淆问题。
您可以根据您当前的情况执行以下操作。这将为 @sale#attribute_to_alter 上的每个变体创建一个单独的示例
There are 'better' ways to test this, but, for the time being, if you are new, I'd recommend getting used to testing and rails without confusing the issue.
You can do something like the following for your current situation. This will create a separate example for each variation on @sale#attribute_to_alter