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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:36:35+00:00 2026-06-13T21:36:35+00:00

Let say I want to test my controller behavior, but it accepts JSON string

  • 0

Let say I want to test my controller behavior, but it accepts JSON string via GET.

Right now I have var in my test class @testJson, but from time to time some unexpected stuff happens to those JSONS (bad char inside i.e.). So I want to add another test case.

But adding another var @problematicJson1 (and there could be more probably) doesn’t seems like a good idea.

What’s is the best way to keep “fixtures” like that? Should I keep’em in files and load them? Is there some fixture feature i don’t know about that could help?

  • 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-13T21:36:36+00:00Added an answer on June 13, 2026 at 9:36 pm

    Those things are not fixtures.

    You should use a neat feature of RSpec (if you are using RSpec at all) that allows to lazily define variables, so the actual variable is instantiated only when used by a specific “it”, even if it is defined in an outer “context/describe” block.

    https://www.relishapp.com/rspec/rspec-core/v/2-6/docs/helper-methods/let-and-let

    context "some context" do
      let(:testJson) { put your json inside the block }
      let(:otherJson) { {:my_json => textJson} } # this will use the defined testJson
    
      it "something" do
        testJson.should have_key "blah"
      end
    
      context "some internal context"
        let(:testJson) { something else }
    
        it "some other test" do
          otherJson[:my_json].should .... 
          # this will use the local version of testJson
          # you only have to redefine the things you need to, unlike a before block
        end
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let’s say that my string is: test! I want to get the first character
I want to get coverage of let's say CoverageTarget.dll. I have a test.dll to
Let's say I declare a variable: String a = test; And I want to
Let's say I want to make a Unit-Test where I have this Tetris game
Let's say I have two directory structures: /var/www/site1.prod /var/www/site1.test I want to use find(1)
let's say you added a controller and action (example: story/index ), and want to
Let's say I have an User entity and I would want to set it's
Let's say I have a method public void Foo(string bar) that the caller should
Let's say I want to connect to https://www.code.com/secure/test.xml and pull all the data. Before
Let's say I want to test a simple helper that takes a class name

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.