rspec-grape 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 +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +100 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/rspec-grape.rb +11 -0
- data/lib/rspec/grape/exceptions.rb +7 -0
- data/lib/rspec/grape/methods.rb +31 -0
- data/lib/rspec/grape/utils.rb +23 -0
- data/lib/rspec/grape/version.rb +5 -0
- data/rspec-grape.gemspec +28 -0
- metadata +143 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ce1c2bd204c85ed12e3882ec9dae4fef40b3564a
|
4
|
+
data.tar.gz: 6bfef25db90716def3574f63c8f5037512e76610
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b972ea8f1a983a193b72eb42cc78c320aff74c256cb55d55eafe1c585b9cc936e55e57ebf742ad5a9123d9fb23ad41b055c9f7cd9cec127d2e6285565cd0efde
|
7
|
+
data.tar.gz: 99b912315880faca5b9fdf3585d3911539c415a1d7b098e57cb393c2ed9dd15f3caeb4da1108647f3e97fac3dd6351726b5f2eec2dfcfe9bdb93c537949d82d5
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Timothy Kovalev
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
# Rspec::Grape
|
2
|
+
|
3
|
+
This gem is a set of spec helpers, that will help to test [Grape](https://github.com/ruby-grape/grape) APIs easily. The usual approach to test apis, as [official documentation shows](https://github.com/ruby-grape/grape#rspec), is:
|
4
|
+
|
5
|
+
```
|
6
|
+
context 'GET /api/v1/test' do
|
7
|
+
it 'returns 200' do
|
8
|
+
get '/api/v1/test'
|
9
|
+
expect(last_response.status).to eq(200)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
```
|
13
|
+
|
14
|
+
Here you describe context as `GET /api/v1/test`, then you have to repeat url and method in example: `get '/api/v1/test'`. But what if you don't have to?
|
15
|
+
|
16
|
+
|
17
|
+
## Installation
|
18
|
+
|
19
|
+
Add this line to your application's Gemfile:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
gem 'rspec-grape'
|
23
|
+
```
|
24
|
+
|
25
|
+
And then execute:
|
26
|
+
|
27
|
+
$ bundle
|
28
|
+
|
29
|
+
Or install it yourself as:
|
30
|
+
|
31
|
+
$ gem install rspec-grape
|
32
|
+
|
33
|
+
## Usage
|
34
|
+
|
35
|
+
### Conventions
|
36
|
+
|
37
|
+
Gem's behaviour is based on some conventions:
|
38
|
+
* `described_class` should point to your API class
|
39
|
+
* examples should be grouped by endpoints
|
40
|
+
* group of endpoint specs shoud be described as 'HTTP_METHOD /api/path'
|
41
|
+
|
42
|
+
### Basic usage
|
43
|
+
|
44
|
+
This gem provides the `call_api` helper method. It automatically reads endpoint url and method from context description, allowing you to avoid duplication and write a shorter spec:
|
45
|
+
|
46
|
+
```
|
47
|
+
context 'GET /api/v1/test' do
|
48
|
+
it 'returns 200' do
|
49
|
+
expect(call_api.status).to eq(200)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
```
|
53
|
+
|
54
|
+
### Passing request params
|
55
|
+
|
56
|
+
Params can be either passed to `call_api` method:
|
57
|
+
|
58
|
+
```
|
59
|
+
call_api({foo: :bar})
|
60
|
+
```
|
61
|
+
|
62
|
+
or set via `let`:
|
63
|
+
|
64
|
+
```
|
65
|
+
let(:api_params) { { foo: :bar } }
|
66
|
+
```
|
67
|
+
|
68
|
+
Note, that params, explicitly passed to `call_api`, have precendence over thoose set in `api_params`.
|
69
|
+
|
70
|
+
|
71
|
+
### Additional spec helpers
|
72
|
+
|
73
|
+
It is also possible to use two methods in your specs: `api_url` and `api_method`. The former returns url from spec description, while the latter returns http method.
|
74
|
+
|
75
|
+
You can always use them, as `call_api` methods does:
|
76
|
+
|
77
|
+
```
|
78
|
+
send(api_method, api_url)
|
79
|
+
```
|
80
|
+
|
81
|
+
## TODO
|
82
|
+
|
83
|
+
* Support urls with params: `/api/test/:id`
|
84
|
+
* Provide `api_helpers` for easier helpers stubbing [see](https://github.com/ruby-grape/grape#stubbing-helpers)
|
85
|
+
|
86
|
+
## Development
|
87
|
+
|
88
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
89
|
+
|
90
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
91
|
+
|
92
|
+
## Contributing
|
93
|
+
|
94
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ktimothy/rspec-grape.
|
95
|
+
|
96
|
+
|
97
|
+
## License
|
98
|
+
|
99
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
100
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rspec/grape"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/rspec-grape.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'rspec/core'
|
2
|
+
require 'rack/test'
|
3
|
+
|
4
|
+
require 'rspec/grape/exceptions'
|
5
|
+
require 'rspec/grape/utils'
|
6
|
+
require 'rspec/grape/methods'
|
7
|
+
|
8
|
+
RSpec.configure do |config|
|
9
|
+
config.include RSpec::Grape::Methods, type: :api
|
10
|
+
config.include RSpec::Grape::Methods, :api
|
11
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Grape
|
3
|
+
module Methods
|
4
|
+
include Rack::Test::Methods
|
5
|
+
|
6
|
+
def app
|
7
|
+
self.described_class
|
8
|
+
end
|
9
|
+
|
10
|
+
def api_method
|
11
|
+
api_endpoint_description.split(' ').first.downcase.to_sym
|
12
|
+
end
|
13
|
+
|
14
|
+
def api_url
|
15
|
+
api_endpoint_description.split(' ').last
|
16
|
+
end
|
17
|
+
|
18
|
+
def call_api(params = nil)
|
19
|
+
params ||= self.respond_to?(:api_params) ? api_params : {}
|
20
|
+
|
21
|
+
self.send(api_method, api_url, params)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def api_endpoint_description
|
27
|
+
@api_endpoint_description ||= RSpec::Grape::Utils.find_endpoint_description(self.class)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Grape
|
3
|
+
module Utils
|
4
|
+
HTTP_METHODS = %w[GET HEAD PUT POST DELETE OPTIONS PATCH LINK UNLINK]
|
5
|
+
REGEXP = /(#{HTTP_METHODS.join('|')}) \/.*/
|
6
|
+
|
7
|
+
def self.is_description_valid?(description)
|
8
|
+
!!(description =~ REGEXP)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.find_endpoint_description(klass)
|
12
|
+
ancestors = klass.ancestors.select { |a| a < RSpec::Core::ExampleGroup }
|
13
|
+
ancestors = ancestors.select do |a|
|
14
|
+
is_description_valid?(a.description)
|
15
|
+
end
|
16
|
+
|
17
|
+
raise RSpec::Grape::NoEndpointDescription unless ancestors.any?
|
18
|
+
|
19
|
+
ancestors.last.description
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/rspec-grape.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 'rspec/grape/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rspec-grape"
|
8
|
+
spec.version = Rspec::Grape::VERSION
|
9
|
+
spec.authors = ["Timothy Kovalev"]
|
10
|
+
spec.email = ["timothy.kovalev@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{A set of helpers, which make grape api specs shorter.}
|
13
|
+
spec.homepage = "https://github.com/ktimothy/rspec-grape"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency "rack-test", "~> 0.6"
|
22
|
+
spec.add_runtime_dependency "rspec-core", "~> 3.0"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec"
|
27
|
+
spec.add_development_dependency "grape"
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec-grape
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Timothy Kovalev
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-07-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rack-test
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.6'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec-core
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.10'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.10'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
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: grape
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
- timothy.kovalev@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rspec"
|
106
|
+
- ".travis.yml"
|
107
|
+
- Gemfile
|
108
|
+
- LICENSE.txt
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- bin/console
|
112
|
+
- bin/setup
|
113
|
+
- lib/rspec-grape.rb
|
114
|
+
- lib/rspec/grape/exceptions.rb
|
115
|
+
- lib/rspec/grape/methods.rb
|
116
|
+
- lib/rspec/grape/utils.rb
|
117
|
+
- lib/rspec/grape/version.rb
|
118
|
+
- rspec-grape.gemspec
|
119
|
+
homepage: https://github.com/ktimothy/rspec-grape
|
120
|
+
licenses:
|
121
|
+
- MIT
|
122
|
+
metadata: {}
|
123
|
+
post_install_message:
|
124
|
+
rdoc_options: []
|
125
|
+
require_paths:
|
126
|
+
- lib
|
127
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
requirements: []
|
138
|
+
rubyforge_project:
|
139
|
+
rubygems_version: 2.4.5
|
140
|
+
signing_key:
|
141
|
+
specification_version: 4
|
142
|
+
summary: A set of helpers, which make grape api specs shorter.
|
143
|
+
test_files: []
|