approvals 0.0.19 → 0.0.25

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 6e2bdf9201b64d91a4d5368e0edf159eb3dd5cb2
4
- data.tar.gz: f82203e46e50c60ac0d229db67a8ac6651fc6b8a
2
+ SHA256:
3
+ metadata.gz: d9fa305870fc2d21ab0b22f4809721dc16dd058da1af3fc2fc356511817c1594
4
+ data.tar.gz: 7266db245dbbaf498cd3598a1f7bcbcab4dbfc34fe5cf35463dc55f99d1935b7
5
5
  SHA512:
6
- metadata.gz: 3cbe81a1c8ab477819e5080a7cae752e0fab27f759497eb23bd5e84f0135a7622a7b82915693fc168c1a2d874393043471940c939c99011df56942035e31724a
7
- data.tar.gz: cf9c5b74d5e40bfcef8b78dfeabb236d2d1328ca5b1264224a02b801d2caa4f9322e9e70cdf7fd3ba8643235cf3335982122584f99c6c0d2009166ef42d94350
6
+ metadata.gz: 417b63747eaed8183d716062279730221a149fe0ebb3970ec06c83dd9337d70e530ae4a70f1993b43d8a6ac0a233ee1f6958007b3f8329637480cee23516d96b
7
+ data.tar.gz: 763de7b3a7ede22c7781440e77ac9cc0af01dd1e1174981a89e439e2525df9d5c5873b66477e71e717be45084603c8c43e37ec5d97f99df626d607140003ccc9
data/.gitignore CHANGED
@@ -5,3 +5,6 @@ pkg/*
5
5
  *.received.txt
6
6
  .approvals
7
7
  tmp/
8
+ vendor/
9
+
10
+ ext/Rakefile
data/.travis.yml CHANGED
@@ -1,10 +1,27 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.2
4
- - 1.9.3
5
3
  - 2.0.0
6
- - 2.1.0
4
+ - 2.1.10
5
+ - 2.2.10
6
+ - 2.3.8
7
+ - 2.4.8
8
+ - 2.5.7
9
+ - 2.6.5
10
+ - 2.7.0
7
11
  - ruby-head
8
- - rbx-2
12
+ - rbx-3
13
+ matrix:
14
+ allow_failures:
15
+ - rvm: rbx-3
16
+ before_install:
17
+ - |
18
+ r_eng="$(ruby -e 'STDOUT.write RUBY_ENGINE')";
19
+ rv="$(ruby -e 'STDOUT.write RUBY_VERSION')";
20
+ if [ "$r_eng" == "ruby" ]; then
21
+ if [ "$rv" \< "2.3" ]; then gem update --system 2.7.10 --no-document
22
+ elif [ "$rv" \< "2.6" ]; then gem update --system --no-document --conservative
23
+ fi
24
+ fi
25
+ - gem update bundler
9
26
  script: bundle exec rspec spec
10
27
  cache: bundler
data/CHANGELOG.md CHANGED
@@ -4,6 +4,19 @@
4
4
 
5
5
  * Your contribution here
6
6
 
7
+ ### v0.0.22 (2015-10-22)
8
+
9
+ * Fix bug in non-binary comparisons.
10
+
11
+ ### v0.0.21 (2015-10-12)
12
+
13
+ * [#64](https://github.com/kytrinyx/approvals/pull/64) Silence deprecation warnings - [@tmock12](https://github.com/tmock12)
14
+ * Fixed typos and replaced a deprecated standard library method call.
15
+
16
+ ### v0.0.20 (2015-04-21)
17
+
18
+ * [#63](https://github.com/kytrinyx/approvals/issues/62) Make CLI --ask compatible with new or old .approval file. - [@kytrinyx](https://github.com/kytrinyx)
19
+
7
20
  ### v0.0.19 (2015-04-20)
8
21
 
9
22
  * [#62](https://github.com/kytrinyx/approvals/issues/62) Fix bug in CLI with --ask option that deletes approval file instead of overwriting it. - [@kytrinyx](https://github.com/kytrinyx)
data/README.md CHANGED
@@ -23,8 +23,8 @@ which Llewellyn Falco is interviewed about approvals.
23
23
  ## Configuration
24
24
 
25
25
  ```ruby
26
- Approvals.configure do |c|
27
- c.approvals_path = 'output/goes/here/'
26
+ Approvals.configure do |config|
27
+ config.approvals_path = 'output/goes/here/'
28
28
  end
29
29
  ```
30
30
 
@@ -42,18 +42,43 @@ Approvals.verify(your_subject, :format => :json)
42
42
 
43
43
  This will raise an `ApprovalError` in the case of a failure.
44
44
 
45
- The default writer uses the `:to_s` method on the subject will be used to generate the output for
46
- the `received` file. For custom complex objects you will need to override
47
- `:to_s` to get helpful output, rather than the default:
48
-
49
- #<Object:0x0000010105ea40> # or whatever the object id is
50
-
51
45
  The first time the approval is run, a file will be created with the contents of the subject of your approval:
52
46
 
53
47
  the_name_of_the_approval.received.txt # or .json, .html, .xml as appropriate
54
48
 
55
49
  Since you have not yet approved anything, the `*.approved` file does not exist, and the comparison will fail.
56
50
 
51
+ ### Customizing formatted output
52
+
53
+ The default writer uses the `:to_s` method on the subject to generate the output for the received file.
54
+ For custom complex objects you will need to provide a custom writer to get helpful output, rather than the default:
55
+
56
+ #<Object:0x0000010105ea40> # or whatever the object id is
57
+
58
+ Create a custom writer class somewhere accessible to your test:
59
+
60
+ ```
61
+ class MyCustomWriter < Approvals::Writers::TextWriter
62
+ def format(data)
63
+ # Custom data formatting here
64
+ end
65
+
66
+ def filter(data)
67
+ # Custom data filtering here
68
+ end
69
+ end
70
+ ```
71
+
72
+ In your test, use a string to reference your custom class:
73
+
74
+ ```
75
+ it "verifies a complex object" do
76
+ Approvals.verify hello, :format => "MyCustomWriter"
77
+ end
78
+ ```
79
+
80
+ Define and use different custom writers as needed!
81
+
57
82
  ## CLI
58
83
 
59
84
  The gem comes with a command-line tool that makes it easier to manage the
@@ -115,17 +140,17 @@ spec/fixtures/approvals/
115
140
  You can override this:
116
141
 
117
142
  ```ruby
118
- RSpec.configure do |c|
119
- c.approvals_path = 'some/other/path'
143
+ RSpec.configure do |config|
144
+ config.approvals_path = 'some/other/path'
120
145
  end
121
146
  ```
122
147
 
123
148
  The basic format of the approval is modeled after RSpec's `it`:
124
149
 
125
150
  ```ruby
126
- it "works" do
151
+ it 'works' do
127
152
  verify do
128
- "this is the the thing you want to verify"
153
+ 'this is the the thing you want to verify'
129
154
  end
130
155
  end
131
156
  ```
@@ -135,21 +160,21 @@ end
135
160
  When using RSpec, the namer is set for you, using the example's `full_description`.
136
161
 
137
162
  ```ruby
138
- Approvals.verify(thing, :name => "the name of your test")
163
+ Approvals.verify(thing, :name => 'the name of your test')
139
164
  ```
140
165
 
141
166
  ### Formatting
142
167
 
143
168
  You can pass a format for your output before it gets written to the file.
144
- At the moment, only text, xml, html, and json are supported.
169
+ At the moment, only text, xml, html, and json are supported, while text is the default.
145
170
 
146
- Simply add a `:format => :text`, `:format => :xml`, `:format => :html`, or `:format => :json` option to the example:
171
+ Simply add a `:format => :txt`, `:format => :xml`, `:format => :html`, or `:format => :json` option to the example:
147
172
 
148
173
  ```ruby
149
- page = "<html><head></head><body><h1>ZOMG</h1></body></html>"
174
+ page = '<html><head></head><body><h1>ZOMG</h1></body></html>'
150
175
  Approvals.verify page, :format => :html
151
176
 
152
- data = "{\"beverage\":\"coffee\"}"
177
+ data = '{\'beverage\':\'coffee\'}'
153
178
  Approvals.verify data, :format => :json
154
179
  ```
155
180
 
@@ -157,19 +182,27 @@ In RSpec, it looks like this:
157
182
 
158
183
  ```ruby
159
184
  verify :format => :html do
160
- "<html><head></head><body><h1>ZOMG</h1></body></html>"
185
+ '<html><head></head><body><h1>ZOMG</h1></body></html>'
161
186
  end
162
187
 
163
188
  verify :format => :json do
164
- "{\"beverage\":\"coffee\"}"
189
+ '{\'beverage\':\'coffee\'}'
190
+ end
191
+ ```
192
+
193
+ If you like you could also change the default format globally with:
194
+
195
+ ```ruby
196
+ RSpec.configure do |config|
197
+ config.approvals_default_format = :json # or :xml, :html
165
198
  end
166
199
  ```
167
200
 
168
- ### Exclude dynamicly changed values from json
201
+ ### Exclude dynamically changed values from json
169
202
 
170
203
  ```ruby
171
- Approvals.configure do |c|
172
- c.excluded_json_keys = {
204
+ Approvals.configure do |config|
205
+ config.excluded_json_keys = {
173
206
  :id =>/(\A|_)id$/,
174
207
  :date => /_at$/
175
208
  }
data/approvals.gemspec CHANGED
@@ -9,9 +9,9 @@ Gem::Specification.new do |s|
9
9
  s.licenses = ['MIT']
10
10
  s.authors = ["Katrina Owen"]
11
11
  s.email = ["katrina.owen@gmail.com"]
12
- s.homepage = ""
12
+ s.homepage = "https://github.com/kytrinyx/approvals"
13
13
  s.summary = %q{Approval Tests for Ruby}
14
- s.description = %q{Approval Tests for Ruby}
14
+ s.description = %q{A library to make it easier to do golden-master style testing in Ruby}
15
15
 
16
16
  s.rubyforge_project = "approvals"
17
17
 
@@ -19,9 +19,18 @@ Gem::Specification.new do |s|
19
19
  s.test_files = `git ls-files -- {spec}/*`.split("\n")
20
20
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
21
  s.require_paths = ["lib"]
22
+ s.extensions << 'ext/mkrf_conf.rb'
22
23
 
24
+ s.add_dependency 'thor', '~> 1.0'
25
+
26
+ if RUBY_VERSION < "2.1"
27
+ s.add_dependency 'nokogiri', '~> 1.6.8'
28
+ else
29
+ s.add_dependency 'nokogiri', '~> 1.8'
30
+ end
31
+ # We also depend on the json gem, but the version we need is
32
+ # Ruby-version-specific. See `ext/mkrf_conf.rb`.
33
+
34
+ s.add_development_dependency 'rake', '~> 13.0'
23
35
  s.add_development_dependency 'rspec', '~> 3.1'
24
- s.add_development_dependency 'json', '~> 1.8'
25
- s.add_dependency 'thor', '~> 0.18'
26
- s.add_dependency 'nokogiri', '~> 1.6'
27
36
  end
data/ext/mkrf_conf.rb ADDED
@@ -0,0 +1,22 @@
1
+ require 'rubygems/dependency_installer'
2
+
3
+ # This is how we can depend on a different version of the same gem for
4
+ # different Ruby versions.
5
+ # See https://en.wikibooks.org/wiki/Ruby_Programming/RubyGems
6
+
7
+ installer = Gem::DependencyInstaller.new
8
+
9
+ begin
10
+ if RUBY_VERSION >= '2.0'
11
+ installer.install 'json', '~> 2.0'
12
+ else
13
+ installer.install 'json', '~> 1.8'
14
+ end
15
+ rescue
16
+ exit(1)
17
+ end
18
+
19
+ # Write fake Rakefile for rake since Makefile isn't used
20
+ File.open(File.join(File.dirname(__FILE__), 'Rakefile'), 'w') do |f|
21
+ f.write("task :default\n")
22
+ end
data/lib/approvals.rb CHANGED
@@ -13,6 +13,7 @@ require 'approvals/executable'
13
13
  require 'approvals/reporters'
14
14
  require 'approvals/filter'
15
15
  require 'approvals/writer'
16
+ require 'approvals/verifier'
16
17
  require 'approvals/namers/default_namer'
17
18
 
18
19
  module Approvals
@@ -1,4 +1,4 @@
1
- require 'erb' # It is referenced on line 56
1
+ require 'erb' # It is referenced on line 69
2
2
  module Approvals
3
3
  class Approval
4
4
  class << self
@@ -19,9 +19,9 @@ module Approvals
19
19
  # Add a Proc that tests if subject is a kind of format
20
20
  IDENTITIES = {
21
21
  hash: Proc.new(){|subject|subject.respond_to? :each_pair},
22
- array: Proc.new(){|subject|subject.respond_to? :each_with_index},
22
+ array: Proc.new(){|subject|subject.respond_to? :each_with_index},
23
23
  }
24
-
24
+
25
25
  def identify_format
26
26
  IDENTITIES.each_pair do |format, id_test|
27
27
  return format if id_test.call(subject)
@@ -34,8 +34,12 @@ module Approvals
34
34
  @writer ||= Writer.for(@format)
35
35
  end
36
36
 
37
+ def verifier
38
+ @verifier ||= Verifier.for(@format)
39
+ end
40
+
37
41
  def verify
38
- unless File.exists?(namer.output_dir)
42
+ unless File.exist?(namer.output_dir)
39
43
  FileUtils.mkdir_p(namer.output_dir)
40
44
  end
41
45
 
@@ -57,16 +61,20 @@ module Approvals
57
61
  end
58
62
 
59
63
  def approved?
60
- File.exists? approved_path
64
+ File.exist? approved_path
61
65
  end
62
66
 
63
67
  BINARY_FORMATS = [:binary]
64
-
68
+
65
69
  def received_matches?
70
+ return verifier
71
+ .new(received_path, approved_path)
72
+ .verify if verifier
73
+
66
74
  if BINARY_FORMATS.include?(@format) # Read without ERB
67
75
  IO.read(received_path).chomp == IO.read(approved_path).chomp
68
76
  else
69
- IO.read(received_path).chomp == ERB.new(IO.read(approved_path).chomp).result
77
+ ERB.new(IO.read(received_path).chomp).result == ERB.new(IO.read(approved_path).chomp).result
70
78
  end
71
79
  end
72
80
 
data/lib/approvals/cli.rb CHANGED
@@ -11,12 +11,17 @@ module Approvals
11
11
 
12
12
  rejected = []
13
13
  approvals.each do |approval|
14
- diff_command = "#{options[:diff]} #{approval}"
14
+ approved, received = approval.split(/\s+/)
15
+ if received.include?(".approved.")
16
+ received, approved = approved, received
17
+ end
18
+
19
+ diff_command = "#{options[:diff]} #{approved} #{received}"
15
20
  puts diff_command
16
21
  system(diff_command)
17
22
 
18
23
  if options[:ask] && yes?("Approve? [y/N] ")
19
- system("mv #{approval}")
24
+ system("mv #{received} #{approved}")
20
25
  else
21
26
  rejected << approval
22
27
  end
@@ -4,7 +4,7 @@ module Approvals
4
4
  class << self
5
5
 
6
6
  def reset
7
- File.truncate(path, 0) if File.exists?(path)
7
+ File.truncate(path, 0) if File.exist?(path)
8
8
  end
9
9
 
10
10
  def append(text)
@@ -16,18 +16,18 @@ module Approvals
16
16
  end
17
17
 
18
18
  def censored value, key=nil
19
- case value
20
- when Array
21
- value.map { |item| censored(item) }
22
- when Hash
23
- Hash[value.map { |key, value| [key, censored(value, key)] }]
19
+ if value.nil?
20
+ nil
21
+ elsif key && placeholder_for(key)
22
+ "<#{placeholder_for(key)}>"
24
23
  else
25
- if value.nil?
26
- nil
27
- elsif key && placeholder_for(key)
28
- "<#{placeholder_for(key)}>"
29
- else
30
- value
24
+ case value
25
+ when Array
26
+ value.map { |item| censored(item) }
27
+ when Hash
28
+ Hash[value.map { |inner_key, inner_value| [inner_key, censored(inner_value, inner_key)] }]
29
+ else
30
+ value
31
31
  end
32
32
  end
33
33
  end
@@ -1,17 +1,13 @@
1
1
  module Approvals
2
2
  module Namers
3
3
  class DirectoryNamer < RSpecNamer
4
+ private
4
5
 
5
- def initialize(example)
6
- @name = directorize example
6
+ def name_for_example(example)
7
+ directorize example
7
8
  end
8
9
 
9
- private
10
-
11
10
  def directorize(example)
12
- parts = [ ]
13
- metadata = example.metadata
14
-
15
11
  approvals_path = lambda do |metadata|
16
12
  description = normalize metadata[:description]
17
13
  example_group = if metadata.key?(:example_group)
@@ -1,10 +1,15 @@
1
1
  module Approvals
2
2
  module Namers
3
3
  class RSpecNamer
4
-
5
4
  attr_reader :name
5
+
6
6
  def initialize(example)
7
- @name = normalize example.full_description
7
+ @name = name_for_example(example)
8
+ @output_dir = nil
9
+ end
10
+
11
+ def name_for_example(example)
12
+ normalize example.full_description
8
13
  end
9
14
 
10
15
  def normalize(string)
@@ -15,7 +20,7 @@ module Approvals
15
20
  unless @output_dir
16
21
  begin
17
22
  @output_dir = ::RSpec.configuration.approvals_path
18
- rescue NoMethodError => e
23
+ rescue NoMethodError
19
24
  end
20
25
  @output_dir ||= 'spec/fixtures/approvals/'
21
26
  end
@@ -0,0 +1,15 @@
1
+ require 'approvals/verifiers/json_verifier'
2
+
3
+ module Approvals
4
+ module Verifier
5
+ REGISTRY = {
6
+ json: Verifiers::JsonVerifier,
7
+ }
8
+
9
+ class << self
10
+ def for(format)
11
+ REGISTRY[format]
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,26 @@
1
+ module Approvals
2
+ module Verifiers
3
+ class JsonVerifier
4
+ def initialize(received_path, approved_path)
5
+ self.received_path = received_path
6
+ self.approved_path = approved_path
7
+ end
8
+
9
+ def verify
10
+ approved == received
11
+ end
12
+
13
+ private
14
+
15
+ attr_accessor :approved_path, :received_path
16
+
17
+ def approved
18
+ JSON.parse(File.read(approved_path))
19
+ end
20
+
21
+ def received
22
+ JSON.parse(File.read(received_path))
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,3 +1,3 @@
1
1
  module Approvals
2
- VERSION = '0.0.19'
2
+ VERSION = '0.0.25'
3
3
  end
@@ -16,15 +16,21 @@ module Approvals
16
16
  html: Writers::HtmlWriter.new,
17
17
  hash: Writers::HashWriter.new,
18
18
  array: Writers::ArrayWriter.new,
19
+ txt: Writers::TextWriter.new,
19
20
  }
20
21
 
21
22
 
22
23
  class << self
23
24
  def for(format)
24
- if REGISTRY.include?(format)
25
- REGISTRY[format]
26
- else
27
- TextWriter.new
25
+ begin
26
+ REGISTRY[format] || Object.const_get(format).new
27
+ rescue NameError => e
28
+ error = ApprovalError.new(
29
+ "Approval Error: #{ e }. Please define a custom writer as outlined"\
30
+ " in README section 'Customizing formatted output': "\
31
+ "https://github.com/kytrinyx/approvals#customizing-formatted-output"
32
+ )
33
+ raise error
28
34
  end
29
35
  end
30
36
  end
@@ -6,19 +6,13 @@ module Approvals
6
6
  end
7
7
 
8
8
  def initialize(opts = {})
9
- self.autoregister = opts[:autoregister] || true
10
- self.detect = opts[:detect]
11
- self.extension = opts[:extension] || ''
12
- self.write = opts[:write] || EXCEPTION_WRITER
9
+ @autoregister = opts[:autoregister] || true
10
+ @detect = opts[:detect]
11
+ @extension = opts[:extension] || ''
12
+ @write = opts[:write] || EXCEPTION_WRITER
13
13
  self.format = opts[:format] || :binary
14
14
  end
15
15
 
16
- attr_accessor :autoregister
17
- attr_accessor :extension
18
- attr_accessor :write
19
- attr_accessor :detect
20
-
21
-
22
16
  attr_reader :format
23
17
 
24
18
  def format=(sym)
@@ -51,6 +51,32 @@ describe Approvals do
51
51
  Approvals.verify hello, :namer => namer
52
52
  end
53
53
 
54
+ context "custom writer" do
55
+ let(:hello) { Object.new }
56
+
57
+ class MyCustomWriter < Approvals::Writers::TextWriter
58
+ def format(data)
59
+ filter(data)
60
+ end
61
+
62
+ def filter(data)
63
+ data.to_s.chars.reject {|c| c =~ /[a-zA-Z0-9]/}
64
+ end
65
+ end
66
+
67
+ it "verifies a complex object" do
68
+ Approvals.verify hello, :namer => namer, :format => "MyCustomWriter"
69
+ end
70
+
71
+ it "raises an error with an uninitialized custom writer class" do
72
+ expect{
73
+ Approvals.verify hello, :namer => namer, :format => "UninitializedWriter"
74
+ }.to raise_error.with_message(
75
+ /Please define a custom writer as outlined in README section 'Customizing formatted output':/
76
+ )
77
+ end
78
+ end
79
+
54
80
  it "verifies html" do
55
81
  html = <<-HTML
56
82
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd"><html><head><title>Approval</title></head><body><h1>An Approval</h1><p>It has a paragraph</p></body></html>
@@ -79,6 +105,11 @@ describe Approvals do
79
105
  Approvals.verify json, :format => :json, :namer => namer
80
106
  end
81
107
 
108
+ it "ignores whitespace differences in json" do
109
+ hash = { foo: {} }
110
+
111
+ Approvals.verify hash, :format => :json, :namer => namer
112
+ end
82
113
 
83
114
  it "verifies json and is newline agnostic" do
84
115
  json = '{"pet":{"species":"turtle","color":"green","name":"Anthony"}}'
@@ -108,6 +139,13 @@ describe Approvals do
108
139
  Approvals.verify string, :namer => namer
109
140
  end
110
141
 
142
+ # Bugfix: If only the approved file gets passed through ERB,
143
+ # then <% (received) is not equal to <% (approved).
144
+ it "passes the received files through ERB" do
145
+ string = "<%"
146
+ Approvals.verify string, :namer => namer
147
+ end
148
+
111
149
  describe "supports excluded keys option" do
112
150
  let(:hash) { {:object => {:id => rand(100), :created_at => Time.now, :name => 'test', deleted_at: nil}} }
113
151
 
data/spec/filter_spec.rb CHANGED
@@ -74,6 +74,40 @@ describe Approvals::Filter do
74
74
  })
75
75
  end
76
76
 
77
+ it "filters array keys" do
78
+ filter = Approvals::Filter.new({foolist: /^foolist$/})
79
+ input = {
80
+ foo: 'bar124',
81
+ foolist: [{foo: 'bar 145', bar: 'foo'}, 'foobar'],
82
+ nonfoo: 'bar',
83
+ }
84
+
85
+ output = filter.apply(input)
86
+
87
+ expect(output).to eq({
88
+ foo: 'bar124',
89
+ foolist: '<foolist>',
90
+ nonfoo: 'bar',
91
+ })
92
+ end
93
+
94
+ it "filters hash keys" do
95
+ filter = Approvals::Filter.new({foohash: /^foohash$/})
96
+ input = {
97
+ foo: 'bar124',
98
+ foohash: {foo: 'bar 145', barlist: ['foo', 'bar']},
99
+ nonfoo: 'bar',
100
+ }
101
+
102
+ output = filter.apply(input)
103
+
104
+ expect(output).to eq({
105
+ foo: 'bar124',
106
+ foohash: '<foohash>',
107
+ nonfoo: 'bar',
108
+ })
109
+ end
110
+
77
111
  it "takes the last applicable filter" do
78
112
  filter = Approvals::Filter.new({foo: /^foo/, bar: /bar$/})
79
113
  input = {
@@ -0,0 +1,3 @@
1
+ {
2
+ "foo": "2017-01-01 00:00:00 +0100"
3
+ }
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe Approvals::Verifiers::JsonVerifier do
4
+ subject(:instance) do
5
+ described_class.new(received_path, approved_path)
6
+ end
7
+
8
+ context "with same json content but different formatting" do
9
+ let(:received_path) do
10
+ "./spec/fixtures/json_approval_with_different_whitespace/received.json"
11
+ end
12
+ let(:approved_path) do
13
+ "./spec/fixtures/json_approval_with_different_whitespace/approved.json"
14
+ end
15
+
16
+ it "passes verification" do
17
+ expect(instance.verify).to be_truthy
18
+ end
19
+ end
20
+
21
+ context "with different json content" do
22
+ let(:received_path) do
23
+ "./spec/fixtures/json_approval_with_different_whitespace/received_different_content.json"
24
+ end
25
+ let(:approved_path) do
26
+ "./spec/fixtures/json_approval_with_different_whitespace/approved.json"
27
+ end
28
+
29
+ it "does not passe verification" do
30
+ expect(instance.verify).to be_falsy
31
+ end
32
+ end
33
+ end
metadata CHANGED
@@ -1,37 +1,37 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: approvals
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.19
4
+ version: 0.0.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - Katrina Owen
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-20 00:00:00.000000000 Z
11
+ date: 2021-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rspec
14
+ name: thor
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '3.1'
20
- type: :development
19
+ version: '1.0'
20
+ type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '3.1'
26
+ version: '1.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: json
28
+ name: nokogiri
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.8'
34
- type: :development
34
+ type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
@@ -39,39 +39,40 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.8'
41
41
  - !ruby/object:Gem::Dependency
42
- name: thor
42
+ name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0.18'
48
- type: :runtime
47
+ version: '13.0'
48
+ type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0.18'
54
+ version: '13.0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: nokogiri
56
+ name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '1.6'
62
- type: :runtime
61
+ version: '3.1'
62
+ type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '1.6'
69
- description: Approval Tests for Ruby
68
+ version: '3.1'
69
+ description: A library to make it easier to do golden-master style testing in Ruby
70
70
  email:
71
71
  - katrina.owen@gmail.com
72
72
  executables:
73
73
  - approvals
74
- extensions: []
74
+ extensions:
75
+ - ext/mkrf_conf.rb
75
76
  extra_rdoc_files: []
76
77
  files:
77
78
  - ".gitignore"
@@ -83,6 +84,7 @@ files:
83
84
  - Rakefile
84
85
  - approvals.gemspec
85
86
  - bin/approvals
87
+ - ext/mkrf_conf.rb
86
88
  - lib/approvals.rb
87
89
  - lib/approvals/approval.rb
88
90
  - lib/approvals/cli.rb
@@ -112,6 +114,8 @@ files:
112
114
  - lib/approvals/rspec.rb
113
115
  - lib/approvals/scrubber.rb
114
116
  - lib/approvals/system_command.rb
117
+ - lib/approvals/verifier.rb
118
+ - lib/approvals/verifiers/json_verifier.rb
115
119
  - lib/approvals/version.rb
116
120
  - lib/approvals/writer.rb
117
121
  - lib/approvals/writers/array_writer.rb
@@ -127,7 +131,10 @@ files:
127
131
  - spec/executable_spec.rb
128
132
  - spec/extensions/rspec_approvals_spec.rb
129
133
  - spec/filter_spec.rb
134
+ - spec/fixtures/approvals/approvals_custom_writer_verifies_a_complex_object.approved.txt
135
+ - spec/fixtures/approvals/approvals_ignores_whitespace_differences_in_json.approved.json
130
136
  - spec/fixtures/approvals/approvals_passes_approved_files_through_erb.approved.txt
137
+ - spec/fixtures/approvals/approvals_passes_the_received_files_through_erb.approved.txt
131
138
  - spec/fixtures/approvals/approvals_supports_excluded_keys_option_also_supports_an_array_of_hashes.approved.json
132
139
  - spec/fixtures/approvals/approvals_supports_excluded_keys_option_supports_the_array_writer.approved.txt
133
140
  - spec/fixtures/approvals/approvals_supports_excluded_keys_option_supports_the_hash_writer.approved.txt
@@ -142,6 +149,7 @@ files:
142
149
  - spec/fixtures/approvals/approvals_verifies_html.approved.html
143
150
  - spec/fixtures/approvals/approvals_verifies_json.approved.json
144
151
  - spec/fixtures/approvals/approvals_verifies_json_and_is_newline_agnostic.approved.json
152
+ - spec/fixtures/approvals/approvals_verifies_json_with_a_time_object.approved.json
145
153
  - spec/fixtures/approvals/approvals_verifies_xml.approved.xml
146
154
  - spec/fixtures/approvals/verifications_a_string.approved.txt
147
155
  - spec/fixtures/approvals/verifies_a_complex_object.approved.txt
@@ -162,6 +170,9 @@ files:
162
170
  - spec/fixtures/approvals/verifies_html.approved.html
163
171
  - spec/fixtures/approvals/verifies_json.approved.json
164
172
  - spec/fixtures/approvals/verifies_xml.approved.xml
173
+ - spec/fixtures/json_approval_with_different_whitespace/approved.json
174
+ - spec/fixtures/json_approval_with_different_whitespace/received.json
175
+ - spec/fixtures/json_approval_with_different_whitespace/received_different_content.json
165
176
  - spec/fixtures/one.png
166
177
  - spec/fixtures/one.txt
167
178
  - spec/fixtures/two.png
@@ -179,11 +190,12 @@ files:
179
190
  - spec/scrubber_spec.rb
180
191
  - spec/spec_helper.rb
181
192
  - spec/system_command_spec.rb
182
- homepage: ''
193
+ - spec/verifiers/json_verifier_spec.rb
194
+ homepage: https://github.com/kytrinyx/approvals
183
195
  licenses:
184
196
  - MIT
185
197
  metadata: {}
186
- post_install_message:
198
+ post_install_message:
187
199
  rdoc_options: []
188
200
  require_paths:
189
201
  - lib
@@ -198,10 +210,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
198
210
  - !ruby/object:Gem::Version
199
211
  version: '0'
200
212
  requirements: []
201
- rubyforge_project: approvals
202
- rubygems_version: 2.2.2
203
- signing_key:
213
+ rubygems_version: 3.0.3
214
+ signing_key:
204
215
  specification_version: 4
205
216
  summary: Approval Tests for Ruby
206
217
  test_files: []
207
- has_rdoc: