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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:54:25+00:00 2026-05-24T03:54:25+00:00

My controller action: def single final_static_matrix = Single.final_static_matrix(average_static_matrix, params[:priorities]) … end In my lib/single.rb:

  • 0

My controller action:

 def single
    final_static_matrix = Single.final_static_matrix(average_static_matrix, params[:priorities])
   
     ...

  end

In my lib/single.rb:

module Single
  def self.final_static_matrix(average_static_matrix = {}, priorities = {})
    final_static_matrix = Hash.new

    for i in 0..average_static_matrix.length-1
      final_static_matrix[i.to_s] = average_static_matrix*priorities[i.to_s]
    end

    final_static_matrix
  end
end

In my controller_spec.rb:

it "should be successful" do
  get :single, :id => 1
  priorities = {"0" => "1"}
  matrix = {"0" => "3"}
  Single.final_static_matrix(matrix, priorities)
  response.should be_success
end
  1. How I should call the function from lib/ directory?
  2. How be better if i will write tests in controller file or create something like single_spec.rb?
  • 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-24T03:54:25+00:00Added an answer on May 24, 2026 at 3:54 am

    What I would do: inside the controller-spec, I would test that the method gets called:

    describe "GET :single" do
      it "succeeds" do
        Single.should_receive(:final_static_matrix).and_return('something')
    
        get :single, :id => 1
      end
    end
    

    and inside spec/lib/single_spec.rb you test that the final_static_matrix acts as expected.

    You can check the documentation of rspec2 here.

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

Sidebar

Related Questions

I have the following controller action: def create @board = Board.new(params[:board]) respond_to do |format|
I have the following controller action and test. I'm new to testing with Shoulda
Assume the following code in a Grails controller: def action = { ClassName o
I have question model which has many options. In my question controller new action
I'm on Rails 2.3.5. In a typical user controller create action class UsersController def
I have a controller that has the following index action : def index if
Relevent codes routes.rb Waterloop3::Application.routes.draw do resources :submissions match ':controller(/:action(/:id(.:format)))' end submission_controller.rb - Contains an
In Ruby on Rails you can write a simple controller action such as: def
My Controller Action accepts int id. What to do when calling from View ActionLink
I have a controller action that is being executed by a link that was

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.