rspec-rcv 0.2.2 → 0.2.6
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 +1 -1
- data/lib/rspec-rcv/handler.rb +35 -4
- data/lib/rspec-rcv/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8825f55c2ec3a93214642eb39530026990cf9670
|
4
|
+
data.tar.gz: b5e3196e7d63da1ba024ee61e8c772d285788505
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 841cebf017ad6a4687e00bcbccba9c64ca4070b5c687528f47a35ddda3ef9838a5ae1597870bd9398ca92c03a49c1c312e56913a82699f52975d8c5a27fe6068
|
7
|
+
data.tar.gz: 4f5b88ec81b959c6cf00e9e8e6f4c02c055e97f9c6687e2fe096957139b61a299c60ba6d382850decd393f2ed28a5d2d6813fefbbf2cfd0a1fa41a22a44a79d0
|
data/lib/rspec-rcv.rb
CHANGED
data/lib/rspec-rcv/handler.rb
CHANGED
@@ -9,7 +9,7 @@ module RSpecRcv
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def call
|
12
|
-
return if existing_data && existing_data["file"] == file_path && existing_data["data"] == data
|
12
|
+
return :no_change if existing_data && existing_data["file"] == file_path && existing_data["data"] == data
|
13
13
|
|
14
14
|
output = { recorded_at: Time.now, file: file_path, data: data }
|
15
15
|
output = opts[:codec].export_with(output) + "\n"
|
@@ -18,17 +18,18 @@ module RSpecRcv
|
|
18
18
|
eq = opts[:compare_with].call(existing_data["data"], data, opts)
|
19
19
|
|
20
20
|
if !eq && opts[:fail_on_changed_output]
|
21
|
-
|
22
|
-
raise RSpecRcv::DataChangedError.new("Existing data will be overwritten. Turn off this feature with fail_on_changed_output=false\n\n#{diff}")
|
21
|
+
raise_error!(output)
|
23
22
|
end
|
24
23
|
|
25
|
-
return if eq
|
24
|
+
return :same if eq
|
26
25
|
end
|
27
26
|
|
28
27
|
FileUtils.mkdir_p(File.dirname(path))
|
29
28
|
File.open(path, 'w') do |file|
|
30
29
|
file.write(output)
|
31
30
|
end
|
31
|
+
|
32
|
+
return :to_disk
|
32
33
|
end
|
33
34
|
|
34
35
|
private
|
@@ -54,5 +55,35 @@ module RSpecRcv
|
|
54
55
|
opts[:codec].decode_with(File.read(path))
|
55
56
|
end
|
56
57
|
end
|
58
|
+
|
59
|
+
def raise_error!(output)
|
60
|
+
diff = Diffy::Diff.new(existing_file, output).to_s
|
61
|
+
data_index = diff.lines.find_index{ |line| line =~ /"data":/ } # keys before data are un-important
|
62
|
+
|
63
|
+
removed = []
|
64
|
+
added = []
|
65
|
+
|
66
|
+
diff.lines[data_index..-1].each do |line|
|
67
|
+
key = line.split("\"")[1]
|
68
|
+
next if key.nil?
|
69
|
+
next if opts.fetch(:ignore_keys, []).include?(key.to_s)
|
70
|
+
next if opts.fetch(:ignore_keys, []).include?(key.to_sym)
|
71
|
+
|
72
|
+
if line.start_with?("-")
|
73
|
+
removed << key
|
74
|
+
elsif line.start_with?("+")
|
75
|
+
added << key
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
raise RSpecRcv::DataChangedError.new(<<-EOF)
|
80
|
+
Existing data will be overwritten. Turn off this feature with fail_on_changed_output=false
|
81
|
+
|
82
|
+
#{diff}
|
83
|
+
|
84
|
+
The following keys were added: #{added.uniq}
|
85
|
+
The following keys were removed: #{removed.uniq}
|
86
|
+
EOF
|
87
|
+
end
|
57
88
|
end
|
58
89
|
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.2.
|
4
|
+
version: 0.2.6
|
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-
|
11
|
+
date: 2015-11-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|