simple_approvals-rspec 1.1.0 → 3.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 +5 -5
 - data/lib/simple_approvals/rspec/approvals.rb +22 -14
 - data/lib/simple_approvals/rspec/matchers.rb +0 -2
 - data/lib/simple_approvals/rspec.rb +0 -2
 - metadata +8 -9
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 2 
     | 
    
         
            +
            SHA256:
         
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: f71df43a87b07fe15b71e6cc0c24c3482c2aff226ff36714be8a988d919edfd2
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 3cfe824a91b39e426f1e101616a558c787f4104e24e8117b1707112e5f1a923c
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 25605c30b71b93bab1ededdc8ade9f8fbfefaa64c513eee4d0972792687fb399fe68cbb3287f76602bbe6b8146ac84af08be0fc11f2cd02828d87ac18a069359
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 817c7d0811dfeea3e111ed9d99dd45149bb41ba72305666dff71c26d05d31c3f0a7e52f8d3eaa5cede99154b670b470ea44d12670bc36daca903e1678b24689d
         
     | 
| 
         @@ -1,5 +1,3 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            # frozen_string_literal: true
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
1 
     | 
    
         
             
            # Top-level class to provide approval test support (inspired by http://approvaltests.com/)
         
     | 
| 
       4 
2 
     | 
    
         
             
            class Approvals
         
     | 
| 
       5 
3 
     | 
    
         
             
              class << self
         
     | 
| 
         @@ -7,33 +5,33 @@ class Approvals 
     | 
|
| 
       7 
5 
     | 
    
         
             
                  scrubbed_content = apply_optional_scrubber(rendered_content, options)
         
     | 
| 
       8 
6 
     | 
    
         
             
                  pre_approve_if_asked(approved_path, scrubbed_content, options)
         
     | 
| 
       9 
7 
     | 
    
         | 
| 
       10 
     | 
    
         
            -
                  expected_content = load_expected_content(approved_path,  
     | 
| 
      
 8 
     | 
    
         
            +
                  expected_content = load_expected_content(approved_path, options)
         
     | 
| 
       11 
9 
     | 
    
         
             
                  received_path = received_path_for approved_path
         
     | 
| 
       12 
10 
     | 
    
         | 
| 
       13 
11 
     | 
    
         
             
                  if scrubbed_content.strip.empty?
         
     | 
| 
       14 
     | 
    
         
            -
                    raise_verify_error_with_diff(approved_path, received_path, scrubbed_content,  
     | 
| 
      
 12 
     | 
    
         
            +
                    raise_verify_error_with_diff(approved_path, received_path, scrubbed_content, options) unless options[:allow_empty]
         
     | 
| 
       15 
13 
     | 
    
         
             
                  elsif scrubbed_content.strip == expected_content.strip
         
     | 
| 
       16 
     | 
    
         
            -
                    handle_match(received_path, scrubbed_content,  
     | 
| 
      
 14 
     | 
    
         
            +
                    handle_match(received_path, scrubbed_content, options)
         
     | 
| 
       17 
15 
     | 
    
         
             
                  else
         
     | 
| 
       18 
     | 
    
         
            -
                    raise_verify_error_with_diff(approved_path, received_path, scrubbed_content,  
     | 
| 
      
 16 
     | 
    
         
            +
                    raise_verify_error_with_diff(approved_path, received_path, scrubbed_content, options)
         
     | 
| 
       19 
17 
     | 
    
         
             
                  end
         
     | 
| 
       20 
18 
     | 
    
         
             
                end
         
     | 
| 
       21 
19 
     | 
    
         | 
| 
       22 
20 
     | 
    
         
             
                private
         
     | 
| 
       23 
21 
     | 
    
         | 
| 
       24 
     | 
    
         
            -
                def apply_optional_scrubber(content,  
     | 
| 
       25 
     | 
    
         
            -
                  if options. 
     | 
| 
      
 22 
     | 
    
         
            +
                def apply_optional_scrubber(content, options)
         
     | 
| 
      
 23 
     | 
    
         
            +
                  if options.has_key?(:scrubber) && options[:scrubber]
         
     | 
| 
       26 
24 
     | 
    
         
             
                    options[:scrubber].call(content)
         
     | 
| 
       27 
25 
     | 
    
         
             
                  else
         
     | 
| 
       28 
26 
     | 
    
         
             
                    content
         
     | 
| 
       29 
27 
     | 
    
         
             
                  end
         
     | 
| 
       30 
28 
     | 
    
         
             
                end
         
     | 
| 
       31 
29 
     | 
    
         | 
| 
       32 
     | 
    
         
            -
                def pre_approve_if_asked(approved_path, scrubbed_content,  
     | 
| 
      
 30 
     | 
    
         
            +
                def pre_approve_if_asked(approved_path, scrubbed_content, options)
         
     | 
| 
       33 
31 
     | 
    
         
             
                  File.write(approved_path, scrubbed_content) if options[:approve_all] || options[:accept_all] || ENV['APPROVE_ALL']
         
     | 
| 
       34 
32 
     | 
    
         
             
                end
         
     | 
| 
       35 
33 
     | 
    
         | 
| 
       36 
     | 
    
         
            -
                def handle_match(received_path, received_content,  
     | 
| 
      
 34 
     | 
    
         
            +
                def handle_match(received_path, received_content, options)
         
     | 
| 
       37 
35 
     | 
    
         
             
                  if options[:keep_received_file] == true
         
     | 
| 
       38 
36 
     | 
    
         
             
                    File.write(received_path, received_content)
         
     | 
| 
       39 
37 
     | 
    
         
             
                  elsif File.file?(received_path)
         
     | 
| 
         @@ -45,7 +43,7 @@ class Approvals 
     | 
|
| 
       45 
43 
     | 
    
         
             
                  "#{approved_path}.received"
         
     | 
| 
       46 
44 
     | 
    
         
             
                end
         
     | 
| 
       47 
45 
     | 
    
         | 
| 
       48 
     | 
    
         
            -
                def load_expected_content(approved_path,  
     | 
| 
      
 46 
     | 
    
         
            +
                def load_expected_content(approved_path, options)
         
     | 
| 
       49 
47 
     | 
    
         
             
                  if File.file? approved_path
         
     | 
| 
       50 
48 
     | 
    
         
             
                    File.read(approved_path)
         
     | 
| 
       51 
49 
     | 
    
         
             
                  else
         
     | 
| 
         @@ -54,7 +52,7 @@ class Approvals 
     | 
|
| 
       54 
52 
     | 
    
         
             
                  end
         
     | 
| 
       55 
53 
     | 
    
         
             
                end
         
     | 
| 
       56 
54 
     | 
    
         | 
| 
       57 
     | 
    
         
            -
                def raise_verify_error_with_diff(approved_path, received_path, received_content,  
     | 
| 
      
 55 
     | 
    
         
            +
                def raise_verify_error_with_diff(approved_path, received_path, received_content, options)
         
     | 
| 
       58 
56 
     | 
    
         
             
                  File.write(received_path, received_content)
         
     | 
| 
       59 
57 
     | 
    
         | 
| 
       60 
58 
     | 
    
         
             
                  # and generate a diff for the console
         
     | 
| 
         @@ -63,8 +61,18 @@ class Approvals 
     | 
|
| 
       63 
61 
     | 
    
         
             
                  message << %(- writing received content to: "#{received_path}")
         
     | 
| 
       64 
62 
     | 
    
         
             
                  message << "\n"
         
     | 
| 
       65 
63 
     | 
    
         | 
| 
       66 
     | 
    
         
            -
                  expected_content = load_expected_content(approved_path)
         
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
      
 64 
     | 
    
         
            +
                  expected_content = load_expected_content(approved_path, options)
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
                  if !expected_content.include?("\n") || !received_content.include?("\n")
         
     | 
| 
      
 67 
     | 
    
         
            +
                    # work around a bug in rspec-support 3.12.0's differ
         
     | 
| 
      
 68 
     | 
    
         
            +
                    # where it shows nothing when both strings are single line
         
     | 
| 
      
 69 
     | 
    
         
            +
                    # https://github.com/rspec/rspec-support/blob/v3.12.0/lib/rspec/support/differ.rb#L16-L18
         
     | 
| 
      
 70 
     | 
    
         
            +
                    message << "expected: #{expected_content.inspect}\n"
         
     | 
| 
      
 71 
     | 
    
         
            +
                    message << "received: #{received_content.inspect}\n"
         
     | 
| 
      
 72 
     | 
    
         
            +
                    ::RSpec::Expectations.fail_with message
         
     | 
| 
      
 73 
     | 
    
         
            +
                  else
         
     | 
| 
      
 74 
     | 
    
         
            +
                    ::RSpec::Expectations.fail_with message, expected_content, received_content
         
     | 
| 
      
 75 
     | 
    
         
            +
                  end
         
     | 
| 
       68 
76 
     | 
    
         
             
                end
         
     | 
| 
       69 
77 
     | 
    
         
             
              end
         
     | 
| 
       70 
78 
     | 
    
         
             
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: simple_approvals-rspec
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version:  
     | 
| 
      
 4 
     | 
    
         
            +
              version: 3.1.2
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - David Alpert
         
     | 
| 
       8 
     | 
    
         
            -
            autorequire: 
     | 
| 
      
 8 
     | 
    
         
            +
            autorequire:
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date:  
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2023-06-02 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: bundler
         
     | 
| 
         @@ -122,24 +122,23 @@ files: 
     | 
|
| 
       122 
122 
     | 
    
         
             
            homepage: https://github.com/davidalpert/simple_approvals-rspec/
         
     | 
| 
       123 
123 
     | 
    
         
             
            licenses: []
         
     | 
| 
       124 
124 
     | 
    
         
             
            metadata: {}
         
     | 
| 
       125 
     | 
    
         
            -
            post_install_message: 
     | 
| 
      
 125 
     | 
    
         
            +
            post_install_message:
         
     | 
| 
       126 
126 
     | 
    
         
             
            rdoc_options: []
         
     | 
| 
       127 
127 
     | 
    
         
             
            require_paths:
         
     | 
| 
       128 
128 
     | 
    
         
             
            - lib
         
     | 
| 
       129 
129 
     | 
    
         
             
            required_ruby_version: !ruby/object:Gem::Requirement
         
     | 
| 
       130 
130 
     | 
    
         
             
              requirements:
         
     | 
| 
       131 
     | 
    
         
            -
              - - " 
     | 
| 
      
 131 
     | 
    
         
            +
              - - "~>"
         
     | 
| 
       132 
132 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       133 
     | 
    
         
            -
                  version:  
     | 
| 
      
 133 
     | 
    
         
            +
                  version: 3.1.0
         
     | 
| 
       134 
134 
     | 
    
         
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
       135 
135 
     | 
    
         
             
              requirements:
         
     | 
| 
       136 
136 
     | 
    
         
             
              - - ">="
         
     | 
| 
       137 
137 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       138 
138 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       139 
139 
     | 
    
         
             
            requirements: []
         
     | 
| 
       140 
     | 
    
         
            -
             
     | 
| 
       141 
     | 
    
         
            -
             
     | 
| 
       142 
     | 
    
         
            -
            signing_key: 
         
     | 
| 
      
 140 
     | 
    
         
            +
            rubygems_version: 3.3.7
         
     | 
| 
      
 141 
     | 
    
         
            +
            signing_key:
         
     | 
| 
       143 
142 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       144 
143 
     | 
    
         
             
            summary: ''
         
     | 
| 
       145 
144 
     | 
    
         
             
            test_files: []
         
     |