response_matcher 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +1 -0
- data/.rubocop.yml +18 -0
- data/README.md +5 -8
- data/circle.yml +6 -0
- data/lib/response_matcher/parse_schema.rb +23 -14
- data/lib/response_matcher/version.rb +1 -1
- data/spec/fixtures/schemas/with_attributes.rb +6 -0
- data/spec/fixtures/schemas/with_nested_schema.rb +7 -0
- data/spec/fixtures/schemas/without_attributes.rb +3 -0
- data/spec/response_matcher/parse_schema_spec.rb +45 -0
- data/spec/response_matcher/settings_spec.rb +10 -0
- data/spec/response_matcher_spec.rb +5 -0
- data/spec/spec_helper.rb +4 -5
- metadata +10 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69d6ecfab7b35acd2792b09fd987e5845193dbf4
|
4
|
+
data.tar.gz: 109c25b684beccc191cb776f4a818f118df794d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc0df45664c34f4c36eeb7cb875276846a818ad21fb050d59dfe89408ee84fc075750dee059ce4d943da7f8ebd0457e8a60dc4cd0d92484397a22a6f3b94f2ab
|
7
|
+
data.tar.gz: 53d0e7dcc19c175e52fb6bda9e2d951db49ba6af611ef45102b3e794d3639213d6975b5f8d66c080e8f8aadf209be678dffeabecfe5d2bafba4e5356592218fd
|
data/.rspec
CHANGED
data/.rubocop.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
AllCops:
|
2
|
+
DisplayCopNames: true
|
3
|
+
DisplayStyleGuide: true
|
4
|
+
StyleGuideCopsOnly: true
|
5
|
+
TargetRubyVersion: 2.4
|
6
|
+
|
7
|
+
Metrics/LineLength:
|
8
|
+
Max: 120
|
9
|
+
|
10
|
+
Documentation:
|
11
|
+
Enabled: false
|
12
|
+
|
13
|
+
FrozenStringLiteralComment:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Metrics/ModuleLength:
|
17
|
+
Exclude:
|
18
|
+
- spec/**/*_spec.rb
|
data/README.md
CHANGED
@@ -7,7 +7,7 @@ Simple solution to check json response in your request tests as [Rspec](https://
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
9
|
```ruby
|
10
|
-
gem 'response_matcher'
|
10
|
+
gem 'response_matcher'
|
11
11
|
```
|
12
12
|
|
13
13
|
And then execute:
|
@@ -45,11 +45,6 @@ end
|
|
45
45
|
└─ ...
|
46
46
|
```
|
47
47
|
|
48
|
-
In ```registration_spec.rb```
|
49
|
-
```ruby
|
50
|
-
expect(response).to response_match('my_schema', user: User.last)
|
51
|
-
```
|
52
|
-
|
53
48
|
In ```my_schema.rb``` you can describe by ruby language how looks like your response
|
54
49
|
|
55
50
|
```ruby
|
@@ -128,7 +123,10 @@ end
|
|
128
123
|
In ```rails_helper.rb```
|
129
124
|
```ruby
|
130
125
|
ResponseMatcher::Settings.configure do |config|
|
131
|
-
config.helpers = [
|
126
|
+
config.helpers = [
|
127
|
+
Helpers::MyHelper,
|
128
|
+
...
|
129
|
+
]
|
132
130
|
end
|
133
131
|
```
|
134
132
|
|
@@ -148,7 +146,6 @@ In ```my_schema.rb```
|
|
148
146
|
In ```rails_helper.rb```
|
149
147
|
```ruby
|
150
148
|
ResponseMatcher::Settings.configure do |config|
|
151
|
-
config.helpers = [Helpers::MyHelper, ...]
|
152
149
|
config.directory = 'spec/schemas/api/v1'
|
153
150
|
end
|
154
151
|
```
|
data/circle.yml
ADDED
@@ -1,28 +1,37 @@
|
|
1
1
|
module ResponseMatcher
|
2
2
|
class ParseSchema
|
3
|
-
def self.new(schema_path,
|
4
|
-
Settings.config.helpers.each
|
5
|
-
|
6
|
-
end
|
7
|
-
|
8
|
-
attr_accessor(*object_hash.keys, :schema_path, :response, :object_hash)
|
3
|
+
def self.new(schema_path, objects = {})
|
4
|
+
Settings.config.helpers.each { |helper| include helper }
|
5
|
+
attr_accessor(*objects.keys)
|
9
6
|
|
10
|
-
super(schema_path,
|
7
|
+
super(schema_path, objects)
|
11
8
|
end
|
12
9
|
|
13
|
-
|
10
|
+
attr_reader :schema_path, :objects, :response
|
11
|
+
|
12
|
+
def initialize(schema_path, objects)
|
14
13
|
@schema_path = schema_path
|
15
|
-
@
|
14
|
+
@objects = objects
|
15
|
+
|
16
|
+
initialize_objects
|
17
|
+
render_schema
|
18
|
+
end
|
16
19
|
|
17
|
-
|
20
|
+
def call(schema_path, objects = {})
|
21
|
+
self.class.new(schema_path, objects).response
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def initialize_objects
|
27
|
+
objects.each do |name, value|
|
18
28
|
instance_variable_set "@#{name}", value
|
19
29
|
end
|
20
|
-
|
21
|
-
@response = eval(File.read(File.absolute_path("#{Settings.config.directory}/#{schema_path}.rb")))
|
22
30
|
end
|
23
31
|
|
24
|
-
def
|
25
|
-
|
32
|
+
def render_schema
|
33
|
+
path = File.absolute_path("#{Settings.config.directory}/#{schema_path}.rb")
|
34
|
+
@response = eval(File.read(path))
|
26
35
|
end
|
27
36
|
end
|
28
37
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module ResponseMatcher
|
2
|
+
describe ParseSchema do
|
3
|
+
context 'Render schema' do
|
4
|
+
before do
|
5
|
+
allow(Settings.config).to receive(:directory).and_return('spec/fixtures/schemas')
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:dummy) { double('dummy', name: 'name', id: 'id') }
|
9
|
+
|
10
|
+
it 'without attributes' do
|
11
|
+
subject = described_class.new('without_attributes')
|
12
|
+
expect(subject.response).to eq(data: {})
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'with attributes' do
|
16
|
+
subject = described_class.new('with_attributes', object: dummy)
|
17
|
+
|
18
|
+
expect(subject.response).to eq(data: {
|
19
|
+
id: dummy.id,
|
20
|
+
name: dummy.name
|
21
|
+
})
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'with nested schema' do
|
25
|
+
nested_dummy = double('nested_dummy', name: 'nested_name', id: 'nested_id')
|
26
|
+
subject = described_class.new('with_nested_schema', object: dummy, nested_object: nested_dummy)
|
27
|
+
|
28
|
+
expect(subject.response).to eq(
|
29
|
+
{
|
30
|
+
data: {
|
31
|
+
id: dummy.id,
|
32
|
+
name: dummy.name
|
33
|
+
},
|
34
|
+
nested_data: {
|
35
|
+
data: {
|
36
|
+
id: nested_dummy.id,
|
37
|
+
name: nested_dummy.name
|
38
|
+
}
|
39
|
+
}
|
40
|
+
}
|
41
|
+
)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
require 'bundler/setup'
|
2
|
+
require 'pry'
|
2
3
|
require 'response_matcher'
|
3
4
|
|
4
5
|
RSpec.configure do |config|
|
5
|
-
|
6
|
-
config.
|
7
|
-
|
8
|
-
# Disable RSpec exposing methods globally on `Module` and `main`
|
9
|
-
config.disable_monkey_patching!
|
6
|
+
config.order = :random
|
7
|
+
config.filter_run focus: true
|
8
|
+
config.run_all_when_everything_filtered = true
|
10
9
|
|
11
10
|
config.expect_with :rspec do |c|
|
12
11
|
c.syntax = :expect
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: response_matcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bezrukavyi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-configurable
|
@@ -103,17 +103,25 @@ extra_rdoc_files: []
|
|
103
103
|
files:
|
104
104
|
- ".gitignore"
|
105
105
|
- ".rspec"
|
106
|
+
- ".rubocop.yml"
|
106
107
|
- CODE_OF_CONDUCT.md
|
107
108
|
- Gemfile
|
108
109
|
- LICENSE.txt
|
109
110
|
- README.md
|
110
111
|
- Rakefile
|
112
|
+
- circle.yml
|
111
113
|
- lib/response_matcher.rb
|
112
114
|
- lib/response_matcher/parse_schema.rb
|
113
115
|
- lib/response_matcher/response_match.rb
|
114
116
|
- lib/response_matcher/settings.rb
|
115
117
|
- lib/response_matcher/version.rb
|
116
118
|
- response_matcher.gemspec
|
119
|
+
- spec/fixtures/schemas/with_attributes.rb
|
120
|
+
- spec/fixtures/schemas/with_nested_schema.rb
|
121
|
+
- spec/fixtures/schemas/without_attributes.rb
|
122
|
+
- spec/response_matcher/parse_schema_spec.rb
|
123
|
+
- spec/response_matcher/settings_spec.rb
|
124
|
+
- spec/response_matcher_spec.rb
|
117
125
|
- spec/spec_helper.rb
|
118
126
|
homepage: https://github.com/bezrukavyi/response_matcher
|
119
127
|
licenses:
|