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:'
4

1 に答える 1

0

テスト データベースには、開発データベースと同じデータが入力されていないと思われます。

于 2012-05-24T12:16:56.900 に答える