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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 977ebc5ea4dd78cb71267be4db6aae26d003ea74
4
- data.tar.gz: 3e79f713985b79424324a1fbeb1f3bf8928f940d
3
+ metadata.gz: a783908cd11d083077bf4eb98891e8a54353c29e
4
+ data.tar.gz: e816f2cd43c83027eca2382c152aec84f26b6ee3
5
5
  SHA512:
6
- metadata.gz: f6a2ae58a7a65e9f63d17a145ae2e084661ef9de18452cef8d2d2578d7c112ed4649a66f485e729a846e6fb08d422b6a690242cf8c22b5630c37347ec0102339
7
- data.tar.gz: 367b3f6f801f58506f91de6d3848624d58e23c51ccc7f26fe9d99ebe765524cac8df6fbd520319321525ac2c828934cf7959a53d1fc80761485f866c607a77cf
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
 
@@ -0,0 +1,15 @@
1
+ require 'json'
2
+
3
+ module RSpecRcv
4
+ module Codecs
5
+ class PrettyJson
6
+ def export_with(hash)
7
+ JSON.pretty_generate(hash)
8
+ end
9
+
10
+ def decode_with(str)
11
+ JSON.parse(str)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ require 'yaml'
2
+
3
+ module RSpecRcv
4
+ module Codecs
5
+ class Yaml
6
+ def export_with(hash)
7
+ YAML.dump(hash)
8
+ end
9
+
10
+ def decode_with(str)
11
+ YAML.load(str)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -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
- export_with: Proc.new do |hash|
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 export_with
46
- @opts[:export_with]
39
+ def codec
40
+ @opts[:codec]
47
41
  end
48
42
 
49
- def export_with=(val)
50
- @opts[:export_with] = val
43
+ def codec=(val)
44
+ @opts[:codec] = val
51
45
  end
52
46
 
53
47
  def compare_with
@@ -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[:export_with].call(output) + "\n"
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
- begin
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
@@ -1,3 +1,3 @@
1
1
  module RSpecRcv
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
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.1.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-16 00:00:00.000000000 Z
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