cucoo 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6c785eb8e5a8993bd6aae1db703047d0cbabf617
4
- data.tar.gz: 634f9f70b65aeb031994644b2f129f3b3afa9133
3
+ metadata.gz: 66bad9fda5aed0527088b95c9908af54d44cf771
4
+ data.tar.gz: ccb0bb323e5d3e1f1a8680d3bac96500790558e9
5
5
  SHA512:
6
- metadata.gz: 660f32172f08fba6ca9e3fd9452b667916b90be3112753b4727bacd24ea3f1c59fe737429de856d641feb25f2165c1fb4959fc7defc13dadd22df10c83043dcc
7
- data.tar.gz: 16fa9e30ffc24b4638f437f93a0c592ce5669d457420c5c74ce906ecb333d8432ecc765834cbdf04ccf0d1ae2e510962c78e998c65be8f0f74eeacd17d58d7b3
6
+ metadata.gz: 6de3dd6e1cb365bbbf39301ca233fa29ef26ba63b75f3d26fd0a4c19559ef46210dab2f28d3e6cd9d84a02050080108a03865fcfe0e9c3e2c334f99a035adf76
7
+ data.tar.gz: e31cdaace674706c95f2312c0be8c7b0ab1e73e69cd14e016ba1a56b92088520a24e3376067c489e408644da9df92d8bd6f51ab8a55773ea80a24f3bab770544
@@ -0,0 +1 @@
1
+ cucoo
@@ -0,0 +1 @@
1
+ ruby-2.1.3
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Cucoo
2
2
 
3
- TODO: Write a gem description
3
+ Cucumber steps and assertions for testing your APIs. This gem offers a DSL on top of webmock, cucumber and json_spec to make testing APIs on rails easier.
4
4
 
5
5
  ## Installation
6
6
 
@@ -18,9 +18,167 @@ Or install it yourself as:
18
18
 
19
19
  $ gem install cucoo
20
20
 
21
- ## Usage
21
+ ## Configuration
22
22
 
23
- TODO: Write usage instructions here
23
+ Cucoo comes as a package with the following gems installed
24
+
25
+ * [json_spec](https://github.com/collectiveidea/json_spec)
26
+ * [cucumber](https://github.com/cucumber/cucumber-rails)
27
+ * [webmock](https://github.com/bblimke/webmock)
28
+
29
+ A typical env.rb would look like this:
30
+
31
+ ```ruby
32
+ require 'cucoo/rails'
33
+
34
+ ActionController::Base.allow_rescue = false
35
+
36
+ require File.expand_path('../../../config/environment', __FILE__)
37
+
38
+ Capybara.default_driver = :selenium
39
+
40
+ Cucumber::Rails::Database.javascript_strategy = :truncation
41
+
42
+ Cucoo.config do |config|
43
+ config.app_port = 6666
44
+ config.stub_host = 'localhost'
45
+ config.stub_port = 4080
46
+ end
47
+ ```
48
+
49
+ This will start your application on port 6666 on localhost and assume the external services are stubbed at specified host and port.
50
+
51
+ ## Ping Pong Test
52
+ Our app responds to a url `/health/ping.json` with ping. The test to assert this is as follows
53
+ ```cucumber
54
+ Scenario: Health Checker
55
+ Given I make a GET to "/health/ping.json"
56
+ Then the response should be OK
57
+ And the response body must be "pong"
58
+ ```
59
+
60
+ ## More examples
61
+
62
+ In all the examples, lets assume we are asserting calls to an external service with the url `/external_service/***`
63
+
64
+ 1) Simple hello world service that accepts two post body params `message` and `says` and calls an external service.
65
+ ```cucumber
66
+ Scenario: Post Hello World
67
+ Given I expect a POST to "/external_service/post_hello" with:
68
+ | request |
69
+ | {"message":"Hello World", "says": "John"} |
70
+ When I make a POST to "/hello_world" with:
71
+ | message | says |
72
+ | Hello World | John |
73
+ Then the response should be OK
74
+ ```
75
+
76
+ The last line does two things. It checks if the response code is 200 and also if the expectations were satisfied. So, this must be called at the end of each scenario.
77
+
78
+ 2) Let's build on top of previous example and let the app return back what the external service returns.
79
+
80
+ ```cucumber
81
+ Scenario: Post Hello World and accept response
82
+ Given I expect a POST to "/external_service/post_hello" with:
83
+ | request | response |
84
+ | {"message":"Hello World","says": "John"} | {"reply":"Get some life John"} |
85
+ When I make a POST to "/hello_world" with:
86
+ | message | says |
87
+ | Hello World | John |
88
+ Then the response should be OK
89
+ Then the JSON should be:
90
+ """
91
+ {
92
+ "reply": "Get some life John"
93
+ }
94
+ """
95
+ ```
96
+
97
+ Note that if the response from an external service is huge and can be read from a file, the POST expectation step can read from the file
98
+
99
+ ```cucumber
100
+ Given I expect a POST to "/external_service/post_hello" with:
101
+ | request | file |
102
+ | {"message":"Hello World","says": "John"} | stub/json/hello_world/response.json |
103
+ ```
104
+
105
+ The file will be read relative to the rails root path.
106
+
107
+ 3) Asserting a request body larger than hello world.
108
+
109
+ ```cucumber
110
+ Scenario: Add a new movie
111
+ Given I expect a POST to "/external_service/add_movie" with json request:
112
+ """
113
+ {
114
+ "name": "The Godfather",
115
+ "director": "Francis Coppola",
116
+ "year": 1972,
117
+ "rating": 9.2,
118
+ "runtime": 175
119
+ }
120
+ """
121
+ When I make a POST to "/movies" with:
122
+ | name | director | year | rating | runtime |
123
+ | The Godfather | Francis Coppola | 1972 | 9.2 | 175 |
124
+ Then the response should be OK
125
+ ```
126
+
127
+ 4) GET and json assertions
128
+
129
+ ```cucumber
130
+ Scenario: Get next token number
131
+ Given I expect a GET to "/external_service/next_free_slot" with:
132
+ | response |
133
+ | {"number": 42, "stats": {"total": 110, "free": 54} |
134
+ When I make a GET to "/next_id"
135
+ Then the response should be OK
136
+ And the JSON response at "stats" should be:
137
+ """
138
+ {"total": 110, "free": 54}
139
+ """
140
+ ```
141
+
142
+ In the above example, we have seen a slightly advanced version of asserting for json response. Please refer [json_spec doc](https://github.com/collectiveidea/json_spec#cucumber) for more examples of json response assertion.
143
+
144
+ We can also check for other response codes:
145
+
146
+ ```cucumber
147
+ Then the response should be NOT FOUND #404
148
+ Then the response should be BAD REQUEST #400
149
+ Then the response code should be "302" #custom response code
150
+ ```
151
+
152
+ 5) PUT request
153
+
154
+ ```cucumber
155
+ Scenario: Update employee details
156
+ Given I expect a PUT to "/external_service/employee/" with json request:
157
+ """
158
+ {
159
+ "id": 812,
160
+ "name": "Steve Balmer",
161
+ "status": "unemployed"
162
+ }
163
+ """
164
+ When I make a PUT to "employees" with:
165
+ | id | name | status |
166
+ | 812 | Steve Balmer | unemployed |
167
+ Then the response should be OK
168
+ ```
169
+
170
+ 6) DELETE request
171
+
172
+ ```cucumber
173
+ Scenario: Delete device token
174
+ Given I expect a DELETE to "/external_service/device/ab112321adceadcdf"
175
+ When I make a DELETE to "devices" with:
176
+ | token |
177
+ | ab112321adceadcdf |
178
+ Then the response should be OK
179
+ ```
180
+
181
+ This gem is very much a work-in-progress. We will keep adding more assertions with usage. Contributions welcome
24
182
 
25
183
  ## Contributing
26
184
 
@@ -23,6 +23,9 @@ Gem::Specification.new do |spec|
23
23
  spec.add_dependency 'json_spec'
24
24
  spec.add_dependency 'capybara'
25
25
  spec.add_dependency 'webmock'
26
+ spec.add_dependency 'rspec-rails', '~> 3.0'
27
+ spec.add_dependency 'cucumber-rails'
28
+ spec.add_dependency 'selenium-webdriver'
26
29
  spec.add_development_dependency 'bundler', '~> 1.7'
27
30
  spec.add_development_dependency 'rake', '~> 10.0'
28
31
  end
@@ -1,7 +1,7 @@
1
1
  module Cucoo
2
2
  class Config
3
3
  class << self
4
- attr_accessor :app_port, :stub_port
4
+ attr_accessor :app_port, :stub_host, :stub_port
5
5
  end
6
6
  end
7
7
  end
@@ -1,9 +1,12 @@
1
+ require 'capybara'
2
+ require 'json_spec/cucumber'
3
+ require 'webmock/cucumber'
4
+ require 'cucumber/rails'
5
+ require 'rspec/mocks'
1
6
  require 'cucoo/stub_helper'
2
7
  require 'cucoo/step_definitions/api_steps'
3
8
  require 'cucoo/step_definitions/stub_steps'
4
9
  require 'cucoo/step_definitions/json_spec_steps'
5
- require 'capybara'
6
- require 'webmock/cucumber'
7
10
 
8
11
  Before do
9
12
  clear_stubs!
@@ -1,4 +1,4 @@
1
- When(/^I make a POST to "([^"]*)" with the following:$/) do |url, params|
1
+ When(/^I make a POST to "([^"]*)" with:$/) do |url, params|
2
2
  Cucoo::Driver.post url, params.hashes.first
3
3
  end
4
4
 
@@ -15,11 +15,11 @@ When(/^I make a GET to "([^"]*)"$/) do |url|
15
15
  Cucoo::Driver.get url
16
16
  end
17
17
 
18
- When(/^I send a DELETE to "([^"]*)"$/) do |url|
18
+ When(/^I make a DELETE to "([^"]*)"$/) do |url|
19
19
  Cucoo::Driver.delete url
20
20
  end
21
21
 
22
- When(/^I send a DELETE to "([^"]*)" with params:$/) do |url, params|
22
+ When(/^I make a DELETE to "([^"]*)" with:$/) do |url, params|
23
23
  Cucoo::Driver.delete url, params.hashes.first
24
24
  end
25
25
 
@@ -31,7 +31,7 @@ And(/^the response body must be "([^"]*)"$/) do |body|
31
31
  expect(Cucoo::Driver.response.to_s).to eq(body)
32
32
  end
33
33
 
34
- When(/^I send a PUT request to "([^"]*)" with the following:$/) do |url, params|
34
+ When(/^I send a PUT request to "([^"]*)" with:$/) do |url, params|
35
35
  Cucoo::Driver.put url, params.hashes.first
36
36
  end
37
37
 
@@ -1,6 +1,6 @@
1
1
  module StubHelper
2
2
  def expand_url(url)
3
- ['http://localhost:', Cucoo::Config.stub_port, url].join
3
+ ['http://', Cucoo::Config.stub_host, ':', Cucoo::Config.stub_port, url].join
4
4
  end
5
5
 
6
6
  def assert_all_stubs!
@@ -1,3 +1,3 @@
1
1
  module Cucoo
2
- VERSION = "0.0.1"
2
+ VERSION = '0.0.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cucoo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - RC
@@ -80,6 +80,48 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec-rails
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: cucumber-rails
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: selenium-webdriver
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
83
125
  - !ruby/object:Gem::Dependency
84
126
  name: bundler
85
127
  requirement: !ruby/object:Gem::Requirement
@@ -116,6 +158,8 @@ extensions: []
116
158
  extra_rdoc_files: []
117
159
  files:
118
160
  - ".gitignore"
161
+ - ".ruby-gemset"
162
+ - ".ruby-version"
119
163
  - Gemfile
120
164
  - LICENSE.txt
121
165
  - README.md