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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1c15b7492a0b8b2a2285d1248c7bf6ae738932dd
4
- data.tar.gz: 797f9192a2b9a9b89d6571f5e47cd26e8ed60508
3
+ metadata.gz: 69d6ecfab7b35acd2792b09fd987e5845193dbf4
4
+ data.tar.gz: 109c25b684beccc191cb776f4a818f118df794d2
5
5
  SHA512:
6
- metadata.gz: c5e810950d3d734b9aa2b64ef765cb0aa7b0f0e8c483d853d325e1cff53fe46caae25cb551e757ea9e2a7445cc7b6dd338846868cc273bdcada397f60f31d597
7
- data.tar.gz: 6e0fe70ed06e0f02366aa1c8ce6b1785eff2cd4635ab3597fad61f8977188b674ab2fe19e6586fe62b42684effe922660ce3ab6ebd89f28b4f9f98069f699cec
6
+ metadata.gz: bc0df45664c34f4c36eeb7cb875276846a818ad21fb050d59dfe89408ee84fc075750dee059ce4d943da7f8ebd0457e8a60dc4cd0d92484397a22a6f3b94f2ab
7
+ data.tar.gz: 53d0e7dcc19c175e52fb6bda9e2d951db49ba6af611ef45102b3e794d3639213d6975b5f8d66c080e8f8aadf209be678dffeabecfe5d2bafba4e5356592218fd
data/.rspec CHANGED
@@ -1,2 +1,3 @@
1
+ --require spec_helper
1
2
  --format documentation
2
3
  --color
@@ -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', '~> 0.1.1'
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 = [Helpers::MyHelper, ...]
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
  ```
@@ -0,0 +1,6 @@
1
+ machine:
2
+ ruby:
3
+ version: 2.4.2
4
+ dependencies:
5
+ pre:
6
+ - gem install bundler
@@ -1,28 +1,37 @@
1
1
  module ResponseMatcher
2
2
  class ParseSchema
3
- def self.new(schema_path, object_hash = {})
4
- Settings.config.helpers.each do |helper|
5
- include helper
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, object_hash)
7
+ super(schema_path, objects)
11
8
  end
12
9
 
13
- def initialize(schema_path, object_hash)
10
+ attr_reader :schema_path, :objects, :response
11
+
12
+ def initialize(schema_path, objects)
14
13
  @schema_path = schema_path
15
- @object_hash = object_hash
14
+ @objects = objects
15
+
16
+ initialize_objects
17
+ render_schema
18
+ end
16
19
 
17
- object_hash.each do |name, value|
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 call(schema_path, object_hash = {})
25
- self.class.new(schema_path, object_hash).response
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
@@ -1,3 +1,3 @@
1
1
  module ResponseMatcher
2
- VERSION = '0.1.1'.freeze
2
+ VERSION = '0.1.2'.freeze
3
3
  end
@@ -0,0 +1,6 @@
1
+ {
2
+ data: {
3
+ id: object.id,
4
+ name: object.name
5
+ }
6
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ data: {
3
+ id: object.id,
4
+ name: object.name
5
+ },
6
+ nested_data: call('with_attributes', object: nested_object)
7
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ data: {}
3
+ }
@@ -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
@@ -0,0 +1,10 @@
1
+ module ResponseMatcher
2
+ describe Settings do
3
+ subject { ResponseMatcher::Settings.config }
4
+
5
+ context 'has default settings' do
6
+ it { expect(subject.helpers).to eq([]) }
7
+ it { expect(subject.directory).to eq('spec/schemas') }
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ describe ResponseMatcher do
2
+ it 'has a version number' do
3
+ expect(ResponseMatcher::VERSION).not_to be nil
4
+ end
5
+ end
@@ -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
- # Enable flags like --only-failures and --next-failure
6
- config.example_status_persistence_file_path = '.rspec_status'
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.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-10-29 00:00:00.000000000 Z
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: