rspec-snapshot 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: 399a12bddd879883df59d2585f9b79f0af141f13
4
+ data.tar.gz: 05f6017e55fa1cd0475e88c0c5c8c085a81ac9c2
5
+ SHA512:
6
+ metadata.gz: a1e1bf2d3e3498d3edabc29e4327cd224086e6e0e4f5b990e33b5bd97e2ddb98b3b4d6360266e9cf46ef3352c2fb3b8faa42b21a9e57d3910354be1849453624
7
+ data.tar.gz: e7c596351101233fe6faf2eaf2e567062b6abf256a2f1a935d626a1ea0376d920c27720a9b8dbb05660a7924b146b987b072240ac8138bc28fde355a3056e57b
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1,6 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.5
5
+ - 2.3.1
6
+ 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.gemspec
4
+ gemspec
@@ -0,0 +1,73 @@
1
+ # RSpec::Snapshot
2
+
3
+ Adding snapshot testing to RSpec, inspired by [jest](http://facebook.github.io/jest/blog/2016/07/27/jest-14.html).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'rspec-snapshot'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install rspec-snapshot
20
+
21
+ ## Usage
22
+
23
+ ### Configration
24
+
25
+ ```ruby
26
+ RSpec.configure do |config|
27
+ # The default setting is `:relative`, that means snapshots will be generate to
28
+ # the relative path of the spec file.
29
+ config.snapshot_dir = "spec/fixtures/snapshots"
30
+ end
31
+ ```
32
+
33
+ ### Rails JSON API controller testing
34
+
35
+ ```ruby
36
+ describe TeamsController do
37
+ describe "GET index" do
38
+ it "returns a list of team" do
39
+ get :index
40
+ expect(response.body).to match_snapshot('controllers/teams/index')
41
+ end
42
+ end
43
+ end
44
+ ```
45
+
46
+ ### Rails view testing
47
+
48
+ ```ruby
49
+ describe "widgets/index" do
50
+ it "displays all the widgets" do
51
+ assign(:widgets, [
52
+ Widget.create!(:name => "slicer"),
53
+ Widget.create!(:name => "dicer")
54
+ ])
55
+
56
+ render
57
+
58
+ expect(rendered).to match_snapshot('views/widgets/index')
59
+ end
60
+ end
61
+ ```
62
+
63
+ Use your imagination for other usages!
64
+
65
+ ## Development
66
+
67
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
68
+
69
+ 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).
70
+
71
+ ## Contributing
72
+
73
+ Bug reports and pull requests are welcome on GitHub at https://github.com/yesmeck/rspec-snapshot.
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task test: [:spec]
7
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rspec/snapshot"
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,4 @@
1
+ require "rspec"
2
+ require "rspec/snapshot/version"
3
+ require "rspec/snapshot/configuration"
4
+ require "rspec/snapshot/matchers"
@@ -0,0 +1,11 @@
1
+ module RSpec
2
+ module Snapshot
3
+ class Configuration; end
4
+
5
+ def self.initialize_configuration(config)
6
+ config.add_setting :snapshot_dir, :default => :relative
7
+ end
8
+
9
+ initialize_configuration RSpec.configuration
10
+ end
11
+ end
@@ -0,0 +1,16 @@
1
+ require "json"
2
+ require "rspec/snapshot/matchers/match_snapshot"
3
+
4
+ module RSpec
5
+ module Snapshot
6
+ module Matchers
7
+ def match_snapshot(snapshot_name)
8
+ MatchSnapShot.new(self.class.metadata, snapshot_name)
9
+ end
10
+ end
11
+ end
12
+ end
13
+
14
+ RSpec.configure do |config|
15
+ config.include RSpec::Snapshot::Matchers
16
+ end
@@ -0,0 +1,46 @@
1
+ require "fileutils"
2
+
3
+ module RSpec
4
+ module Snapshot
5
+ module Matchers
6
+ class MatchSnapShot
7
+ def initialize(metadata, snapshot_name)
8
+ @metadata = metadata
9
+ @snapshot_name = snapshot_name
10
+ end
11
+
12
+ def matches?(actual)
13
+ @actual = actual
14
+ filename = "#{@snapshot_name}.snap"
15
+ snap_path = File.join(snapshot_dir, filename)
16
+ FileUtils.mkdir_p(File.dirname(snap_path)) unless Dir.exist?(File.dirname(snap_path))
17
+ if File.exist?(snap_path)
18
+ file = File.new(snap_path)
19
+ @expect = file.read
20
+ file.close
21
+ @actual == @expect
22
+ else
23
+ RSpec.configuration.reporter.message "Generate #{snap_path}"
24
+ file = File.new(snap_path, "w+")
25
+ file.write(@actual)
26
+ file.close
27
+ true
28
+ end
29
+ end
30
+
31
+
32
+ def failure_message
33
+ "\nexpected: #{@expect_snap}\n got: #{@actual_snap}\n"
34
+ end
35
+
36
+ def snapshot_dir
37
+ if RSpec.configuration.snapshot_dir.to_s == 'relative'
38
+ File.dirname(@metadata[:file_path]) << "/__snapshots__"
39
+ else
40
+ RSpec.configuration.snapshot_dir
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,5 @@
1
+ module RSpec
2
+ module Snapshot
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rspec/snapshot/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rspec-snapshot"
8
+ spec.version = RSpec::Snapshot::VERSION
9
+ spec.authors = ["Wei Zhu"]
10
+ spec.email = ["yesmeck@gmail.com"]
11
+
12
+ spec.summary = %q{RSpec Snapshot Matcher}
13
+ spec.description = %q{Adding snapshot testing to RSpec}
14
+ spec.homepage = "https://github.com/yesmeck/rspec-snapshot"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "rspec", "> 3.0.0"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.12"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "pry", "~> 0.10.4"
26
+ spec.add_development_dependency "activesupport", "~> 5.0.0"
27
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec-snapshot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Wei Zhu
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-09-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">"
18
+ - !ruby/object:Gem::Version
19
+ version: 3.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">"
25
+ - !ruby/object:Gem::Version
26
+ version: 3.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.10.4
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.10.4
69
+ - !ruby/object:Gem::Dependency
70
+ name: activesupport
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 5.0.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 5.0.0
83
+ description: Adding snapshot testing to RSpec
84
+ email:
85
+ - yesmeck@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - README.md
95
+ - Rakefile
96
+ - bin/console
97
+ - bin/setup
98
+ - lib/rspec/snapshot.rb
99
+ - lib/rspec/snapshot/configuration.rb
100
+ - lib/rspec/snapshot/matchers.rb
101
+ - lib/rspec/snapshot/matchers/match_snapshot.rb
102
+ - lib/rspec/snapshot/version.rb
103
+ - rspec-snapshot.gemspec
104
+ homepage: https://github.com/yesmeck/rspec-snapshot
105
+ licenses: []
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.4.8
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: RSpec Snapshot Matcher
127
+ test_files: []