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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:59:37+00:00 2026-06-06T13:59:37+00:00

I am running a sinatra app and have a testing suite setup using rspec

  • 0

I am running a sinatra app and have a testing suite setup using rspec 2.7.0 and webrat 0.7.3 (both the most recent versions). I have an extensive set of tests for all of my request actions and it seems to be working fine. Today I discovered Sinatra’s redirect back request-level helper and implemented it in a couple of areas of my application that were rendering forms with get requests which were taking parameters.

The nice thing about the redirect back helper is that if I have an action say:

get '/login' do
  @used_var = params[:var]
  haml :login
end

Which renders a form, I can have validation on the post request receiving the form:

post '/login' do
  # pretend User.authenticate pulls back a user entry from the database if there
  # is a valid username/password combination
  unless User.authenticate(params[:username], params[:password]).nil?
    redirect '/content'
  else
    flash[:notice] = "Invalid username/password combo"
    redirect back # will redirect back to the get '/login' request
  end
end

And if the form doesn’t validate properly, it will redirect back to the page with the from and retain any parameters that were passed in without me having to worry about storing it to a session variable. The only problem is that rspec doesn’t seem to want to play nicely with the redirect back helper. i.e. if I have a spec action that does this:

it 'should redirect to login when invalid username/password combo is received.' do
  get '/login', :var => 'value'
  fill_in 'username', :with => 'invalid_username'
  fill_in 'password', :with => 'invalid_password'
  click_button 'Submit'
  last_response.should be_redirect; follow_redirect!
  last_request.url.should include("/login")
end

The spec fails to pass because for some reason it seems that rspec or webrat isn’t picking up on the redirect back helper and is instead redirecting the request back to the root url for my application ('/').

What I want to know is whether there is a way to get rspec to redirect to the proper location in these instances? The actual application functions as expected when I test it with my browser (it redirects me to the first page with parameters), but the rspec tests don’t pass properly.

  • 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-06T13:59:40+00:00Added an answer on June 6, 2026 at 1:59 pm

    Apparently this was a bug in rack, and it appears to have been fixed with the release of rack 1.3.0. I tested this spec with rack 1.2.5 (most recent version prior to 1.3.0 release), and it failed, but upon upgrading to 1.3, it started passing.

    After some digging around, pretty sure that this pull request (here is the commit) was the change that fixed it.

    So it is no longer an issue in rack ~> 1.3.

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

Sidebar

Related Questions

So I have a few machines in production that are running a Sinatra app
I have a production ruby sinatra app running on nginx/passenger, and I frequently see
I have a sinatra app running locally and awhile back I ran into an
I have a sinatra app running on heroku. My problem: I always get redirected
Running rails 3.2.3 with guard/spork/rspec/factory_girl and have the following in my spec helper: Spork.prefork
I've been trying to get a simple hello world web app running on Sinatra.
I'm trying to integrate rspec_api_documentation (https://github.com/zipmark/rspec_api_documentation) into my sinatra app. I'm running into the
I'm building a Facebook app called Lovers , using a Sinatra app on Heroku
I'm developing a sinatra app, and I'd like to test it using cucumber and
I have s sinatra app warbled and deployed on glassfish. I have used bundler

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.