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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T13:04:10+00:00 2026-05-21T13:04:10+00:00

I am trying to validate one block of json data that I receive from

  • 0

I am trying to validate one block of json data that I receive from server

json consists of information about bunch of orders. An each order includes cost of each part, taxes and total. And it is kind of strict requirement each order contains exactly 4 parts. And each order has three kind of taxes and a total.

I have a step which looks like this

   And "standardorder" includes parts "1..4", taxes "1..3" and total

and step implementation is like following. Here @jsonhelper.json is shared state (json for one order) passed from previous step.

 And /^"([^"]*)" includes parts "([^"]*)", taxes "([^"]*)" and total$/ do |arg1, arg2, arg3|
    json = @jsonhelper.json
    validkeys = ["total"]

    parts = arg2.split('..').map{|d| Integer(d)}
    (parts[0]..parts[1]).each do |i|
        validkeys.push "p#{i}"
    end

    taxes = arg3.split('..').map{|d| Integer(d)}
    (taxes[0]..taxes[1]).each do |i|
        validkeys.push "t#{i}"
    end

    validkeys.each do |key|
        json[arg1].keys.include?(key).should be_true
    end 
end

Now this script works fine except that if any one key is missing it doesn’t state which one is missing. Either it passes or fails as assertions are iterated for each key.

I would like to know if there is any possibility of sending keys which are found ok to result stream. Thus my intention is to know to which keys are ok and which failed and which one skipped. As such order of keys is not expected in json.

Thanks in advance.

  • 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-21T13:04:10+00:00Added an answer on May 21, 2026 at 1:04 pm

    It’s probably best to split the step definitions first:

     And "standardorder" should be received
     And the order should include parts 1 to 4
     And the order should include taxes 1 to 3
     And the order should include the total 
    

    Then you can re-use the steps elsewhere.

    The ‘order’ check easy to implement as you’re just checking one element.

    For the other two, you are really just checking the presence of items in an array, e.g.:

    actual_values.should == expected_values
    

    If that fails, RSpec will give you a report showing how the arrays differ.

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

Sidebar

Related Questions

I'm trying to validate one xml that I create with a local schema, but
I'm trying to validate some POST data. One of the validations I need to
I'm trying to validate that a submitted URL doesn't already exist in the database.
I am currently trying to validate a form server side, the way it works
I'm trying to write a xml schema that will validate this piece of xml:
I'm trying to validate an attribute in one model when I destroy another model.
I'm trying to validate uniqueness of some field in my model with one catch
I'm trying to validate a flash form. In one case I need to know
I have an matrix in this format that I am trying to validate and
I have a simple form with fields that I am trying to validate using

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.