spec/lib/swagger/swagger_dsl_spec.rb in apipie-rails-0.9.3 vs spec/lib/swagger/swagger_dsl_spec.rb in apipie-rails-0.9.4

- old
+ new

@@ -22,21 +22,21 @@ return get_ref(schema['$ref']) end schema end - def swagger_response_for(path, code=200, method='get') + def swagger_response_for(path, code = 200, method = 'get') response = swagger[:paths][path][method][:responses][code] response[:schema] = resolve_refs(response[:schema]) response end - def swagger_params_for(path, method='get') + def swagger_params_for(path, method = 'get') swagger[:paths][path][method][:parameters] end - def swagger_param_by_name(param_name, path, method='get') + def swagger_param_by_name(param_name, path, method = 'get') params = swagger_params_for(path, method) matching = params.select{|p| p[:name] == param_name } raise "multiple params named [#{param_name}] in swagger definition for [#{method} #{path}]" if matching.length > 1 nil if matching.length == 0 @@ -70,11 +70,11 @@ match do |actual| deep_match?(actual, expected) end - def deep_match?(actual, expected, breadcrumb=[]) + def deep_match?(actual, expected, breadcrumb = []) pending_params = actual.params_ordered.dup expected.each do |expected_param| expected_param_name = expected_param.is_a?(Hash) ? expected_param.keys.first : expected_param actual_param = pending_params.find { |param| param.name.to_s == expected_param_name.to_s } unless actual_param @@ -336,10 +336,11 @@ expect(returns_obj.code).to eq(201) expect(returns_obj.is_array?).to eq(false) expect(returns_obj).to match_field_structure([:pet_name, :animal_type]) end + it 'should have the 201 response described in the swagger' do response = swagger_response_for('/pets/{id}/extra_info', 201) expect(response[:description]).to eq("Found a pet") schema = response[:schema] @@ -357,10 +358,11 @@ expect(returns_obj).to match_field_structure([:pet_name, :animal_type, {:pet_measurements => [:weight, :height, :num_legs]} ]) end + it 'should have the 202 response described in the swagger' do response = swagger_response_for('/pets/{id}/extra_info', 202) expect(response[:description]).to eq('Accepted') schema = response[:schema] @@ -386,10 +388,11 @@ {:pet_measurements => [:weight, :height,:num_legs]}, {:pet_history => [:did_visit_vet, :avg_meals_per_day]}, {:additional_histories => [:did_visit_vet, :avg_meals_per_day]} ]) end + it 'should have the 203 response described in the swagger' do response = swagger_response_for('/pets/{id}/extra_info', 203) expect(response[:description]).to eq('Non-Authoritative Information') schema = response[:schema] @@ -422,10 +425,11 @@ expect(returns_obj.code).to eq(204) expect(returns_obj.is_array?).to eq(false) expect(returns_obj).to match_field_structure([:int_array, :enum_array]) end + it 'should have the 204 response described in the swagger' do response = swagger_response_for('/pets/{id}/extra_info', 204) schema = response[:schema] expect(schema).to have_field(:int_array, 'array', {items: {type: 'number'}}) @@ -442,10 +446,11 @@ expect(returns_obj).to match_field_structure([:pet_name, :animal_type, :num_fleas ]) end + it 'should have the 422 response described in the swagger' do response = swagger_response_for('/pets/{id}/extra_info', 422) expect(response[:description]).to eq('Fleas were discovered on the pet') schema = response[:schema] @@ -566,9 +571,10 @@ expect(returns_obj).to match_field_structure([:pet_name, :animal_type, {:pet_measurements => [:weight, :height, :num_legs]} ]) end + it 'should have the 200 response described in the swagger' do response = swagger_response_for('/pets_with_measurements_described_as_class/{id}', 200) expect(response[:description]).to eq('measurements of the pet') schema = response[:schema]