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

  • Home
  • SEARCH
  • 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 8552907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:31:58+00:00 2026-06-11T14:31:58+00:00

I am writing test for cotroller but without succes. My test is: describe VideosController

  • 0

I am writing test for cotroller but without succes. My test is:

describe VideosController do
  describe 'index' do
    it 'should select the index template for rendering' do
      Video.stub(:video_exists?).with("KgfdlZuVz7I").and_return(true)
      get :index, { :q => "KgfdlZuVz7I" }
      response.should render_template('index')
    end
  end
end

Here is controller.

class VideosController < ApplicationController
  def index
    if params[:q]
      params_hash = CGI::parse(params[:q])
      if Video.video_exists?(params_hash.values[0][0])
        video = Video.new :video_id => params_hash.values[0][0]
        if video.save!
          flash[:notification] = "Video found."
        else
          flash[:notification] = "Video found but not saved to database."
        end
        redirect_to root_path  
      else
        flash[:notification] = "Video not found."
        redirect_to root_path
      end
    end
  end
end

Test doesn’t pass and it raises message:

VideosController index should select the index template for rendering
Failure/Error: get :index, { :q => “KgfdlZuVz7I” }
received :video_exists? with une
xpected arguments
expected: (“KgfdlZuVz7I”)
got: (no args)
Please stub a default value first if message might be received with other args as well.
# ./app/controllers/videos_controller.rb:5:in index'
# ./spec/controllers/videos_controller_spec.rb:12:in
block (3 levels) in ‘

Think I am not stubbing Video on right way, because I stubbed just video_exists? but not new and save. But I don’t know how to resolve this since I am new in TDD and Rspec.

  • 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-11T14:31:59+00:00Added an answer on June 11, 2026 at 2:31 pm

    As piece of advice #1 you should not write out your “random string” twice like you did in your test. That is extremely susceptible to mistyping and very difficult to visually verify. Use this instead:

    rnd_id = "KgfdlZuVz7I"
    Video.stub(:video_exists?).with(rnd_id).and_return(true)
    get :index, { :q => rnd_id }
    

    Also, I’m not sure what params_hash = CGI::parse(params[:q]) is supposed to be doing. Why not just use the params like normal?

    class VideosController < ApplicationController
      def index
        if params[:q]
          if Video.video_exists?(params[:q])
            video = Video.new :video_id => params[:q]
            if video.save!
              flash[:notification] = "Video found."
            else
              flash[:notification] = "Video found but not saved to database."
            end
            redirect_to root_path  
          else
            flash[:notification] = "Video not found."
            redirect_to root_path
          end
        end
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a unit test and the controller method is throwing an exception
I writing test cases for Android apps using Robotium. One of my test cases
In writing Test case as I know, first step/task is to identify the Test
I'm writing test code that needs to clean up the entities it creates when
I'm fairly new to writing test cases and this will be my first major
We want to design a simple domain specific language for writing test scripts to
Writing a test app to emulate PIO lines, I have a very simple Python/Tk
I'm writing a test case where I'm trying to use mockito to avoid entering
I am writing a test using easymock + powermock, the reason I am using
I'm writing some test cases, and I've got a test case that is using

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.