title: Matching a complex data structure (an array of structs) with Rspec
body: <p>How can I match the following array with Rspec ?</p>
  
  <pre><code>[#&lt;struct Competitor html_url="https://github.com/assaf/vanity", description="Experiment Driven Development for Ruby", watchers=845, forks=146&gt;, 
   #&lt;struct Competitor html_url="https://github.com/andrew/split", description="Rack Based AB testing framework", watchers=359, forks=43&gt;]
  </code></pre>
  
  <p>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.</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I currently have this test which go green, </p>
  
  <pre><code>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
  </code></pre>
  
  <p>but I'd like to know if it is the correct way to test the following method or you think it could be better :</p>
  
  <pre><code>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' =&gt; tags_array.map{|tag|/^#{tag}/i}).only(:watchlists).each do |u|
        u.watchlists.all_in(:tags_array =&gt; tags_array.map{|tag|/^#{tag}/i}).desc(:watchers).each do |wl|
          competitors &lt;&lt; Competitor.new(wl.html_url, wl.description, wl.watchers, wl.forks)
        end
      end
      return competitors
    end
  end
  </code></pre>