Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6825555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:02:43+00:00 2026-05-26T22:02:43+00:00

I have a set of request specs written using RSpec2 and Capybara. Here’s one

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T22:02:43+00:00Added an answer on May 26, 2026 at 10:02 pm

    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

    require 'spec_helper'
    describe "Product Display and Interactions" do
    
        ["attr_value_1", "attr_value_2"].each do |sale_attr_value|
          it "should hide the price and show SOLD OUT in the product listing when sale attribute is set to #{sale_attr_value}" do
            @product = Factory.create(:sold_out_product)
            @sale.attribute_to_alter = sale_attr_value
            @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
    
      [...]
    
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have set up a local server using XAMPP. I am making a request
I have set up a version control system using TortoiseSVN at my home to
I have set my app to initially request location as soon as it loads
I am performing a curl request to a page. I have set both 'CURLOPT_TIMEOUT'
I have set up 2 apache servers, one for 80 port and second for
How to set multiple Content-Types? I have to pass an array to request body.
I have Delphi XE. I try to set Request.Range of idHttp but I cannot
I have set my app's initial view with storyboard to the main one. I
I have set up the OAuth request following the documentation for a Non-Google Service
I have set up i18n to my web app using Spring.It works fine.But I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.