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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:04:29+00:00 2026-06-04T15:04:29+00:00

I am new to cucumber testing. I am trying to test a simple api,

  • 0

I am new to cucumber testing. I am trying to test a simple api, which upon request to get “/main/state_list” will return a list of states in json.

My .feature file

 Feature: Check if valid states are returned in json
 In order to select a state
 As a user
 I want to know if valid states are returned in json

 Scenario: Get list of states
 Given A GET request is made
 Then the result should be list of states in JSON:
 """
 [{"state":"California","_id":"4fbca64718a7ad0a68000003"},   
 {"state":"Georgia","_id":"4fbca69618a7ad0a68000005"}]
 """

My .rb Steps file

 Given /^A GET request is made$/ do
 get "/main/state_list"
 end
 Then /^the result should be list of states in JSON:$/ do |str|
 json_data=JSON.parse(last_response.body)
 json_data.should  == JSON.parse(str)
 end

My controller code

def state_list
@states= State.all
render :json => @states.to_json
end

When I visit the url in a browser directly I get the out put correctly

When I run cucumber in my cmd I get this error. Basically empty response was sent.

 host is not a valid option for Mongo::Connection
 Feature: Check if valid states are returned in json
 In order to select a state
 As a user
 I want to know if valid states are returned in json

 Scenario: Get list of states        # features\check_list_of_states.feature:6
 Given A GET request is made        #features/step_definitionscheck_list_of_states_steps.rb:2
 Then the result should be list of states in JSON: # features/step_definition/check_list_of_states_steps.rb:5
  """
  [{"state":"California","_id":"4fbca64718a7ad0a68000003"},{"state":"Georgia","_id":"4fbca69618a7ad0a68000005"}]
  """
  expected: [{"_id"=>"4fbca64718a7ad0a68000003", "state"=>"California"}, {"_
  id"=>"4fbca69618a7ad0a68000005", "state"=>"Georgia"}]
       got: [] (using ==)
  Diff:
  @@ -1,3 +1,2 @@
  -[{"_id"=>"4fbca64718a7ad0a68000003", "state"=>"California"},
  - {"_id"=>"4fbca69618a7ad0a68000005", "state"=>"Georgia"}]
  +[]
   (RSpec::Expectations::ExpectationNotMetError)
  ./features/step_definitions/check_list_of_states_steps.rb:8:in `/^the resu
  lt should be list of states in JSON:$/'
  features\check_list_of_states.feature:8:in `Then the result should be list
  of states in JSON:'
  • 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-04T15:04:31+00:00Added an answer on June 4, 2026 at 3:04 pm

    I suspect your test database isn’t populated with the same data as your development database.

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

Sidebar

Related Questions

I'm new to rails and cucumber and I'm trying to test the following scenario
I am new to Cucumber testing and I am trying to understand when to
I'm trying to visit a page with cucumber, with: visit new_video_path but I get
I'm currently trying to set up integration/acceptance testing for a new rails 3 application
I've got a cucumber step that is trying to populate objects, including a new
I'm new to Ruby, and I've been trying to learn Rake, RSpec, and Cucumber.
I am new to capybara but I am trying to use it to test
I'm trying to get some Cucumber tests working with Devise, and I have the
I'm new to cucumber and I find following snippets to test the Devise login
New Question I am looking for a way in Javascript to get the parent

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.