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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:20:21+00:00 2026-05-29T10:20:21+00:00

I use before do content_type text/html, :charset => utf-8 end in my sinatra app.

  • 0

I use

before do
  content_type "text/html", :charset => "utf-8"
end

in my sinatra app.

How can I check if this works in my rspec tests?
I though it should be something like:

it "should be utf-8 encoded" do
  get '/'
  last_response.body.encoding.should == 'utf-8'
end

But encoding does not return a string.

  • 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-29T10:20:22+00:00Added an answer on May 29, 2026 at 10:20 am

    You have two encoding to take care:

    • the encoding of the response declared in the Content-Type header,
    • the encoding in which Ruby has stored the response body inside the last_reponse.body object.

    A good Rack application should make sure that the two are kept in sync and are coherent with each other, but some middleware component or coding error could make them mismatch them. So you have to test both.

    This test will make sure that the body string is encoded in ‘UTF-8’.

    it "should be UTF-8 encoded" do
        get '/'
        last_response.body.encoding.name.should == 'UTF-8'
    end
    

    Here we are testing how the body string is encoded as Ruby object.

    (Please beware that code this will work only on Ruby 1.9.x.)

    Instead, if you want to test whether the server has declared an UTF-8 content type for the body, you should use

    it "should have UTF-8 content type" do
        get '/'
        last_response.content_type.should =~ /UTF-8/
    end
    

    In this second test we check whether the server declared that it is using the UTF-8 encoding setting the Content-Type header to something that contains UTF-8.

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

Sidebar

Related Questions

can use anything in any order? does placing of <meta http-equiv=Content-Type content=text/html;charset=UTF-8> is important
In my iPhone app I'm actually detecting text/html content type before showing data in
<head> <meta http-equiv=Content-Type content=text/html; charset=UTF-8 /> [{CONTENT:meta}] [{CONTENT:title}] [{CONTENT:head}] </head> [{CONTENT:open_body}] <p>[{LOCATION:main_1}]</p> <p>[{LOCATION:main_1}]</p> </body>
I want to ask why we use this keyword before the parameter in an
I've always assumed that before I can use the Dvorak layout I need to
I use Visual Studio 2008. I haven't seen this behavior before and, as far
I have 2 pages written in JSP the first page contains: <%@page contentType=text/html pageEncoding=UTF-8%>
Is there any way to first test if a file is in use before
I want to use the before action to optionally interrupt the processing if it
I've seen code samples that use an @ before fopen as in $fh =

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.