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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:22:13+00:00 2026-06-17T15:22:13+00:00

Trying understand syntax for testing around the Tire gem. This controller spec (default from

  • 0

Trying understand syntax for testing around the Tire gem.

This controller spec (default from a scaffold template) is failing

  describe "GET index" do
    it "assigns all reports as @reports" do
      report = Report.create! valid_attributes
      get :index, {}, valid_session
      assigns(:reports).should eq([report])
    end
  end

because

 Failure/Error: assigns(:reports).should eq([report])
 TypeError:
   can't convert Tire::Results::Collection to Array (Tire::Results::Collection#to_ary gives Tire::Results::Collection)

How to write the spec so that it expects a Tire result collection instead of an array of active record objects? Or, is there a better way to go about this?

FWIW-

class ReportsController < ApplicationController  
  def index
    @reports = Report.search(params)
  end

  ...

and the model:

class Report < ActiveRecord::Base
  include Tire::Model::Search
  include Tire::Model::Callbacks
  ...
  def self.search(params)
    tire.search(load: true) do
      query { string params[:query] } if params[:query].present?
    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-17T15:22:15+00:00Added an answer on June 17, 2026 at 3:22 pm

    I realise this is an insanely late answer, but hey, here goes.

    Rspec is doing a direct comparison. It has a collection, and it’s trying to compare it to the array. However, Tyre defines the cast to an array to not actually return an array (why, I’m not sure, sounds annoying to me!)

    Given as you aren’t meant to compare an array, then I had a quick peek at the source of Collection : https://github.com/karmi/tire/blob/master/lib/tire/results/collection.rb

    Well, we don’t have a to_ary that’s useful…but we do have an each, and the inclusion of Enumerable. This means that we have basically everything that’s available to an array.

    So, given that, what do we actually want to do here? We want to check that @report is available inside @reports. Well, we have enumerable, and a quick check of the expectations source( https://github.com/rspec/rspec-expectations/blob/master/lib/rspec/matchers/built_in/include.rb#L38 ) says that include will map to include? on an arrayesque object.

    So, in short, try changing your test to:

    describe "GET index" do
      it "assigns all reports as @reports" do
       report = Report.create! valid_attributes
       get :index, {}, valid_session
       assigns(:reports).should include(report)
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to understand PNG format. Consider this PNG Image: The Image is taken from
Hi I am trying to understand why I get a syntax error for this:
so I was watching a tutorial and I am trying to understand this syntax
I am new to Python and I am trying to understand this syntax: a,
I am trying to understand some C++ syntax: template<class T> class Foo { Foo();
Trying to understand Ruby a bit better, I ran into this code surfing the
Trying to understand the math of this code snippet. A token is provided which
Im trying to understand how class generics work and this bit just doesnt make
I'm trying to understand the syntax used in STL for a class. Our teacher
I'm a C# guy trying to learn Java. I understand the syntax and the

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.