rspec-rcv 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +33 -17
- data/lib/rspec_rcv.rb +1 -0
- data/lib/rspec_rcv/configuration.rb +12 -1
- data/lib/rspec_rcv/handler.rb +1 -1
- data/lib/rspec_rcv/helpers/deep_except.rb +28 -0
- data/lib/rspec_rcv/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6594a5efc10dfc904a94eab1c8edc61c4671e054
|
4
|
+
data.tar.gz: 34bee1dfb7ffc22268827ec07d2c8e84c32e67e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6af94e5c1df0e47eb082d9ec9a483e1ce35c6bc1f3bb323db09796a862c634bf031d32a8d1e57cdea4bf7cdf5fab8e49de2a0ff1cbd7e77381918817aff0ea25
|
7
|
+
data.tar.gz: f3b5cad2b80a2289d2d37dacef440edd18f4d46d3ea9aa2cdfa8cb69a81a6e682cc612f69f5b58aec7fba55741ded4e1e5aa178a57ef92aa0e93e1fc2f68a05c
|
data/README.md
CHANGED
@@ -30,34 +30,50 @@ the file in the spec suite.
|
|
30
30
|
|
31
31
|
# Configuration Options
|
32
32
|
|
33
|
-
The following options are available to override, as well as
|
33
|
+
The following options are available to override, as well as important default values:
|
34
34
|
|
35
35
|
```ruby
|
36
36
|
config.exportable_proc = Proc.new { response.body }
|
37
|
-
config.compare_with
|
38
|
-
config.
|
39
|
-
|
40
|
-
hash[:data] = JSON.parse(hash[:data])
|
41
|
-
rescue JSON::ParserError
|
42
|
-
end
|
43
|
-
JSON.pretty_generate(hash)
|
44
|
-
end
|
37
|
+
config.compare_with # Deep ignoring comparison by default
|
38
|
+
config.codec = Codecs::PrettyJson.new
|
39
|
+
config.ignore_keys = []
|
45
40
|
config.base_path = nil
|
46
41
|
config.fail_on_changed_output = true
|
47
42
|
```
|
48
43
|
|
49
|
-
`exportable_proc`, `compare_with
|
50
|
-
and should be a String. For `compare_with`, the proc should return true when existing and new are considered equal.
|
51
|
-
a hash will be passed in and the result will be a String written to disk.
|
44
|
+
`exportable_proc`, `compare_with` must implement `.call`. For `exportable_proc`, the result will be written to disk
|
45
|
+
and should be a String. For `compare_with`, the proc should return true when existing and new are considered equal.
|
52
46
|
|
53
|
-
`
|
54
|
-
|
55
|
-
|
56
|
-
Note: This can support things that aren't JSON because you can override Proc's that you need to. However, some of the internal workings assume JSON and so it is recommended to just keep the file as JSON.
|
47
|
+
`codec` must implement `export_with(hash)` and `decode_with(str)`. There is a PrettyJson and Yaml codec included in this gem,
|
48
|
+
and PrettyJson is the default as it can be directly consumed by javascript.
|
57
49
|
|
58
50
|
# What about fields that change everytime I run the specs?
|
59
51
|
|
60
|
-
|
52
|
+
There is an option called `ignore_keys` which will deep ignore keys that you don't want to cause spec change. For instance,
|
53
|
+
the following hashes would not trigger a change with `ignore_keys = [:id]`
|
54
|
+
|
55
|
+
```
|
56
|
+
{
|
57
|
+
id: 1,
|
58
|
+
deep: {
|
59
|
+
id: 2,
|
60
|
+
name: "Steve"
|
61
|
+
}
|
62
|
+
}
|
63
|
+
|
64
|
+
{
|
65
|
+
id: "DIFF",
|
66
|
+
deep: {
|
67
|
+
id: "DIFF,
|
68
|
+
name: "Steve"
|
69
|
+
}
|
70
|
+
}
|
71
|
+
```
|
72
|
+
|
73
|
+
but if the name changed from "Steve", then a change would be triggered.
|
74
|
+
|
75
|
+
If you want more configuration, you can override `compare_with`. For instance, here is a configuration to shallowly ignore
|
76
|
+
`id, created_at, updated_at` in a Rails app:
|
61
77
|
|
62
78
|
```ruby
|
63
79
|
RSpecRcv.configure do |config|
|
data/lib/rspec_rcv.rb
CHANGED
@@ -2,8 +2,11 @@ module RSpecRcv
|
|
2
2
|
class Configuration
|
3
3
|
DEFAULTS = {
|
4
4
|
exportable_proc: Proc.new { JSON.parse(response.body) },
|
5
|
-
compare_with: Proc.new
|
5
|
+
compare_with: Proc.new do |existing, new, opts|
|
6
|
+
Helpers::DeepExcept.new(existing, opts[:ignore_keys]).to_h == Helpers::DeepExcept.new(new, opts[:ignore_keys]).to_h
|
7
|
+
end,
|
6
8
|
codec: Codecs::PrettyJson.new,
|
9
|
+
ignore_keys: [],
|
7
10
|
fail_on_changed_output: true,
|
8
11
|
base_path: nil,
|
9
12
|
fixture: nil
|
@@ -44,6 +47,14 @@ module RSpecRcv
|
|
44
47
|
@opts[:codec] = val
|
45
48
|
end
|
46
49
|
|
50
|
+
def ignore_keys
|
51
|
+
@opts[:ignore_keys]
|
52
|
+
end
|
53
|
+
|
54
|
+
def ignore_keys=(val)
|
55
|
+
@opts[:ignore_keys] = val
|
56
|
+
end
|
57
|
+
|
47
58
|
def compare_with
|
48
59
|
@opts[:compare_with]
|
49
60
|
end
|
data/lib/rspec_rcv/handler.rb
CHANGED
@@ -15,7 +15,7 @@ module RSpecRcv
|
|
15
15
|
output = opts[:codec].export_with(output) + "\n"
|
16
16
|
|
17
17
|
if existing_data
|
18
|
-
eq = opts[:compare_with].call(existing_data["data"], data)
|
18
|
+
eq = opts[:compare_with].call(existing_data["data"], data, opts)
|
19
19
|
|
20
20
|
if !eq && opts[:fail_on_changed_output]
|
21
21
|
diff = Diffy::Diff.new(existing_file, output)
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module RSpecRcv
|
2
|
+
module Helpers
|
3
|
+
class DeepExcept
|
4
|
+
def initialize(hash, except)
|
5
|
+
@hash = hash
|
6
|
+
@except = except
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_h
|
10
|
+
inject(@hash, @except.map(&:to_sym))
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def inject(hash, except)
|
16
|
+
hash.inject({}) do |h, (k, v)|
|
17
|
+
if v && v.respond_to?(:to_h)
|
18
|
+
h[k] = inject(v, except)
|
19
|
+
elsif !except.include?(k.to_sym)
|
20
|
+
h[k] = v
|
21
|
+
end
|
22
|
+
h
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
data/lib/rspec_rcv/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-rcv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen Bussey
|
@@ -85,6 +85,7 @@ files:
|
|
85
85
|
- lib/rspec_rcv/configuration.rb
|
86
86
|
- lib/rspec_rcv/data_changed_error.rb
|
87
87
|
- lib/rspec_rcv/handler.rb
|
88
|
+
- lib/rspec_rcv/helpers/deep_except.rb
|
88
89
|
- lib/rspec_rcv/test_frameworks/rspec.rb
|
89
90
|
- lib/rspec_rcv/version.rb
|
90
91
|
- rspec-rcv.gemspec
|