simple_approvals-rspec 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/simple_approvals/rspec.rb +2 -0
- data/lib/simple_approvals/rspec/approvals.rb +68 -0
- data/lib/simple_approvals/rspec/matchers.rb +9 -0
- metadata +4 -7
- data/.editorconfig +0 -15
- data/.gitignore +0 -29
- data/.rubocop.yml +0 -33
- data/Gemfile +0 -2
- data/VERSION +0 -1
- data/rakefile.rb +0 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 814f75f6418ca6f93bcb761ef3e3ad6589c5584a
|
4
|
+
data.tar.gz: a7d45f22b4751d8afd90ace0623d0cb897282c59
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf1e5b00dd26c840d45d495ce0da9bffbda755c5ad3ab5798fde864a4dbf1482014bf7350852237a95f594ee1073d7019a29206fc45de03d5534f464cc5661ce
|
7
|
+
data.tar.gz: da4e6c6e613f3501382dc853f121e84771118ba7f0ec74cfd84c9c4fc27d9776155023bcc532e7401fa790b197e5703ba29a9eb6a4b11cc7a920a2814bf7179c
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# Top-level class to provide approval test support (inspired by http://approvaltests.com/)
|
2
|
+
class Approvals
|
3
|
+
class << self
|
4
|
+
def verify(rendered_content, approved_path, **options)
|
5
|
+
scrubbed_content = apply_optional_scrubber(rendered_content, options)
|
6
|
+
pre_approve_if_asked(approved_path, scrubbed_content, options)
|
7
|
+
|
8
|
+
expected_content = load_expected_content(approved_path, **options)
|
9
|
+
received_path = received_path_for approved_path
|
10
|
+
|
11
|
+
if scrubbed_content.strip.empty?
|
12
|
+
raise_verify_error_with_diff(approved_path, received_path, scrubbed_content, **options) unless options[:allow_empty]
|
13
|
+
elsif scrubbed_content.strip == expected_content.strip
|
14
|
+
handle_match(received_path, scrubbed_content, **options)
|
15
|
+
else
|
16
|
+
raise_verify_error_with_diff(approved_path, received_path, scrubbed_content, **options)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def apply_optional_scrubber(content, **options)
|
23
|
+
if options.key?(:scrubber) && options[:scrubber]
|
24
|
+
options[:scrubber].call(content)
|
25
|
+
else
|
26
|
+
content
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def pre_approve_if_asked(approved_path, scrubbed_content, **options)
|
31
|
+
File.write(approved_path, scrubbed_content) if options[:approve_all] || options[:accept_all]
|
32
|
+
end
|
33
|
+
|
34
|
+
def handle_match(received_path, received_content, **options)
|
35
|
+
if options[:keep_received_file] == true
|
36
|
+
File.write(received_path, received_content)
|
37
|
+
elsif File.file?(received_path)
|
38
|
+
File.delete received_path
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def received_path_for(approved_path)
|
43
|
+
"#{approved_path}.received"
|
44
|
+
end
|
45
|
+
|
46
|
+
def load_expected_content(approved_path, **options)
|
47
|
+
if File.file? approved_path
|
48
|
+
File.read(approved_path)
|
49
|
+
else
|
50
|
+
File.open(approved_path, 'w') { |f| f.write('') } if options[:create_if_missing]
|
51
|
+
''
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def raise_verify_error_with_diff(approved_path, received_path, received_content, **options)
|
56
|
+
File.write(received_path, received_content)
|
57
|
+
|
58
|
+
# and generate a diff for the console
|
59
|
+
message = options[:message_override] || %(Approval failed to match "#{approved_path}")
|
60
|
+
message << "\n"
|
61
|
+
message << %(- writing received content to: "#{received_path}")
|
62
|
+
message << "\n"
|
63
|
+
|
64
|
+
expected_content = load_expected_content(approved_path)
|
65
|
+
::RSpec::Expectations.fail_with message, expected_content, received_content
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_approvals-rspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Alpert
|
@@ -115,13 +115,10 @@ executables: []
|
|
115
115
|
extensions: []
|
116
116
|
extra_rdoc_files: []
|
117
117
|
files:
|
118
|
-
- ".editorconfig"
|
119
|
-
- ".gitignore"
|
120
|
-
- ".rubocop.yml"
|
121
|
-
- Gemfile
|
122
118
|
- README.md
|
123
|
-
-
|
124
|
-
-
|
119
|
+
- lib/simple_approvals/rspec.rb
|
120
|
+
- lib/simple_approvals/rspec/approvals.rb
|
121
|
+
- lib/simple_approvals/rspec/matchers.rb
|
125
122
|
homepage: https://github.com/davidalpert/simple_approvals-rspec/
|
126
123
|
licenses: []
|
127
124
|
metadata: {}
|
data/.editorconfig
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
# top-most EditorConfig file
|
2
|
-
root = true
|
3
|
-
|
4
|
-
# Unix-style newlines with a newline ending every file
|
5
|
-
[*]
|
6
|
-
end_of_line = lf
|
7
|
-
insert_final_newline = true
|
8
|
-
|
9
|
-
[*.rb]
|
10
|
-
indent_style = space
|
11
|
-
indent_size = 2
|
12
|
-
|
13
|
-
[*.json]
|
14
|
-
indent_style = space
|
15
|
-
indent_size = 2
|
data/.gitignore
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
*.gem
|
2
|
-
*.rbc
|
3
|
-
.bundle
|
4
|
-
.config
|
5
|
-
.yardoc
|
6
|
-
InstalledFiles
|
7
|
-
_yardoc
|
8
|
-
coverage
|
9
|
-
doc/
|
10
|
-
lib/bundler/man
|
11
|
-
pkg
|
12
|
-
rdoc
|
13
|
-
spec/reports
|
14
|
-
test/tmp
|
15
|
-
test/version_tmp
|
16
|
-
tmp
|
17
|
-
.idea/*
|
18
|
-
*.swp
|
19
|
-
*Gemfile.lock
|
20
|
-
.DS_Store
|
21
|
-
.gradle/
|
22
|
-
archive*
|
23
|
-
build/*
|
24
|
-
*.pyc
|
25
|
-
node_modules/
|
26
|
-
rubocop.html
|
27
|
-
tags
|
28
|
-
.fingerprint
|
29
|
-
LOGFILE_*
|
data/.rubocop.yml
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
AllCops:
|
3
|
-
Exclude:
|
4
|
-
- 'vendor/**/*'
|
5
|
-
- 'spec/fixtures/**/*'
|
6
|
-
- 'spec/spec_helper.rb'
|
7
|
-
- 'rakefile.rb'
|
8
|
-
# - 'simple_approvals.gemspec'
|
9
|
-
# - 'Gemfile'
|
10
|
-
# - 'example/rakefile.rb'
|
11
|
-
# - 'example/Gemfile'
|
12
|
-
# - 'example/**/*'
|
13
|
-
# - 'spec/**/*'
|
14
|
-
Style/Encoding:
|
15
|
-
Enabled: true
|
16
|
-
|
17
|
-
SignalException:
|
18
|
-
EnforcedStyle: only_raise
|
19
|
-
|
20
|
-
CaseIndentation:
|
21
|
-
EnforcedStyle: end
|
22
|
-
|
23
|
-
Metrics/ClassLength:
|
24
|
-
Enabled: false
|
25
|
-
|
26
|
-
Metrics/MethodLength:
|
27
|
-
Enabled: false
|
28
|
-
|
29
|
-
Metrics/LineLength:
|
30
|
-
Enabled: false
|
31
|
-
|
32
|
-
Metrics/ParameterLists:
|
33
|
-
Max: 6
|
data/Gemfile
DELETED
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
1.0.1
|
data/rakefile.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
$: << './'
|
3
|
-
|
4
|
-
require 'rubygems'
|
5
|
-
require 'bundler/setup'
|
6
|
-
|
7
|
-
require 'version_bumper'
|
8
|
-
require 'bundler'
|
9
|
-
require 'bundler/gem_helper'
|
10
|
-
require 'geminabox_client'
|
11
|
-
|
12
|
-
module SimpleApprovals
|
13
|
-
# Helper for setting version
|
14
|
-
module RSpec
|
15
|
-
# Helper for setting version
|
16
|
-
class GemHelper < Bundler::GemHelper
|
17
|
-
def reload_version
|
18
|
-
@gemspec.version = SimpleApprovals::RSpec.gem_version
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
# The current version of the gem
|
23
|
-
def self.gem_version
|
24
|
-
File.read('VERSION').strip
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|