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.
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