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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:52:56+00:00 2026-06-06T12:52:56+00:00

How can I match the following array with Rspec ? [#<struct Competitor html_url=https://github.com/assaf/vanity, description=Experiment

  • 0

How can I match the following array with Rspec ?

[#<struct Competitor html_url="https://github.com/assaf/vanity", description="Experiment Driven Development for Ruby", watchers=845, forks=146>, 
 #<struct Competitor html_url="https://github.com/andrew/split", description="Rack Based AB testing framework", watchers=359, forks=43>]

I need to check if a class method return an array of struct like the previous or a more extensive one which include the previous.

UPDATE:

I currently have this test which go green,

require 'spec_helper'
  describe "Category" do
    before :each do
      @category = Category.find_by(name: "A/B Testing")
    end

    describe ".find_competitors_by_tags" do
      it "returns a list of competitors for category" do
        competitors = Category.find_competitors_by_tags(@category.tags_array).to_s
        competitors.should match /"Experiment Driven Development for Ruby"/
      end
    end
  end
end

but I’d like to know if it is the correct way to test the following method or you think it could be better :

class Category
  ...

  Object.const_set :Competitor, Struct.new(:html_url, :description, :watchers, :forks)
  def self.find_competitors_by_tags(tags_array)
    competitors = []

    User.all_in('watchlists.tags_array' => tags_array.map{|tag|/^#{tag}/i}).only(:watchlists).each do |u|
      u.watchlists.all_in(:tags_array => tags_array.map{|tag|/^#{tag}/i}).desc(:watchers).each do |wl|
        competitors << Competitor.new(wl.html_url, wl.description, wl.watchers, wl.forks)
      end
    end
    return competitors
  end
end
  • 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-06-06T12:52:57+00:00Added an answer on June 6, 2026 at 12:52 pm

    I would test the minimum needed to make sure that your find function works correctly. You probably don’t need to check every field for the returned records for that. What you have does that. I’d modify it a bit, to just look at the description (or whatever other field is appropriate):

      it "returns a list of competitors for category" do
        competitors = Category.find_competitors_by_tags(@category.tags_array)
        descriptions = competitors.map(&:description).sort
        descriptions.should == [
          "Experiment Driven Development for Ruby",
          "Rack Based AB testing framework",
        ]
      end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can you match the following words by PHP, either by regex/globbing/...? Examples INNO,
How can i match the following dates with python regular expression in one statement,
How can you match the following figure in $_GET by PHP? I have the
Can anyone tell me why the following code might not cycle through the array
i want to implement the following exhaustive match, but i can't figure out to
One can use numpy 's extract function to match an element in an array.
I have the following array and can't figure out how to get the data
I know i can match numbers with Pattern.compile(\\d*); But it doesn't handle the long
How can I build a regular expression in python which can match all the
How can I match a field in the MySql-Database with a regular expression that

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.