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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:24:01+00:00 2026-06-18T02:24:01+00:00

I want to test this method in my controller. def fetch_match_displayed_count(params) match_count = 0

  • 0

I want to test this method in my controller.

def fetch_match_displayed_count(params)
  match_count = 0
  params.each do |param|
    match_count += 1 if param[1]["result"] && param[1]["result"] != "result"
  end
  match_count
end

This is the test I’ve written so far.

describe "fetch_match_displayed_count" do
  it "should assign match_count with correct number of matches" do
    params = {"result_1"=>{"match_id"=>"975", "result"=>"not_match"}, "result_2"=>{"match_id"=>"976", "result"=>"match"}, "result_3"=>{"match_id"=>"977", "result"=>"not_sure"}, "result_4"=>{"match_id"=>"978", "result"=>"match"}, "result_5"=>{"match_id"=>"979", "result"=>"not_match"}, "workerId"=>"123", "hitId"=>"", "assignmentId"=>"", "controller"=>"mt_results", "action"=>"create"}
    controller.should_receive(:fetch_match_displayed_count).with(params)
    get :fetch_match_displayed_count, {params:params}
    assigns(:match_count).should == 5
  end
end

My problem seems to lie in this line get :fetch_match_displayed_count, {params:params}
The method is expecting params, but is getting nil.

I have two questions.

  1. Should this method be in a helper and not in the controller itself (per Rails convention)?

  2. How do I submit a get request and pass params in my test?

  • 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-18T02:24:02+00:00Added an answer on June 18, 2026 at 2:24 am

    As a general rule, you should test the public interface of your class. For a controller, this means you test actions, not helper methods.

    You should be able to make this work by setting up one or more separate test cases that call the appropriate action(s), then use a message expectation to test that the helper method is called with the right arguments — or test that the helper method does what it is supposed to do (sets the right instance variables/redirects/etc).

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

Sidebar

Related Questions

As in the title, I want to test a method like this: public void
I have this code in my controller and want to test this code line
Say I have a vector: (def data [Hello World Test This]) And I want
I have a method in my Controller which looks like this: @RequestMapping(value = /test,
I want to test if a sentence contains anything else than white-space characters. This
I have this string: Test: String And I want to select the text before
I want to get the text field test out of this web page. How
i want the following functionality. input : this is test <b> bold text </b>
I want to do something like this: require 'erb' @var = 'test' template =
This is what i want to do: $line = 'blabla translate(test) blabla'; $line =

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.