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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:22:01+00:00 2026-05-18T05:22:01+00:00

I would like to test a controller that directly renders some JSON output (by

  • 0

I would like to test a controller that directly renders some JSON output (by using “render :json => @entity_names”). For that task I tried in my spec file “response.should have_text(‘[“enim”, “enita”]’)”. Unfortunately I always get that error:
Failure/Error: response.should have_text(‘[“enim”, “enita”]’)
undefined method `has_text?’ for #

Do I miss some gem that provides that method? Here my Gemfile:

source 'http://rubygems.org'

gem 'rails', '>= 3.0.0'
gem 'mysql2'
gem 'mongrel'
gem 'devise'
gem 'will_paginate', :git => 'git://github.com/mislav/will_paginate.git', :branch =>    'rails3'
gem 'thinking-sphinx', :git     => 'git://github.com/freelancing-god/thinking-sphinx.git', :branch  => 'rails3', :require => 'thinking_sphinx'

group :test, :development do
  gem 'rspec-rails', '>= 2.0.0.beta.19'
  gem 'steak', :git => 'git://github.com/cavalle/steak.git'
  gem 'webrat'
  gem 'capybara'
  gem 'capybara-envjs'
  gem 'shoulda'
  gem 'launchy'
  gem 'autotest'
  gem 'autotest-rails'
  gem 'test_notifier'
  gem 'rails3-generators'
  gem 'factory_girl_rails'
  gem 'populator'
  gem 'faker'
  gem 'random_data'
  gem 'database_cleaner', :git => 'git://github.com/bmabey/database_cleaner.git'
  gem 'delorean'
end
  • 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-18T05:22:02+00:00Added an answer on May 18, 2026 at 5:22 am

    You could construct your expected output as JSON, then get the response body (which is also JSON), decode both, and compare them. Something like:

    it "should do something" do
      expected = { :some_key => "and some value" }.to_json 
      xhr :post, :create, { :foo => "bar" }
      ActiveSupport::JSON.decode(response.body).should == ActiveSupport::JSON.decode(expected)
    end 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've written some applications than heavily use network, and I would like to test
I am using Moq for unit testing and I would like to test for
(please excuse that I didn't use aliases). I would like my query output to
I would like to perform an audit as part of a unit test that
I would like to test a string containing a path to a file for
I would like to test a function with a tuple from a set of
I am starting out with automated testing and I would like to test one
My main JavaScript framework is jQuery , so I would like my unit test
I would like to be able to build test applications (e.g. the nightly Minefield/Firefox)
I would like to know what a Unit test and Web Test is in

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.