forked from cucumber/cucumber-rails
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrest_api.feature
47 lines (45 loc) · 1.28 KB
/
rest_api.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
Feature: REST API
Scenario: Compare JSON
Given I have created a new Rails app "rails-3-app" and installed cucumber-rails
And I write to "app/controllers/posts_controller.rb" with:
"""
class PostsController < ApplicationController
def index
render json: {'hello' => 'world'}.to_json
end
end
"""
And I write to "config/routes.rb" with:
"""
Rails3App::Application.routes.draw do
resources :posts
end
"""
And I write to "features/posts.feature" with:
"""
Feature: posts
Scenario: See them
When the client requests GET /posts
Then the response should be JSON:
\"\"\"
{
"hello": "world"
}
\"\"\"
"""
And I write to "features/step_definitions/rest_steps.rb" with:
"""
When /^the client requests GET (.*)$/ do |path|
get(path)
end
Then /^the response should be JSON:$/ do |json|
JSON.parse(last_response.body).should == JSON.parse(json)
end
"""
And I run `bundle exec rake db:migrate`
And I run `bundle exec rake cucumber`
Then the feature run should pass with:
"""
1 scenario (1 passed)
2 steps (2 passed)
"""