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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:34:36+00:00 2026-05-13T08:34:36+00:00

I have a Sinatra app that serves pages as read-only or editable depending on

  • 0

I have a Sinatra app that serves pages as read-only or editable depending on if the user is logged in.

The controller sets a variable @can_edit, that is used by the views to hide/show edit links. How can I test @can_edit‘s value in my tests? I have no idea how to get at the current instance of the controller under Rack::Test.

I use class_eval to stub the logged_in? method in the controller, but I’m having to resort to checking last_response.body for my edit links to see if @can_edit has been set or not.

How can I test the value of @can_edit directly?

  • 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-13T08:34:36+00:00Added an answer on May 13, 2026 at 8:34 am

    Unfortunately I don’t think this is possible without modifying Rack::Test. When you make a request during application testing, Rack::Test does the following:

    1. adds the request to a list of recent requests
    2. creates a new instance of your application and invokes its call method
    3. adds your application’s response to a list of recent responses

    It’s easy to access the last_request and last_response, but unfortunately no information is saved about the state of your application while it’s running.

    If you’re interested in hacking together a Rack::Test patch to do this, start by looking at rack-test/lib/rack/mock_session.rb on line 30. This is where Rack::Test runs your application and receives the standard Rack app return values (status, headers, body). My guess is that you’re going to have to modify your application as well, to collect and make accessible all of its instance variables.

    In any case, it’s best to test for results, not implementation details. If you want to make sure an edit link is not visible, test for the presence of the edit link by DOM id:

    assert last_response.body.match(/<a href="..." id="...">/)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My (Sinatra) app intermittently goes into a bad state that I have only been
I have a Sinatra app that, boiled down, looks basically like this: class MyApp
I have a Sinatra app, that uses omniauth which constantantly gets this error attack
I have a Sinatra DataMapper app hitting a sqlite3 database that I am attempting
I have a .Net XML webservice that I need a simple Sinatra app to
I have a simple Sinatra app that I will be hosting in tomcat as
I have a Sinatra app that basically takes some input values and then finds
So I have a few machines in production that are running a Sinatra app
I have a simple Sinatra app that I am playing with, and for some
I have a basic Ruby app that I am building with Sinatra, Datamapper and

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.