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 4101174
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:39:45+00:00 2026-05-20T20:39:45+00:00

in rspec, I have a spec that looks something like this: require ‘spec_helper’ describe

  • 0

in rspec, I have a spec that looks something like this:

require 'spec_helper'

describe IncomingMailsController do

  include Devise::TestHelpers

  it "should find the correct text in the sample" do
  sample_text = '100s of these'
  target_text = 'find me'
   .... ALL Kinds of stuff to process (30+ lines)
   thread.content.should == 'find me'
  end

end

Is there a way with rspec, to allow me to somehow use all that logic in one block? And then create 100s of it “xxxxx” do, and pass that a variable being the sample text?

Thanks

  • 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-20T20:39:46+00:00Added an answer on May 20, 2026 at 8:39 pm

    You can put the it test blocks inside a loop, and run through a collection of all the times you want to each for (in the example below those items are in the search_items collection)

    require 'spec_helper'
    
    describe IncomingMailsController do
    
      include Devise::TestHelpers
    
      search_items.each do |item|
        it "should find the correct text (#{item}) in the sample" do
          sample_text = '100s of these'
          target_text = item
          .... ALL Kinds of stuff to process (30+ lines)
          thread.content.should == 'find me'
        end
      end
    
    end
    

    UPDATE

    I saw on a comment to another answer in this threase that you have a directory with 100+ files of samples, you can get the list of filenames using Dir#glob. You can then use that in the loop to generate your it test cases.

    UPDATE 2

      Dir.glob('/path/to/files/*.txt').each do |file_name|
        it "should find the correct text in the sample #{file_name}" do
          file_content = File.open(file_name, "rb")
          sample_text = '100s of these'
          target_text = 'fine me'
          .... ALL Kinds of stuff to process (30+ lines)
          thread.content.should == 'find me'
        end
      end
    

    You might have to play with the full path of file_name but that should get you some of the way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Rails RSpec file which looks something like require 'spec_helper' describe Something
I've got an rspec test which looks something like this: require 'require_all' require_rel '../spec_helper'
I have a Rakefile that looks like this: require 'rspec/core/rake_task' desc Run all RSpec
I have the following rspec code: require 'spec_helper' require 'mocha' require 'rr' describe ProjectsController,
I'm getting 4 RSpec errors that have something to do with the Will-Paginate gem,
I have controller methods that look like this: class TestController < ApplicationController def testAction
I have a nested controller that works fine, and I'd like to setup rspec
I have the following RSpec example which is passing: describe UsersController do it should
I have problems to get rspec running properly to test validates_inclusion_of my migration looks
I'm going through a tutorial that has suggested using rspec , but I have

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.