/
test_endpoint.feature
106 lines (90 loc) 路 2.87 KB
/
test_endpoint.feature
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
Feature: test endpoint
If your API is stable and the new code isn't breaking it
you'll see nothing special, just passing specs
**NOTE:** the second request example is expecting a successful response and it is,
but specs are NOT passing because of nonsufficient `name` parameter
**NOTE:** the third response example is expecting a successful response and it is,
but specs are NOT passing because of nonsufficient `role` attribute
Background:
Given a file named "lurker/api/v1/users/__id-PATCH.json.yml" with:
"""yml
---
prefix: 'users management'
description: 'user updating'
requestParameters:
properties:
id:
type: integer
example: 1
user:
type: object
properties:
name:
type: string
example: Bob
responseCodes:
- status: 400
successful: true
description: ''
- status: 200
successful: true
description: ''
responseParameters:
properties:
id:
type: integer
example: 1
name:
type: string
example: Bob
surname:
type: string
example: Marley
extensions:
path_info: "/api/v1/users/1"
method: PATCH
path_params:
controller: api/v1/users
action: update
id: 1
"""
Scenario: json schema tests request and response using "users/update"
Given a file named "spec/controllers/api/v1/users_controller_spec.rb" with:
"""ruby
require "spec_helper"
describe Api::V1::UsersController, :lurker do
render_views
let(:user) do
User.where(name: 'razum2um').first_or_create!
end
it "updates a user" do
patch :update, id: user.id, user: { name: 'Bob' }
expect(response).to be_success
end
end
"""
When I run `bin/rspec spec/controllers/api/v1/users_controller_spec.rb`
Then the example should pass
Scenario: json schema tests response parameters and tell what fails using "users/update"
Given a file named "spec/controllers/api/v1/users_controller_blank_spec.rb" with:
"""ruby
require "spec_helper"
describe Api::V1::UsersController, :lurker do
render_views
let(:user) do
User.where(name: 'razum2um').first_or_create!
end
it "updates a user" do
patch :update, id: user.id, user: { name: '' }, format: 'json'
expect(response).not_to be_success
end
end
"""
When I run `bin/rspec spec/controllers/api/v1/users_controller_blank_spec.rb`
Then the output should contain failures:
"""
Lurker::ValidationError:
Response
The property '#/' contains additional properties ["errors"]
1 example, 1 failure
"""