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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 62b3a8d716c6ffce6fe323ef1892cfd80c6f922f
4
- data.tar.gz: 6a55d9f3d6dcfb74a4a723001efa2b13cbca04ed
3
+ metadata.gz: 8825f55c2ec3a93214642eb39530026990cf9670
4
+ data.tar.gz: b5e3196e7d63da1ba024ee61e8c772d285788505
5
5
  SHA512:
6
- metadata.gz: 91074435ecde69054339d80bfae8cae50cd1d8bd7ad718a32dbd6bafe1f2776751759d3412f57768b616ea076e40ae5993dccedfacf178b51fa94fe913eea086
7
- data.tar.gz: 978ebe2eb26c108a1b387e4668c268608d4efc852ccb57f33ab9b8faa20e5f5c3b6a4e289a0f0428eb6c58791f5cf94483cfb179447f19b0e5fe2d0a6f030366
6
+ metadata.gz: 841cebf017ad6a4687e00bcbccba9c64ca4070b5c687528f47a35ddda3ef9838a5ae1597870bd9398ca92c03a49c1c312e56913a82699f52975d8c5a27fe6068
7
+ data.tar.gz: 4f5b88ec81b959c6cf00e9e8e6f4c02c055e97f9c6687e2fe096957139b61a299c60ba6d382850decd393f2ed28a5d2d6813fefbbf2cfd0a1fa41a22a44a79d0
@@ -27,6 +27,6 @@ module RSpecRcv
27
27
  end
28
28
 
29
29
  def config(overrides=nil)
30
- @configuration.opts(overrides)
30
+ configuration.opts(overrides)
31
31
  end
32
32
  end
@@ -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
- diff = Diffy::Diff.new(existing_file, output)
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
@@ -1,3 +1,3 @@
1
1
  module RSpecRcv
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.6"
3
3
  end
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.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-10-22 00:00:00.000000000 Z
11
+ date: 2015-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler