rspec_snapshot_matcher 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9dd8baeccde6842990b6f4d3674d04ed06f148f7
4
+ data.tar.gz: 59b5d4c87b1c79823b000242bcbed57a6c167233
5
+ SHA512:
6
+ metadata.gz: db1cd82d6542d153fd5ea34b81ee49610ff2b44394c84c90d6341c81666770723ffecf80cb54cd8cb99de2d3da1f6d558c3a6b4d049fd5ef939166f2fede7d4d
7
+ data.tar.gz: 2383e45372c766eeb6a3336291ef71106dac0a0b91e4536984db693652c23c26dfa3c55775b7e2ba61d2794c0ab4385e3c6fdbe6ad23e6ebe28fc8d24f3bc6a8
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ /spec/fixtures/snapshots
12
+
13
+ *.swp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,20 @@
1
+ Metrics/LineLength:
2
+ Max: 100
3
+
4
+ Documentation:
5
+ Enabled: false
6
+
7
+ Style/BlockLength:
8
+ Exclude:
9
+ - 'Rakefile'
10
+ - '**/*.rake'
11
+ - 'spec/**/*.rb'
12
+
13
+ Style/BlockDelimiters:
14
+ EnforcedStyle: semantic
15
+ FunctionalMethods:
16
+ - before
17
+ - let
18
+ - let!
19
+ - subject
20
+ - expect
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.0
5
+ before_install: gem install bundler -v 1.12.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rspec-snapshot-matcher.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Patrick Caldwell
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,41 @@
1
+ # Rspec::Snapshot::Matcher
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rspec/snapshot/matcher`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'rspec-snapshot-matcher'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install rspec-snapshot-matcher
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rspec-snapshot-matcher.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'rspec_snapshot_matcher'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require 'pry'
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,2 @@
1
+ require 'rspec_snapshot_matcher/version'
2
+ require 'rspec_snapshot_matcher/matchers'
@@ -0,0 +1,12 @@
1
+ require 'rspec'
2
+ require 'rspec_snapshot_matcher/matchers/snapshot_matcher.rb'
3
+
4
+ RSpec.configure do |config|
5
+ config.include(RSpecSnapshotMatcher::Matchers)
6
+
7
+ config.around(:all) do |example|
8
+ Thread.current[:rspec_snapshot_matcher_example] = example
9
+ example.run
10
+ Thread.current[:rspec_snapshot_matcher_example] = nil
11
+ end
12
+ end
@@ -0,0 +1,87 @@
1
+ require 'yaml'
2
+
3
+ module RSpecSnapshotMatcher
4
+ module Matchers
5
+ class MatchSnapshot
6
+ attr_reader :actual, :expected
7
+
8
+ def matches?(actual)
9
+ @actual = actual
10
+
11
+ if File.exist?(snapshot_filename)
12
+ @expected = YAML.load_file(snapshot_filename)
13
+ return @actual == @expected
14
+ else
15
+ save_snapshot(actual, snapshot_filename)
16
+ return true
17
+ end
18
+ end
19
+
20
+ def description
21
+ "match snapshot #{snapshot_filename}"
22
+ end
23
+
24
+ def failure_message
25
+ [
26
+ "expected: #{expected.inspect}",
27
+ " got: #{actual.inspect}",
28
+ '',
29
+ "(using snapshot #{snapshot_filename})"
30
+ ].join("\n")
31
+ end
32
+
33
+ def failure_message_when_negated
34
+ [
35
+ 'expected value not to match snapshot but it did',
36
+ "snapshot: #{actual.inspect}",
37
+ '',
38
+ "(using snapshot #{snapshot_filename})",
39
+ '',
40
+ 'does negating this matcher really make sense?'
41
+ ].join("\n")
42
+ end
43
+
44
+ def diffable?
45
+ true
46
+ end
47
+
48
+ private
49
+
50
+ def save_snapshot(actual, filename)
51
+ snapshot_directory = File.dirname(filename)
52
+ FileUtils.mkdir_p(snapshot_directory)
53
+
54
+ File.open(snapshot_filename, 'w') do |io|
55
+ io.write(actual.to_yaml)
56
+ end
57
+ end
58
+
59
+ def snapshot_filename
60
+ @snapshot_filename ||= begin
61
+ parts = [
62
+ 'spec',
63
+ 'fixtures',
64
+ 'snapshots',
65
+ *example_group_path,
66
+ example.description
67
+ ].map { |part| part.gsub(/\W/, '_') }
68
+
69
+ "#{File.join(*parts)}.yml"
70
+ end
71
+ end
72
+
73
+ def example_group_path
74
+ return [] unless example.example_group
75
+ example.example_group.parent_groups.reverse.map(&:description)
76
+ end
77
+
78
+ def example
79
+ Thread.current[:rspec_snapshot_matcher_example]
80
+ end
81
+ end
82
+
83
+ def match_snapshot(*args)
84
+ MatchSnapshot.new(*args)
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,3 @@
1
+ module RSpecSnapshotMatcher
2
+ VERSION = '0.1.0'.freeze
3
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'rspec_snapshot_matcher/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'rspec_snapshot_matcher'
9
+ spec.version = RSpecSnapshotMatcher::VERSION
10
+ spec.authors = ['Patrick Caldwell']
11
+ spec.email = ['tncbbthositg@gmail.com']
12
+
13
+ spec.summary = 'Matcher to compare objects to snapshots like Jest'
14
+ spec.description = %(This is an RSpec matcher that compares an actual value with the expected
15
+ value from an autogenerated snapshot file.)
16
+ spec.homepage = 'https://github.com/autopilotconsulting/rspec-snapshot-matcher'
17
+ spec.license = 'MIT'
18
+
19
+ spec.bindir = 'exe'
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
24
+ f.match(%r{^(test|spec|features)/})
25
+ end
26
+
27
+ spec.add_development_dependency 'bundler', '~> 1.12'
28
+ spec.add_development_dependency 'rake', '~> 10.0'
29
+ spec.add_development_dependency 'rspec', '~> 3.0'
30
+ spec.add_development_dependency 'rubocop', '~> 0.49.1'
31
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec_snapshot_matcher
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Patrick Caldwell
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-07-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.49.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.49.1
69
+ description: |-
70
+ This is an RSpec matcher that compares an actual value with the expected
71
+ value from an autogenerated snapshot file.
72
+ email:
73
+ - tncbbthositg@gmail.com
74
+ executables: []
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - ".rspec"
80
+ - ".rubocop.yml"
81
+ - ".travis.yml"
82
+ - Gemfile
83
+ - LICENSE.txt
84
+ - README.md
85
+ - Rakefile
86
+ - bin/console
87
+ - bin/setup
88
+ - lib/rspec_snapshot_matcher.rb
89
+ - lib/rspec_snapshot_matcher/matchers.rb
90
+ - lib/rspec_snapshot_matcher/matchers/snapshot_matcher.rb
91
+ - lib/rspec_snapshot_matcher/version.rb
92
+ - rspec_snapshot_matcher.gemspec
93
+ homepage: https://github.com/autopilotconsulting/rspec-snapshot-matcher
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.5.1
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Matcher to compare objects to snapshots like Jest
117
+ test_files: []