api_rspecta 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 +14 -0
- data/.rvmrc +53 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +7 -0
- data/api_rspecta.gemspec +26 -0
- data/lib/api_rspecta/init.rb +9 -0
- data/lib/api_rspecta/version.rb +3 -0
- data/lib/api_rspecta.rb +112 -0
- data/spec/lib/api_rspecta_spec.rb +10 -0
- data/spec/spec_helper.rb +1 -0
- metadata +103 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 2d6235063aebb35bf9215a8217314ef3ec12dbbd
|
|
4
|
+
data.tar.gz: 4d81e49b341c7ccba181314998dc07cd9f6c45c4
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 151a86305355d766f01200c846382bcb12f90279c42b1381b817e9354c6b317251884c69532e65c76c7f92f0b23aa2c7ec2172a3e9423a605fe00b861d27a1ea
|
|
7
|
+
data.tar.gz: cae2c853acb561b73d35f70c4d7841b5f7fb071a973ce50e39782e5f498b0e06150f48dbe38352b3e6ac23d88f229bd77c875c331709fc39129546672df7b5d5
|
data/.gitignore
ADDED
data/.rvmrc
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
|
4
|
+
# development environment upon cd'ing into the directory
|
|
5
|
+
|
|
6
|
+
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
|
|
7
|
+
# Only full ruby name is supported here, for short names use:
|
|
8
|
+
# echo "rvm use 2.0.0" > .rvmrc
|
|
9
|
+
environment_id="ruby-2.0.0-p576@api_rspecta"
|
|
10
|
+
|
|
11
|
+
# Uncomment the following lines if you want to verify rvm version per project
|
|
12
|
+
# rvmrc_rvm_version="1.25.33 (stable)" # 1.10.1 seems like a safe start
|
|
13
|
+
# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | __rvm_awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
|
|
14
|
+
# echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
|
|
15
|
+
# return 1
|
|
16
|
+
# }
|
|
17
|
+
|
|
18
|
+
# First we attempt to load the desired environment directly from the environment
|
|
19
|
+
# file. This is very fast and efficient compared to running through the entire
|
|
20
|
+
# CLI and selector. If you want feedback on which environment was used then
|
|
21
|
+
# insert the word 'use' after --create as this triggers verbose mode.
|
|
22
|
+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
|
|
23
|
+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
|
24
|
+
then
|
|
25
|
+
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
|
26
|
+
for __hook in "${rvm_path:-$HOME/.rvm}/hooks/after_use"*
|
|
27
|
+
do
|
|
28
|
+
if [[ -f "${__hook}" && -x "${__hook}" && -s "${__hook}" ]]
|
|
29
|
+
then \. "${__hook}" || true
|
|
30
|
+
fi
|
|
31
|
+
done
|
|
32
|
+
unset __hook
|
|
33
|
+
if (( ${rvm_use_flag:=1} >= 2 )) # display only when forced
|
|
34
|
+
then
|
|
35
|
+
if [[ $- == *i* ]] # check for interactive shells
|
|
36
|
+
then printf "%b" "Using: $(tput setaf 2 2>/dev/null)$GEM_HOME$(tput sgr0 2>/dev/null)
|
|
37
|
+
" # show the user the ruby and gemset they are using in green
|
|
38
|
+
else printf "%b" "Using: $GEM_HOME
|
|
39
|
+
" # don't use colors in non-interactive shells
|
|
40
|
+
fi
|
|
41
|
+
fi
|
|
42
|
+
else
|
|
43
|
+
# If the environment file has not yet been created, use the RVM CLI to select.
|
|
44
|
+
rvm --create "$environment_id" || {
|
|
45
|
+
echo "Failed to create RVM environment '${environment_id}'."
|
|
46
|
+
return 1
|
|
47
|
+
}
|
|
48
|
+
fi
|
|
49
|
+
|
|
50
|
+
# If you use bundler, this might be useful to you:
|
|
51
|
+
# if [[ -s Gemfile ]] && {
|
|
52
|
+
# ! builtin command -v bundle >/dev/null ||
|
|
53
|
+
# builtin command -v bundle | GREP_OPTIONS=""
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2014 Alex Bush
|
|
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
|
+
# ApiRspecta
|
|
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 'api_rspecta'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
|
|
15
|
+
$ bundle
|
|
16
|
+
|
|
17
|
+
Or install it yourself as:
|
|
18
|
+
|
|
19
|
+
$ gem install api_rspecta
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
TODO: Write usage instructions here
|
|
24
|
+
|
|
25
|
+
## Contributing
|
|
26
|
+
|
|
27
|
+
1. Fork it ( https://github.com/[my-github-username]/api_rspecta/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/api_rspecta.gemspec
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'api_rspecta/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "api_rspecta"
|
|
8
|
+
spec.version = ApiRspecta::VERSION
|
|
9
|
+
spec.authors = ["Smart Cloud, Inc.", "Alex Bush", "Alex Petropavlovsky"]
|
|
10
|
+
spec.email = ["alex.v.bush@gmail.com", "petalvlad@gmail.com"]
|
|
11
|
+
spec.summary = %q{ api_rspecta adds convenient methods to your RSpec to test JSON APIs. }
|
|
12
|
+
spec.description = %q{ }
|
|
13
|
+
spec.homepage = "https://github.com/SmartCloud/api_rspecta"
|
|
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_development_dependency "bundler", "~> 1.7"
|
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
23
|
+
spec.add_development_dependency "rspec", "~> 3.0.0"
|
|
24
|
+
|
|
25
|
+
#spec.add_runtime_dependency 'rspec', '~> 3.0.0'
|
|
26
|
+
end
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# :enddoc:
|
|
2
|
+
|
|
3
|
+
if RSpec.respond_to?(:configure)
|
|
4
|
+
RSpec.configure do |c|
|
|
5
|
+
c.include ApiRspecta::ApiRequestsHelpers::JsonHelpers, type: :api
|
|
6
|
+
c.include ApiRspecta::ApiRequestsHelpers::ResponseHelpers, type: :api
|
|
7
|
+
c.include ApiRspecta::ApiRequestsHelpers::RequestHelpers, type: :api
|
|
8
|
+
end
|
|
9
|
+
end
|
data/lib/api_rspecta.rb
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
require "api_rspecta/version"
|
|
2
|
+
|
|
3
|
+
module ApiRspecta
|
|
4
|
+
module ApiRequestsHelpers
|
|
5
|
+
module JsonHelpers
|
|
6
|
+
def json
|
|
7
|
+
@json ||= JSON.parse last_response.body
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def refresh_json
|
|
11
|
+
@json = JSON.parse last_response.body
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def print_json
|
|
15
|
+
puts JSON.pretty_generate(json)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def json_has_key(key)
|
|
19
|
+
item_has_key(json, key)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def json_has_keys(keys)
|
|
23
|
+
item_has_keys(json, keys)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def json_has_no_key(key)
|
|
27
|
+
item_has_no_key(json, key)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def item_has_key(item, key)
|
|
31
|
+
expect(item).to have_key(key.to_s)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def item_has_no_key(item, key)
|
|
35
|
+
expect(item).not_to have_key(key.to_s)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def item_has_keys(item, keys)
|
|
39
|
+
keys.each { |key| item_has_key(item, key) }
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def item_has_only_the_keys(item, the_keys)
|
|
43
|
+
expect(item.keys.count).to eq the_keys.count
|
|
44
|
+
the_keys.each { |key| item_has_key(item, key) }
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
module ResponseHelpers
|
|
50
|
+
def should_respond_ok
|
|
51
|
+
response_status 200
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def should_respond_created
|
|
55
|
+
response_status 201
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def should_respond_with_no_content
|
|
59
|
+
response_status 204
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def should_respond_not_authenticated
|
|
63
|
+
response_status 401
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def should_respond_not_authorized
|
|
67
|
+
response_status 403
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def should_respond_not_found
|
|
71
|
+
response_status 404
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def response_status(status)
|
|
75
|
+
expect(last_response.status).to eq(status)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def should_respond_with_error_for(field)
|
|
79
|
+
response_status 422
|
|
80
|
+
expect(json["errors"]).to have_key(field.to_s)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def should_respond_with_errors_for(fields)
|
|
84
|
+
fields.each { |field| should_respond_with_error_for(field) }
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
module RequestHelpers
|
|
89
|
+
def token_auth_header
|
|
90
|
+
#{ 'HTTP_AUTHORIZATION' => ActionController::HttpAuthentication::Token.encode_credentials(ENV['auth_token']) }
|
|
91
|
+
{}
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def auth_header options
|
|
95
|
+
options[:auth_header] || {}
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def default_options
|
|
99
|
+
{ auth_header: token_auth_header }
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def guest_options
|
|
103
|
+
{}
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
if defined?(RSpec)
|
|
111
|
+
require 'api_rspecta/init'
|
|
112
|
+
end
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe 'ApiRspecta' do
|
|
4
|
+
it 'should be configured' do
|
|
5
|
+
puts ApiRspecta::ApiRequestsHelpers::JsonHelpers
|
|
6
|
+
puts ApiRspecta::ApiRequestsHelpers::ResponseHelpers
|
|
7
|
+
puts ApiRspecta::ApiRequestsHelpers::RequestHelpers
|
|
8
|
+
#RSpec.token_auth_header
|
|
9
|
+
end
|
|
10
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require 'api_rspecta'
|
metadata
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: api_rspecta
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Smart Cloud, Inc.
|
|
8
|
+
- Alex Bush
|
|
9
|
+
- Alex Petropavlovsky
|
|
10
|
+
autorequire:
|
|
11
|
+
bindir: bin
|
|
12
|
+
cert_chain: []
|
|
13
|
+
date: 2014-12-20 00:00:00.000000000 Z
|
|
14
|
+
dependencies:
|
|
15
|
+
- !ruby/object:Gem::Dependency
|
|
16
|
+
name: bundler
|
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
|
18
|
+
requirements:
|
|
19
|
+
- - ~>
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '1.7'
|
|
22
|
+
type: :development
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
requirements:
|
|
26
|
+
- - ~>
|
|
27
|
+
- !ruby/object:Gem::Version
|
|
28
|
+
version: '1.7'
|
|
29
|
+
- !ruby/object:Gem::Dependency
|
|
30
|
+
name: rake
|
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
|
32
|
+
requirements:
|
|
33
|
+
- - ~>
|
|
34
|
+
- !ruby/object:Gem::Version
|
|
35
|
+
version: '10.0'
|
|
36
|
+
type: :development
|
|
37
|
+
prerelease: false
|
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
39
|
+
requirements:
|
|
40
|
+
- - ~>
|
|
41
|
+
- !ruby/object:Gem::Version
|
|
42
|
+
version: '10.0'
|
|
43
|
+
- !ruby/object:Gem::Dependency
|
|
44
|
+
name: rspec
|
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
|
46
|
+
requirements:
|
|
47
|
+
- - ~>
|
|
48
|
+
- !ruby/object:Gem::Version
|
|
49
|
+
version: 3.0.0
|
|
50
|
+
type: :development
|
|
51
|
+
prerelease: false
|
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
53
|
+
requirements:
|
|
54
|
+
- - ~>
|
|
55
|
+
- !ruby/object:Gem::Version
|
|
56
|
+
version: 3.0.0
|
|
57
|
+
description: ' '
|
|
58
|
+
email:
|
|
59
|
+
- alex.v.bush@gmail.com
|
|
60
|
+
- petalvlad@gmail.com
|
|
61
|
+
executables: []
|
|
62
|
+
extensions: []
|
|
63
|
+
extra_rdoc_files: []
|
|
64
|
+
files:
|
|
65
|
+
- .gitignore
|
|
66
|
+
- .rvmrc
|
|
67
|
+
- Gemfile
|
|
68
|
+
- LICENSE.txt
|
|
69
|
+
- README.md
|
|
70
|
+
- Rakefile
|
|
71
|
+
- api_rspecta.gemspec
|
|
72
|
+
- lib/api_rspecta.rb
|
|
73
|
+
- lib/api_rspecta/init.rb
|
|
74
|
+
- lib/api_rspecta/version.rb
|
|
75
|
+
- spec/lib/api_rspecta_spec.rb
|
|
76
|
+
- spec/spec_helper.rb
|
|
77
|
+
homepage: https://github.com/SmartCloud/api_rspecta
|
|
78
|
+
licenses:
|
|
79
|
+
- MIT
|
|
80
|
+
metadata: {}
|
|
81
|
+
post_install_message:
|
|
82
|
+
rdoc_options: []
|
|
83
|
+
require_paths:
|
|
84
|
+
- lib
|
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - '>='
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '0'
|
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
|
+
requirements:
|
|
92
|
+
- - '>='
|
|
93
|
+
- !ruby/object:Gem::Version
|
|
94
|
+
version: '0'
|
|
95
|
+
requirements: []
|
|
96
|
+
rubyforge_project:
|
|
97
|
+
rubygems_version: 2.2.2
|
|
98
|
+
signing_key:
|
|
99
|
+
specification_version: 4
|
|
100
|
+
summary: api_rspecta adds convenient methods to your RSpec to test JSON APIs.
|
|
101
|
+
test_files:
|
|
102
|
+
- spec/lib/api_rspecta_spec.rb
|
|
103
|
+
- spec/spec_helper.rb
|