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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:55:09+00:00 2026-06-17T02:55:09+00:00

I have the following spec… describe successful POST on /user/create do it should redirect

  • 0

I have the following spec…

  describe "successful POST on /user/create" do
    it "should redirect to dashboard" do
      post '/user/create', {
          :name => "dave",
          :email => "dave@dave.com",
          :password => "another_pass"
      }
      last_response.should be_redirect
      follow_redirect!
      last_request.url.should == 'http://example.org/dave/dashboard'
    end
  end

The post method on the Sinatra application makes a call to an external service using rest-client. I need to somehow stub the rest client call to send back canned responses so I don’t have to invoke an actual HTTP call.

My application code is…

  post '/user/create' do
    user_name = params[:name]
    response = RestClient.post('http://localhost:1885/api/users/', params.to_json, :content_type => :json, :accept => :json)
    if response.code == 200
      redirect to "/#{user_name}/dashboard"
    else
      raise response.to_s
    end
  end

Can someone tell me how I do this with RSpec? I’ve Googled around and come across many blog posts which scratch the surface but I can’t actually find the answer. I’m pretty new to RSpec period.

Thanks

  • 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-17T02:55:11+00:00Added an answer on June 17, 2026 at 2:55 am

    Using a mock for the response you can do this. I’m still pretty new to rspec and test in general, but this worked for me.

    describe "successful POST on /user/create" do
      it "should redirect to dashboard" do
        RestClient = double
        response = double
        response.stub(:code) { 200 }
        RestClient.stub(:post) { response }
    
        post '/user/create', {
          :name => "dave",
          :email => "dave@dave.com",
          :password => "another_pass"
        }
        last_response.should be_redirect
        follow_redirect!
        last_request.url.should == 'http://example.org/dave/dashboard'
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following spec to test controller method: context #create do it should redirect
I have the following factory: factory :user do name 'Henk' email 'foo@bar.co' password 'foobar'
I have following Rspec test: describe Productlimit do before(:each) do @productlimit = Factory.create(:productlimit, :user
I have the following spec describe user enters 150 into time do before do
I have the following code in a spec: it 'should save some favorite locations'
I have the following factories: Factory.define :producer, :class => User do |f| f.sequence(:email) {
I have the following spec: describe EmailImport do describe #format_x_priority do specify { EmailImport.format_x_priority('5
Currently in my spec/decorators/product_decorator_spec.rb, I have the following: require 'spec_helper' describe ProductDecorator do let(:product)
I have following controller spec which passes. But I would like to replace create(:link)
I have the following spec: it saves a default 'active' status if not specified

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.