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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:28:52+00:00 2026-05-23T10:28:52+00:00

Please consider this test: def test_ok_on_second_request bad_response = @request.get /bad-response assert_equal 404, bad_response.status good_response

  • 0

Please consider this test:

def test_ok_on_second_request
  bad_response = @request.get "/bad-response"
  assert_equal 404, bad_response.status

  good_response = @request.get "/test-title"
  assert_equal 200, good_response.status
  assert_equal "text/html", good_response.content_type
end

I have assured that /test-title is a valid path. The assertion that’s supposed to return 200 is in fact returning 404. How is Rack behaving in order to return two different results for the same request?

This is the code for the Server class inside the project:

module Blogrite
  class Server
    attr_accessor :status, :mimetype, :body, :provider
    def initialize *args, &block
      @status, @mimetype = 200, "text/html"
      provider = args[0][:with].nil? ? :filesystem : args[0][:with]
      @provider = Blogrite.const_get(provider.capitalize).new
      # p "Server is running with #{@provider.class}."
    end

    def call env
      begin
        article   = go env['PATH_INFO'].delete("/")
      rescue Blogrite::Article::NoBodyError
        @status = 404
      end

      @status   = 404 if !article
      @status   = 403 if env["REQUEST_METHOD"] == 'POST'
      @mimetype = "text/css" if env["PATH_INFO"].include?("css")
      @body     = if article then article.render
                  elsif env.respond_to?(:to_yaml) then "<pre>#{env.to_yaml}</pre>"
                  else "oops"
                  end

      [@status,{ "Content-Type" => @mimetype},[@body]]
    end

    def go path
      f = @provider.fetch path
      Article.parse f unless f.nil?
    end
  end
end

The whole workflow is too big for me to paste it in but you can check the project out on Github. I appreciate your help, thank you.

  • 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-23T10:28:52+00:00Added an answer on May 23, 2026 at 10:28 am

    The solution for the problem is as simple as initializing @status inside the call function.

        class Server
          attr_accessor :status, :mimetype, :body, :provider
          def initialize *args, &block
     -      @status, @mimetype = 200, "text/html"
            provider = args[0][:with].nil? ? :filesystem : args[0][:with]
            @provider = Blogrite.const_get(provider.capitalize).new
            # p "Server is running with #{@provider.class}."
          end
    
          def call env
            begin
     -        article   = go env['PATH_INFO'].delete("/")
     +        @status, @mimetype = 200, "text/html"
     +        article = go env['PATH_INFO'].delete("/")
            rescue Blogrite::Article::NoBodyError
              @status = 404
            end
    

    That way the rack instance – that is called only once – stays out of the request’s way. Every call function should have its own defaults, not the server class.

    Thanks to @rubenfonseca for helping me out.

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

Sidebar

Related Questions

Please consider the simple express.js route: app.get(/test, function(req, res) { if(condition1) { res.render(foo, {
Please consider the following test program (using scala 2.9.0.1) object test { def main(args:Array[String])
Please consider this snippet: http://fruple.com/kemper/test/categorie.html Firefox screenshot: Chrome screenshot why are some of the
Please consider this example class: [Serializable] public class SomeClass { private DateTime _SomeDateTime; public
Please consider this code: template<typename T> char (&f(T[1]))[1]; template<typename T> char (&f(...))[2]; int main()
Please consider this site . I'm having trouble stretching the submenu list items in
This is a complex question, please consider carefully before answering. Consider this situation. Two
This is a very basic question, so please bear with me. Consider the following
Please consider the following code: public class Person ( public string FirstName {get; set;}
I encountered this problem while solving a practice test Consider this C code to

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.