rspec-rcv 0.1.1 → 0.1.2
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 +4 -4
- data/lib/rspec_rcv.rb +5 -0
- data/lib/rspec_rcv/codecs/pretty_json.rb +15 -0
- data/lib/rspec_rcv/codecs/yaml.rb +15 -0
- data/lib/rspec_rcv/configuration.rb +6 -12
- data/lib/rspec_rcv/handler.rb +2 -7
- data/lib/rspec_rcv/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a783908cd11d083077bf4eb98891e8a54353c29e
|
4
|
+
data.tar.gz: e816f2cd43c83027eca2382c152aec84f26b6ee3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b055ccc2c89a77db00197fc3adae47b1cdb623a780ca2a24078b951c953eccb14c0f4aa10196bca8fe0fdc8947d06310e93f08bec1f21d3f1f1f704c60602c63
|
7
|
+
data.tar.gz: 8ac4afdf9b6fd7d7681e70a16d590c851d3ee594a698f3e8068bad9f3a9448ecd4add5fc4d2c1d60ffd65217f032369c7bcc31c92bf27dbc8416dd3016a635fa
|
data/lib/rspec_rcv.rb
CHANGED
@@ -1,10 +1,15 @@
|
|
1
1
|
require "rspec_rcv/version"
|
2
|
+
|
3
|
+
require "rspec_rcv/codecs/pretty_json"
|
4
|
+
require "rspec_rcv/codecs/yaml"
|
5
|
+
|
2
6
|
require "rspec_rcv/configuration"
|
3
7
|
require "rspec_rcv/test_frameworks/rspec"
|
4
8
|
|
5
9
|
require "rspec_rcv/handler"
|
6
10
|
require "rspec_rcv/data_changed_error"
|
7
11
|
|
12
|
+
|
8
13
|
module RSpecRcv
|
9
14
|
extend self
|
10
15
|
|
@@ -1,15 +1,9 @@
|
|
1
1
|
module RSpecRcv
|
2
2
|
class Configuration
|
3
3
|
DEFAULTS = {
|
4
|
-
exportable_proc: Proc.new { response.body },
|
4
|
+
exportable_proc: Proc.new { JSON.parse(response.body) },
|
5
5
|
compare_with: Proc.new { |existing, new| existing == new },
|
6
|
-
|
7
|
-
begin
|
8
|
-
hash[:data] = JSON.parse(hash[:data])
|
9
|
-
rescue JSON::ParserError
|
10
|
-
end
|
11
|
-
JSON.pretty_generate(hash)
|
12
|
-
end,
|
6
|
+
codec: Codecs::PrettyJson.new,
|
13
7
|
fail_on_changed_output: true,
|
14
8
|
base_path: nil,
|
15
9
|
fixture: nil
|
@@ -42,12 +36,12 @@ module RSpecRcv
|
|
42
36
|
@opts[:exportable_proc] = val
|
43
37
|
end
|
44
38
|
|
45
|
-
def
|
46
|
-
@opts[:
|
39
|
+
def codec
|
40
|
+
@opts[:codec]
|
47
41
|
end
|
48
42
|
|
49
|
-
def
|
50
|
-
@opts[:
|
43
|
+
def codec=(val)
|
44
|
+
@opts[:codec] = val
|
51
45
|
end
|
52
46
|
|
53
47
|
def compare_with
|
data/lib/rspec_rcv/handler.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'json'
|
2
1
|
require 'diffy'
|
3
2
|
|
4
3
|
module RSpecRcv
|
@@ -13,7 +12,7 @@ module RSpecRcv
|
|
13
12
|
return if existing_data && existing_data["file"] == file_path && existing_data["data"] == data
|
14
13
|
|
15
14
|
output = { recorded_at: Time.now, file: file_path, data: data }
|
16
|
-
output = opts[:
|
15
|
+
output = opts[:codec].export_with(output) + "\n"
|
17
16
|
|
18
17
|
if existing_data
|
19
18
|
eq = opts[:compare_with].call(existing_data["data"], data)
|
@@ -52,11 +51,7 @@ module RSpecRcv
|
|
52
51
|
|
53
52
|
def existing_data
|
54
53
|
@existing_data ||= if File.exists?(path)
|
55
|
-
|
56
|
-
JSON.parse(File.read(path))
|
57
|
-
rescue JSON::ParserError
|
58
|
-
# The file must not have been valid, so we will overwrite it
|
59
|
-
end
|
54
|
+
opts[:codec].decode_with(File.read(path))
|
60
55
|
end
|
61
56
|
end
|
62
57
|
end
|
data/lib/rspec_rcv/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen Bussey
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,6 +80,8 @@ files:
|
|
80
80
|
- README.md
|
81
81
|
- Rakefile
|
82
82
|
- lib/rspec_rcv.rb
|
83
|
+
- lib/rspec_rcv/codecs/pretty_json.rb
|
84
|
+
- lib/rspec_rcv/codecs/yaml.rb
|
83
85
|
- lib/rspec_rcv/configuration.rb
|
84
86
|
- lib/rspec_rcv/data_changed_error.rb
|
85
87
|
- lib/rspec_rcv/handler.rb
|