cucoo 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +2 -0
- data/cucoo.gemspec +28 -0
- data/lib/cucoo.rb +14 -0
- data/lib/cucoo/api_driver.rb +37 -0
- data/lib/cucoo/config.rb +7 -0
- data/lib/cucoo/rails.rb +27 -0
- data/lib/cucoo/step_definitions/api_steps.rb +37 -0
- data/lib/cucoo/step_definitions/json_spec_steps.rb +3 -0
- data/lib/cucoo/step_definitions/stub_steps.rb +45 -0
- data/lib/cucoo/stub_helper.rb +30 -0
- data/lib/cucoo/version.rb +3 -0
- metadata +157 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6c785eb8e5a8993bd6aae1db703047d0cbabf617
|
4
|
+
data.tar.gz: 634f9f70b65aeb031994644b2f129f3b3afa9133
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 660f32172f08fba6ca9e3fd9452b667916b90be3112753b4727bacd24ea3f1c59fe737429de856d641feb25f2165c1fb4959fc7defc13dadd22df10c83043dcc
|
7
|
+
data.tar.gz: 16fa9e30ffc24b4638f437f93a0c592ce5669d457420c5c74ce906ecb333d8432ecc765834cbdf04ccf0d1ae2e510962c78e998c65be8f0f74eeacd17d58d7b3
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 RC
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Cucoo
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'cucoo'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install cucoo
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/[my-github-username]/cucoo/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/cucoo.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'cucoo/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'cucoo'
|
8
|
+
spec.version = Cucoo::VERSION
|
9
|
+
spec.authors = ['RC']
|
10
|
+
spec.email = ['rc.chandru@gmail.com']
|
11
|
+
spec.summary = %q{Cucumber steps and assertions for testing your APIs}
|
12
|
+
spec.description = %q{Cucumber steps and assertions for testing your APIs}
|
13
|
+
spec.homepage = 'https://github.com/rcdexta/cucoo'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_dependency 'httparty'
|
22
|
+
spec.add_dependency 'activesupport'
|
23
|
+
spec.add_dependency 'json_spec'
|
24
|
+
spec.add_dependency 'capybara'
|
25
|
+
spec.add_dependency 'webmock'
|
26
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
27
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
28
|
+
end
|
data/lib/cucoo.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'cucoo/version'
|
2
|
+
require 'cucoo/config'
|
3
|
+
require 'cucoo/api_driver'
|
4
|
+
|
5
|
+
module Cucoo
|
6
|
+
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
def self.config
|
10
|
+
yield Config
|
11
|
+
WebMock.disable_net_connect!(allow: %W(127.0.0.1:#{Cucoo::Config.app_port} localhost:#{Cucoo::Config.app_port}))
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Cucoo
|
2
|
+
class ApiDriver
|
3
|
+
|
4
|
+
include HTTParty
|
5
|
+
|
6
|
+
def post(url, body=nil)
|
7
|
+
@response = self.class.post(url, {body: body})
|
8
|
+
end
|
9
|
+
|
10
|
+
def post_with_header(url, headers = {}, body=nil)
|
11
|
+
@response = self.class.post(url, {body: body, headers: headers})
|
12
|
+
end
|
13
|
+
|
14
|
+
def put(url, body=nil)
|
15
|
+
@response = self.class.put(url, {body: body})
|
16
|
+
end
|
17
|
+
|
18
|
+
def delete(url, body=nil)
|
19
|
+
@response = self.class.delete(url, {body: body})
|
20
|
+
end
|
21
|
+
|
22
|
+
def get(url)
|
23
|
+
@response = self.class.get(url)
|
24
|
+
end
|
25
|
+
|
26
|
+
def response
|
27
|
+
@response
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class Driver
|
32
|
+
extend SingleForwardable
|
33
|
+
@api_driver = Cucoo::ApiDriver.new
|
34
|
+
def_delegators :@api_driver, :post, :put, :get, :delete, :response, :post_with_header
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
data/lib/cucoo/config.rb
ADDED
data/lib/cucoo/rails.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'cucoo/stub_helper'
|
2
|
+
require 'cucoo/step_definitions/api_steps'
|
3
|
+
require 'cucoo/step_definitions/stub_steps'
|
4
|
+
require 'cucoo/step_definitions/json_spec_steps'
|
5
|
+
require 'capybara'
|
6
|
+
require 'webmock/cucumber'
|
7
|
+
|
8
|
+
Before do
|
9
|
+
clear_stubs!
|
10
|
+
Capybara.server_port = Cucoo::Config.app_port
|
11
|
+
Cucoo::ApiDriver.base_uri "localhost:#{Capybara.current_session.server.port}"
|
12
|
+
end
|
13
|
+
|
14
|
+
World(RSpec::Mocks::ExampleMethods)
|
15
|
+
|
16
|
+
Before do
|
17
|
+
RSpec::Mocks.setup
|
18
|
+
end
|
19
|
+
|
20
|
+
After do
|
21
|
+
begin
|
22
|
+
RSpec::Mocks.verify
|
23
|
+
ensure
|
24
|
+
RSpec::Mocks.teardown
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
When(/^I make a POST to "([^"]*)" with the following:$/) do |url, params|
|
2
|
+
Cucoo::Driver.post url, params.hashes.first
|
3
|
+
end
|
4
|
+
|
5
|
+
When(/^I make a POST to "([^"]*)"$/) do |url|
|
6
|
+
Cucoo::Driver.post url
|
7
|
+
end
|
8
|
+
|
9
|
+
When(/^I make a POST to "([^"]*)" with headers "([^"]*)" and the following params:$/) do |url, headers, params|
|
10
|
+
header, value = headers.split(':')
|
11
|
+
Cucoo::Driver.post_with_header url, {header => value, 'Content-type' => 'text/plain; charset=UTF-8'}, params.hashes.first.to_json
|
12
|
+
end
|
13
|
+
|
14
|
+
When(/^I make a GET to "([^"]*)"$/) do |url|
|
15
|
+
Cucoo::Driver.get url
|
16
|
+
end
|
17
|
+
|
18
|
+
When(/^I send a DELETE to "([^"]*)"$/) do |url|
|
19
|
+
Cucoo::Driver.delete url
|
20
|
+
end
|
21
|
+
|
22
|
+
When(/^I send a DELETE to "([^"]*)" with params:$/) do |url, params|
|
23
|
+
Cucoo::Driver.delete url, params.hashes.first
|
24
|
+
end
|
25
|
+
|
26
|
+
And(/^the response error message should be "([^"]*)"$/) do |message|
|
27
|
+
expect(Cucoo::Driver.response['error']).to eq(message)
|
28
|
+
end
|
29
|
+
|
30
|
+
And(/^the response body must be "([^"]*)"$/) do |body|
|
31
|
+
expect(Cucoo::Driver.response.to_s).to eq(body)
|
32
|
+
end
|
33
|
+
|
34
|
+
When(/^I send a PUT request to "([^"]*)" with the following:$/) do |url, params|
|
35
|
+
Cucoo::Driver.put url, params.hashes.first
|
36
|
+
end
|
37
|
+
|
@@ -0,0 +1,45 @@
|
|
1
|
+
Given(/^I expect a POST to "([^"]*)" with:$/) do |url, table|
|
2
|
+
params = table.hashes.first
|
3
|
+
stub_my_request(:post, url, params)
|
4
|
+
end
|
5
|
+
|
6
|
+
Given(/^I expect a POST to "([^"]*)" with json request:$/) do |url, json|
|
7
|
+
stub_my_request(:post, url, {request: JSON.parse(json)})
|
8
|
+
end
|
9
|
+
|
10
|
+
Given(/^I expect a PUT to "([^"]*)" with json request:$/) do |url, json|
|
11
|
+
stub_my_request(:put, url, {request: JSON.parse(json)})
|
12
|
+
end
|
13
|
+
|
14
|
+
And(/^I expect a GET to "([^"]*)" with:$/) do |url, table|
|
15
|
+
params = table.hashes.first
|
16
|
+
stub_my_request(:get, url, params)
|
17
|
+
end
|
18
|
+
|
19
|
+
Given(/^I expect a GET to "([^"]*)" and return NOT FOUND$/) do |url|
|
20
|
+
stub_my_request(:get, url, {status: 404})
|
21
|
+
end
|
22
|
+
|
23
|
+
And(/^I expect a DELETE to "([^"]*)"$/) do |url|
|
24
|
+
stub_my_request(:delete, url, {})
|
25
|
+
end
|
26
|
+
|
27
|
+
Then(/^the response should be OK$/) do
|
28
|
+
expect(Cucoo::Driver.response.code).to be_between(200, 201).inclusive
|
29
|
+
assert_all_stubs!
|
30
|
+
end
|
31
|
+
|
32
|
+
Then(/^the response should be NOT FOUND$/) do
|
33
|
+
expect(Cucoo::Driver.response.code).to eq(404)
|
34
|
+
assert_all_stubs!
|
35
|
+
end
|
36
|
+
|
37
|
+
Then(/^the response should be BAD REQUEST$/) do
|
38
|
+
expect(Cucoo::Driver.response.code).to eq(400)
|
39
|
+
assert_all_stubs!
|
40
|
+
end
|
41
|
+
|
42
|
+
Then(/^the response code should be "([^"]*)"$/) do |code|
|
43
|
+
expect(Cucoo::Driver.response.code).to eq(code.to_i)
|
44
|
+
assert_all_stubs!
|
45
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module StubHelper
|
2
|
+
def expand_url(url)
|
3
|
+
['http://localhost:', Cucoo::Config.stub_port, url].join
|
4
|
+
end
|
5
|
+
|
6
|
+
def assert_all_stubs!
|
7
|
+
@stubs.each do |stub|
|
8
|
+
expect(stub).to have_been_requested
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def stub_my_request(method, url, params)
|
13
|
+
response = if params[:file]
|
14
|
+
File.new(params['file']).read
|
15
|
+
else
|
16
|
+
params[:response] || {}.to_json
|
17
|
+
end
|
18
|
+
status = params[:status] ? params[:status].to_i : 200
|
19
|
+
stub_obj = stub_request(method, expand_url(url))
|
20
|
+
@stubs << stub_obj
|
21
|
+
stub_obj.with(body: params[:request], headers: {'Content-Type' => 'application/json'}) if params[:request]
|
22
|
+
stub_obj.to_return(body: response, status: status)
|
23
|
+
end
|
24
|
+
|
25
|
+
def clear_stubs!
|
26
|
+
@stubs = []
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
World(StubHelper)
|
metadata
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cucoo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- RC
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: json_spec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: capybara
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: webmock
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: bundler
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.7'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.7'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rake
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '10.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '10.0'
|
111
|
+
description: Cucumber steps and assertions for testing your APIs
|
112
|
+
email:
|
113
|
+
- rc.chandru@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- Gemfile
|
120
|
+
- LICENSE.txt
|
121
|
+
- README.md
|
122
|
+
- Rakefile
|
123
|
+
- cucoo.gemspec
|
124
|
+
- lib/cucoo.rb
|
125
|
+
- lib/cucoo/api_driver.rb
|
126
|
+
- lib/cucoo/config.rb
|
127
|
+
- lib/cucoo/rails.rb
|
128
|
+
- lib/cucoo/step_definitions/api_steps.rb
|
129
|
+
- lib/cucoo/step_definitions/json_spec_steps.rb
|
130
|
+
- lib/cucoo/step_definitions/stub_steps.rb
|
131
|
+
- lib/cucoo/stub_helper.rb
|
132
|
+
- lib/cucoo/version.rb
|
133
|
+
homepage: https://github.com/rcdexta/cucoo
|
134
|
+
licenses:
|
135
|
+
- MIT
|
136
|
+
metadata: {}
|
137
|
+
post_install_message:
|
138
|
+
rdoc_options: []
|
139
|
+
require_paths:
|
140
|
+
- lib
|
141
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - ">="
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '0'
|
151
|
+
requirements: []
|
152
|
+
rubyforge_project:
|
153
|
+
rubygems_version: 2.4.6
|
154
|
+
signing_key:
|
155
|
+
specification_version: 4
|
156
|
+
summary: Cucumber steps and assertions for testing your APIs
|
157
|
+
test_files: []
|