jsonapi_rspec 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +71 -0
- data/LICENSE.txt +21 -0
- data/README.md +107 -0
- data/Rakefile +13 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/jsonapi_rspec.gemspec +33 -0
- data/lib/jsonapi_rspec/be_json_api_response_for.rb +190 -0
- data/lib/jsonapi_rspec/configuration.rb +9 -0
- data/lib/jsonapi_rspec/string.rb +22 -0
- data/lib/jsonapi_rspec/version.rb +3 -0
- data/lib/jsonapi_rspec.rb +21 -0
- metadata +172 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8409f6d1d66e1c807057ae55f76b8fcbd2d22383
|
4
|
+
data.tar.gz: 94cf34c0cb18fdbd4b8c7ec1a3d90beb751da926
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 717a0dea8650593f11055f37b483bb53f4d57c516024cddce6ff344517d145b9aa78437479db856d46772a55c3cb6b30c5b88eba7b7dee6c43b0fbad485959a9
|
7
|
+
data.tar.gz: fef72061c50a0bb8f9f622e871015627f625125265621e14bb037d41070774c41ab49050e57ab06c85b4f8afb0ff1fc2596dc37d6838d0979a88b2f9bc5b94fb
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
jsonapi_rspec (0.1.0)
|
5
|
+
activesupport (>= 4.2.8)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activesupport (5.1.4)
|
11
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
12
|
+
i18n (~> 0.7)
|
13
|
+
minitest (~> 5.1)
|
14
|
+
tzinfo (~> 1.1)
|
15
|
+
coderay (1.1.2)
|
16
|
+
concurrent-ruby (1.0.5)
|
17
|
+
diff-lcs (1.3)
|
18
|
+
docile (1.1.5)
|
19
|
+
i18n (0.8.6)
|
20
|
+
json (2.1.0)
|
21
|
+
method_source (0.8.2)
|
22
|
+
midwire_common (0.3.0)
|
23
|
+
thor (~> 0.19)
|
24
|
+
minitest (5.10.3)
|
25
|
+
pry (0.10.4)
|
26
|
+
coderay (~> 1.1.0)
|
27
|
+
method_source (~> 0.8.1)
|
28
|
+
slop (~> 3.4)
|
29
|
+
pry-nav (0.2.4)
|
30
|
+
pry (>= 0.9.10, < 0.11.0)
|
31
|
+
rack (2.0.3)
|
32
|
+
rake (10.5.0)
|
33
|
+
rspec (3.6.0)
|
34
|
+
rspec-core (~> 3.6.0)
|
35
|
+
rspec-expectations (~> 3.6.0)
|
36
|
+
rspec-mocks (~> 3.6.0)
|
37
|
+
rspec-core (3.6.0)
|
38
|
+
rspec-support (~> 3.6.0)
|
39
|
+
rspec-expectations (3.6.0)
|
40
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
41
|
+
rspec-support (~> 3.6.0)
|
42
|
+
rspec-mocks (3.6.0)
|
43
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
44
|
+
rspec-support (~> 3.6.0)
|
45
|
+
rspec-support (3.6.0)
|
46
|
+
simplecov (0.15.1)
|
47
|
+
docile (~> 1.1.0)
|
48
|
+
json (>= 1.8, < 3)
|
49
|
+
simplecov-html (~> 0.10.0)
|
50
|
+
simplecov-html (0.10.2)
|
51
|
+
slop (3.6.0)
|
52
|
+
thor (0.20.0)
|
53
|
+
thread_safe (0.3.6)
|
54
|
+
tzinfo (1.2.3)
|
55
|
+
thread_safe (~> 0.1)
|
56
|
+
|
57
|
+
PLATFORMS
|
58
|
+
ruby
|
59
|
+
|
60
|
+
DEPENDENCIES
|
61
|
+
bundler (~> 1.15.4)
|
62
|
+
jsonapi_rspec!
|
63
|
+
midwire_common (~> 0.1)
|
64
|
+
pry-nav (~> 0.2.4)
|
65
|
+
rack
|
66
|
+
rake (~> 10.0)
|
67
|
+
rspec (~> 3.0)
|
68
|
+
simplecov
|
69
|
+
|
70
|
+
BUNDLED WITH
|
71
|
+
1.16.0.pre.3
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Chris Blackburn
|
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,107 @@
|
|
1
|
+
# JsonapiRspec
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/midwire/jsonapi_rspec.svg?branch=master)](https://travis-ci.org/midwire/jsonapi_rspec)
|
4
|
+
|
5
|
+
Match json:api formatted Rack::Response (or Rails controller response) to an instantiated object or ActiveRecord/ActiveModel object.
|
6
|
+
|
7
|
+
This project started because I wanted to be able to easily compare a json:api response to a model in my Rails API controllers, across several projects. Finding myself copying the code between projects, I decided to stick it all in a gem.
|
8
|
+
|
9
|
+
As such, it may not strictly suit your needs, but if you let me know I'll do my best to accommodate.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
group :test do
|
17
|
+
gem 'jsonapi_rspec'
|
18
|
+
end
|
19
|
+
```
|
20
|
+
|
21
|
+
And then execute:
|
22
|
+
|
23
|
+
$ bundle
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
In your controller specs:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
my_model = MyModel.create(...)
|
31
|
+
get :show, params: { id: my_model.id }
|
32
|
+
expect(response).to be_jsonapi_response_for(my_model)
|
33
|
+
```
|
34
|
+
|
35
|
+
It currently tests for required json:api sections and matching attributes for the passed model instance.
|
36
|
+
```json
|
37
|
+
{
|
38
|
+
"jsonapi": "version 1.1", // does not check
|
39
|
+
"data":{ // checks if exists and is a hash
|
40
|
+
"id":"123", // checks if this matches the object.id
|
41
|
+
"type":"tags", // checks if exists and is the matching type for object
|
42
|
+
"attributes":{ // checks each attrib. against object attributes
|
43
|
+
"string_attribute":"Category",
|
44
|
+
"datetime_attribute":"2017-10-13T19:33:54+00:00",
|
45
|
+
"time_attribute":"2017-10-14 17:12:45 -0500",
|
46
|
+
"true_attribute":true,
|
47
|
+
"false_attribute":false,
|
48
|
+
"nil_attribute":null,
|
49
|
+
"fixnum_attribute":11,
|
50
|
+
"float_attribute":11.11,
|
51
|
+
"bignum_attribute":9999999999999999999999999999999,
|
52
|
+
"links":{ // does not check
|
53
|
+
"self":"http://test.host/api/v1/tag_types.123"
|
54
|
+
}
|
55
|
+
}
|
56
|
+
},
|
57
|
+
"included": [{ // does not check
|
58
|
+
"type": "users",
|
59
|
+
"id": 9,
|
60
|
+
"attributes": {
|
61
|
+
"first-name": "Dan",
|
62
|
+
"last-name": "Gebhardt",
|
63
|
+
"twitter": "dgeb"
|
64
|
+
},
|
65
|
+
"links": {
|
66
|
+
"self": "http://example.com/users/9"
|
67
|
+
}
|
68
|
+
}],
|
69
|
+
"meta":{ // does not check for existance by default
|
70
|
+
"copyright":"Copyright 2017 Chris Blackburn", // required if meta tag exists
|
71
|
+
"version":"v1" // required if meta tag exists
|
72
|
+
}
|
73
|
+
}
|
74
|
+
```
|
75
|
+
|
76
|
+
### Possible Failure Messages
|
77
|
+
|
78
|
+
* 'Response is an error'
|
79
|
+
* "Unexpected key in response: '#{key}'"
|
80
|
+
* 'Expected response to match an object instance but it is an empty string'
|
81
|
+
* "The 'data' section is missing or invalid"
|
82
|
+
* "Expected data:type '#{data_type}' to match: '#{object_type}'"
|
83
|
+
* "The 'meta' section is missing or invalid"
|
84
|
+
* "The 'meta:version' is missing"
|
85
|
+
* "The 'meta:copyright' is missing or invalid - regex: '/^Copyright.+\\d{4}/'"
|
86
|
+
* "Fix 'match_attribute?' method to handle: '#{obj_val_class_name}'" - please file an issue if you get this one.
|
87
|
+
* "Attribute: :#{attr_name} with a value of '#{json_val}'(#{json_val.class.name}) does not match object: '#{obj_val}'(#{obj_val.class.name})
|
88
|
+
* "Expected '#{value}' to match object id: '#{object_id}'"
|
89
|
+
|
90
|
+
See the specs for details.
|
91
|
+
|
92
|
+
### Configuration
|
93
|
+
|
94
|
+
This is the only configuration option at the moment:
|
95
|
+
|
96
|
+
JsonapiRspec.configure do |config|
|
97
|
+
config.meta_required = false # default
|
98
|
+
end
|
99
|
+
|
100
|
+
|
101
|
+
## Contributing
|
102
|
+
|
103
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/midwire/jsonapi_rspec.
|
104
|
+
|
105
|
+
## License
|
106
|
+
|
107
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
|
3
|
+
require 'rspec/core/rake_task'
|
4
|
+
RSpec::Core::RakeTask.new(:spec)
|
5
|
+
task default: :spec
|
6
|
+
|
7
|
+
begin
|
8
|
+
require 'midwire_common/rake_tasks'
|
9
|
+
rescue StandardError => e
|
10
|
+
puts(">>> Can't load midwire_common/rake_tasks.")
|
11
|
+
puts(">>> Did you 'bundle exec'?: #{e.message}")
|
12
|
+
exit
|
13
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "jsonapi_rspec"
|
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(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'jsonapi_rspec/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'jsonapi_rspec'
|
8
|
+
spec.version = JsonapiRspec::VERSION
|
9
|
+
spec.authors = ['Chris Blackburn']
|
10
|
+
spec.email = ['chris@midwiretech.com']
|
11
|
+
|
12
|
+
spec.summary = 'Provides RSpec matchers for json:api related specs'
|
13
|
+
spec.description = spec.summary
|
14
|
+
spec.homepage = 'https://github.com/midwire/jsonapi_rspec'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = 'exe'
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ['lib']
|
23
|
+
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.15.4'
|
25
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
26
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
27
|
+
spec.add_development_dependency 'pry-nav', '~> 0.2.4'
|
28
|
+
spec.add_development_dependency 'rack'
|
29
|
+
spec.add_development_dependency 'simplecov'
|
30
|
+
spec.add_development_dependency 'midwire_common', '~> 0.1'
|
31
|
+
|
32
|
+
spec.add_dependency 'activesupport', '>= 4.2.8'
|
33
|
+
end
|
@@ -0,0 +1,190 @@
|
|
1
|
+
require_relative 'string'
|
2
|
+
require 'active_support/all'
|
3
|
+
|
4
|
+
# Class BeJsonApiResponseFor provides custom RSpec matching for json:api
|
5
|
+
# responses for a given object instance. It checks attributes and elements
|
6
|
+
# iteratively and fails on the first mismatch that it finds.
|
7
|
+
#
|
8
|
+
# It expects a Rack::Response (or similar) object to be passed as the left-side
|
9
|
+
# of the comparison and a regular Object-derived instance as the right-side.
|
10
|
+
#
|
11
|
+
# Usage:
|
12
|
+
# expect(response).to BeJsonApiResponseFor.new(object_instance)
|
13
|
+
#
|
14
|
+
# @author Chris Blackburn <87a1779b@opayq.com>
|
15
|
+
#
|
16
|
+
class BeJsonApiResponseFor
|
17
|
+
def initialize(object_instance)
|
18
|
+
@object_instance = object_instance
|
19
|
+
end
|
20
|
+
|
21
|
+
def matches?(response)
|
22
|
+
return false unless valid_response?(response)
|
23
|
+
|
24
|
+
@parsed_response = JSON.parse(response.body)
|
25
|
+
|
26
|
+
return false if response_is_error?
|
27
|
+
return false unless valid_data_section?
|
28
|
+
if JsonapiRspec.configuration.meta_required
|
29
|
+
return false unless valid_meta_section?
|
30
|
+
end
|
31
|
+
|
32
|
+
@parsed_response.each do |key, value|
|
33
|
+
case key.to_sym
|
34
|
+
when :data
|
35
|
+
return false unless match_object?(value)
|
36
|
+
when :meta
|
37
|
+
return false unless valid_meta_section?
|
38
|
+
when :jsonapi
|
39
|
+
next # this can legally be anything
|
40
|
+
when :included
|
41
|
+
next # TODO: handle included objects
|
42
|
+
else
|
43
|
+
return set_failure_message("Unexpected key in response: '#{key}'")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
true
|
48
|
+
end
|
49
|
+
|
50
|
+
def failure_message
|
51
|
+
@failure_message ||= "Expected object [#{@object_instance}] to match"
|
52
|
+
"#{@failure_message} - parsed response: #{pretty_response}"
|
53
|
+
end
|
54
|
+
|
55
|
+
def failure_message_when_negated
|
56
|
+
@failure_message = "handle method 'failure_message_when_negated' in custom_matchers.rb"
|
57
|
+
"#{@failure_message}: #{pretty_response}"
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def pretty_response
|
63
|
+
JSON.pretty_generate(@parsed_response)
|
64
|
+
rescue JSON::GeneratorError
|
65
|
+
@parsed_response.to_s
|
66
|
+
end
|
67
|
+
|
68
|
+
# Set the failure message
|
69
|
+
#
|
70
|
+
# @param [String] msg Failure message
|
71
|
+
#
|
72
|
+
# @return [Boolean] always returns false
|
73
|
+
#
|
74
|
+
def set_failure_message(msg)
|
75
|
+
@failure_message = msg
|
76
|
+
false
|
77
|
+
end
|
78
|
+
|
79
|
+
def valid_response?(response)
|
80
|
+
if response.body == ''
|
81
|
+
return set_failure_message('Expected response to match an object instance but it is an empty string')
|
82
|
+
end
|
83
|
+
true
|
84
|
+
end
|
85
|
+
|
86
|
+
def valid_data_section?
|
87
|
+
unless @parsed_response.dig('data').is_a?(Hash)
|
88
|
+
return set_failure_message("The 'data' section is missing or invalid")
|
89
|
+
end
|
90
|
+
true
|
91
|
+
end
|
92
|
+
|
93
|
+
def valid_type?(data_type)
|
94
|
+
object_type = @object_instance.class.name.underscore.dasherize.pluralize
|
95
|
+
unless data_type == object_type
|
96
|
+
return set_failure_message("Expected data:type '#{data_type}' to match: '#{object_type}'")
|
97
|
+
end
|
98
|
+
true
|
99
|
+
end
|
100
|
+
|
101
|
+
def valid_meta_section?
|
102
|
+
meta = @parsed_response.dig('meta')
|
103
|
+
return set_failure_message("The 'meta' section is missing or invalid") unless meta.is_a?(Hash)
|
104
|
+
return set_failure_message("The 'meta:version' is missing") if meta.dig('version').nil?
|
105
|
+
unless meta.dig('copyright') =~ /^Copyright.+\d{4}/
|
106
|
+
return set_failure_message("The 'meta:copyright' is missing or invalid - regex: '/^Copyright.+\\d{4}/'")
|
107
|
+
end
|
108
|
+
true
|
109
|
+
end
|
110
|
+
|
111
|
+
def response_is_error?
|
112
|
+
is_error = !@parsed_response.dig('errors').nil?
|
113
|
+
set_failure_message('Response is an error') if is_error
|
114
|
+
is_error
|
115
|
+
end
|
116
|
+
|
117
|
+
def match_attribute?(attr_name, json_val)
|
118
|
+
obj_val = @object_instance.send(attr_name.to_sym)
|
119
|
+
obj_val_class_name = obj_val.class.name
|
120
|
+
|
121
|
+
case obj_val_class_name
|
122
|
+
when 'Float'
|
123
|
+
matched = obj_val == json_val.to_f
|
124
|
+
when 'DateTime'
|
125
|
+
matched = obj_val.to_i == DateTime.parse(json_val).to_i
|
126
|
+
when 'Time'
|
127
|
+
matched = obj_val.to_i == Time.parse(json_val).to_i
|
128
|
+
when 'String', 'NilClass', 'TrueClass', 'FalseClass', 'Fixnum', 'Integer', 'Bignum'
|
129
|
+
matched = obj_val == json_val
|
130
|
+
else
|
131
|
+
return set_failure_message("Fix 'match_attribute?' method to handle: '#{obj_val_class_name}'")
|
132
|
+
end
|
133
|
+
|
134
|
+
unless matched
|
135
|
+
return set_failure_message(
|
136
|
+
<<-STRING.here_with_pipe!(' ')
|
137
|
+
|Attribute: :#{attr_name}
|
138
|
+
|with a value of '#{json_val}'(#{json_val.class.name})
|
139
|
+
|does not match object: '#{obj_val}'(#{obj_val.class.name})
|
140
|
+
STRING
|
141
|
+
)
|
142
|
+
end
|
143
|
+
true
|
144
|
+
end
|
145
|
+
|
146
|
+
def match_object?(values)
|
147
|
+
values.each do |key, value|
|
148
|
+
case key.to_sym
|
149
|
+
when :id
|
150
|
+
object_id = @object_instance.send(key)
|
151
|
+
unless object_id == value.to_i
|
152
|
+
return set_failure_message("Expected '#{value}' to match object id: '#{object_id}'")
|
153
|
+
end
|
154
|
+
when :type
|
155
|
+
return false unless valid_type?(value)
|
156
|
+
when :attributes
|
157
|
+
value.each do |attr, val|
|
158
|
+
attribute = attr.underscore
|
159
|
+
next if attr.to_sym == :links # skip link validation
|
160
|
+
# return false unless @object_instance.send(attribute) == val
|
161
|
+
return false unless match_attribute?(attribute, val)
|
162
|
+
end
|
163
|
+
when :relationships
|
164
|
+
next # skip relationships validation
|
165
|
+
else
|
166
|
+
fail "Invalid attribute: '#{key}'"
|
167
|
+
end
|
168
|
+
end
|
169
|
+
true
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
# Usage:
|
174
|
+
# expect(response).to be_jsonapi_response_for(object_instance)
|
175
|
+
#
|
176
|
+
RSpec::Matchers.define :be_jsonapi_response_for do |object|
|
177
|
+
match do |actual_response|
|
178
|
+
@instance = BeJsonApiResponseFor.new(object)
|
179
|
+
|
180
|
+
def failure_message
|
181
|
+
@instance.failure_message
|
182
|
+
end
|
183
|
+
|
184
|
+
def failure_message_when_negated
|
185
|
+
@instance.failure_message
|
186
|
+
end
|
187
|
+
|
188
|
+
@instance.matches?(actual_response)
|
189
|
+
end
|
190
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class String
|
2
|
+
# Helper for the heredoc functionality. Allows pipe '|' delimeted heredocs
|
3
|
+
# with a parameterized delimeter.
|
4
|
+
#
|
5
|
+
# Example:
|
6
|
+
# html = <<-stop.here_with_pipe(delimeter="\n")
|
7
|
+
# |<!-- Begin: comment -->
|
8
|
+
# |<script type="text/javascript">
|
9
|
+
# stop
|
10
|
+
# html == '<!-- Begin: comment -->\n<script type="text/javascript">'
|
11
|
+
#
|
12
|
+
# @param [String] delimeter Joins the lines of strings with this delimeter.
|
13
|
+
#
|
14
|
+
# @return [String] Returns the concatenated string.
|
15
|
+
#
|
16
|
+
def here_with_pipe!(delimeter = ' ')
|
17
|
+
lines = split("\n")
|
18
|
+
lines.map! { |c| c.sub!(/\s*\|/, '') }
|
19
|
+
new_string = lines.join(delimeter)
|
20
|
+
replace(new_string)
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'jsonapi_rspec/version'
|
2
|
+
require 'jsonapi_rspec/be_json_api_response_for'
|
3
|
+
|
4
|
+
module JsonapiRspec
|
5
|
+
class << self
|
6
|
+
attr_accessor :configuration
|
7
|
+
|
8
|
+
def root
|
9
|
+
Pathname.new(File.dirname(__FILE__)).parent
|
10
|
+
end
|
11
|
+
|
12
|
+
def configure
|
13
|
+
self.configuration ||= Configuration.new
|
14
|
+
yield(configuration)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
autoload :Configuration, 'jsonapi_rspec/configuration'
|
19
|
+
end
|
20
|
+
|
21
|
+
JsonapiRspec.configure {} # initialize the configuration
|
metadata
ADDED
@@ -0,0 +1,172 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jsonapi_rspec
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chris Blackburn
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-10-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.15.4
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.15.4
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry-nav
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.2.4
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.2.4
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rack
|
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: simplecov
|
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
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: midwire_common
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.1'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.1'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: activesupport
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 4.2.8
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 4.2.8
|
125
|
+
description: Provides RSpec matchers for json:api related specs
|
126
|
+
email:
|
127
|
+
- chris@midwiretech.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".gitignore"
|
133
|
+
- ".rspec"
|
134
|
+
- ".travis.yml"
|
135
|
+
- Gemfile
|
136
|
+
- Gemfile.lock
|
137
|
+
- LICENSE.txt
|
138
|
+
- README.md
|
139
|
+
- Rakefile
|
140
|
+
- bin/console
|
141
|
+
- bin/setup
|
142
|
+
- jsonapi_rspec.gemspec
|
143
|
+
- lib/jsonapi_rspec.rb
|
144
|
+
- lib/jsonapi_rspec/be_json_api_response_for.rb
|
145
|
+
- lib/jsonapi_rspec/configuration.rb
|
146
|
+
- lib/jsonapi_rspec/string.rb
|
147
|
+
- lib/jsonapi_rspec/version.rb
|
148
|
+
homepage: https://github.com/midwire/jsonapi_rspec
|
149
|
+
licenses:
|
150
|
+
- MIT
|
151
|
+
metadata: {}
|
152
|
+
post_install_message:
|
153
|
+
rdoc_options: []
|
154
|
+
require_paths:
|
155
|
+
- lib
|
156
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
157
|
+
requirements:
|
158
|
+
- - ">="
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: '0'
|
161
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
162
|
+
requirements:
|
163
|
+
- - ">="
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0'
|
166
|
+
requirements: []
|
167
|
+
rubyforge_project:
|
168
|
+
rubygems_version: 2.5.1
|
169
|
+
signing_key:
|
170
|
+
specification_version: 4
|
171
|
+
summary: Provides RSpec matchers for json:api related specs
|
172
|
+
test_files: []
|