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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:04:33+00:00 2026-06-13T12:04:33+00:00

I’m very new to rspec, and rails, and ruby. I’m learning them at the

  • 0

I’m very new to rspec, and rails, and ruby. I’m learning them at the moment. I find myself puting a get or post request in every individual test I perform which isn’t very DRY. Do I need to keep issuing these requests for the test to work? or am i missing something fundamental?

EDIT:

For each test I’m performing I have to issue a get :page style request so that the controller will run the request. but when testing various aspects of the same action I repeatedly issue the same request and thus repeat the code. This is not DRY (Don’t repeat yourself).

describe "Find Movies With Same Director" do
    it "should respond, and find the requested movie" do
      stubFind()
      id = "1"
      get :match_director, :id=>id
      response.code.should eq("200")
    end

    it "should search for movies with the same director" do
      id = "1"
      Movie.should_receive(:match_director).with(id)
      get :match_director, :id=>id
    end

    it "should pass all matching movies to view" do
      id = "1"
      Movie.should_receive(:match_director).with(id).and_return("")
      get :match_director, :id=>id
      assigns[:movies].should not_be nil
    end

    it "should pass a list of movies" do
      id = "1"
      Movie.stub(:match_director).and_return(stub_model(Movie))
      get :match_director, :id=>id

      assigns[:movies].should be_instance_of(Movie)
    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-13T12:04:34+00:00Added an answer on June 13, 2026 at 12:04 pm

    If you are doing the same thing for several tests you can move them to a before block.

    describe 'something' do
        it 'should do one thing' do
            common_thing
            specific_thing
        end
    
        it 'should do one thing' do
            common_thing
            specific_thing
        end
    end
    

    becomes

    describe 'something' do
        before :each do
            common_thing
        end
    
        it 'should do one thing' do
            specific_thing
        end
    
        it 'should do one thing' do
            specific_thing
        end
    end
    

    If you want the common thing to be called only once for all tests then you replace before :each with before :all.

    EDIT: after seeing you edit I think that you could put the call get :match_director, :id=>id in a method and use it instead:

    def call_match_director
        get :match_director, :id=>id
    end
    

    Then it will be easy to add params to the call in one place. You can also put the id in a variable with the let construct:

    let(:id) { "1" }
    

    All in all like this:

    describe "Find Movies With Same Director" do
      let(:id) { "1" }
    
      def call_match_director
        get :match_director, :id=>id
      end
    
      it "should respond, and find the requested movie" do
        stubFind()
        call_match_director
        response.code.should eq("200")
      end
    
      it "should search for movies with the same director" do
        Movie.should_receive(:match_director).with(id)
        call_match_director
      end
    
      it "should pass all matching movies to view" do
        Movie.should_receive(:match_director).with(id).and_return("")
        call_match_director
        assigns[:movies].should not_be nil
      end
    
      it "should pass a list of movies" do
        Movie.stub(:match_director).and_return(stub_model(Movie))
        call_match_director
        assigns[:movies].should be_instance_of(Movie)
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a view passing on information from a database: def serve_article(request, id): served_article
I'm trying to create an if statement in PHP that prevents a single post
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have a jquery bug and I've been looking for hours now, I can't

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.