snapshot_testing 0.3.3 → 0.3.4

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
2
  SHA256:
3
- metadata.gz: abbd9e5dcb8e1bfc22a718387076ca8bc503da999d9d85ffb524a52b1ec9a01c
4
- data.tar.gz: a6286990db3d03a19f8afc35f61c447b686f0cdfbc2f82f1513fa3881efbdd09
3
+ metadata.gz: 24fffb537b059196e90489d136f7de672ee775dec6930f44c1906c21eac7d57d
4
+ data.tar.gz: 4708f457af4cf2bff18f17e3acb87631398d3dbb5ee04132283f3bf4a9f575fd
5
5
  SHA512:
6
- metadata.gz: 31d91ce651122861a12589a3f6b70e5e9c7958fd972ad2ca8ea6d937474d3cafaf502afa3b24cb1503a5e95d20d73392a5a055b6d0fcb346f91b47e483391863
7
- data.tar.gz: a9cae871013fadb45996d40822b0edae0fd0f6c9a6664b9cab38d9d0884f4e73cb2310ec613a4de3e04ed5390e07530cd73a1d48ef234501bae40492f7322528
6
+ metadata.gz: cbe9245acd2bb2726bb1b022de932723e0a2a0ec29a097f9f20e46afa19fea53ecd7c6baa4ed3b67a84e2ba00370d81d0695170012f046ca4b0ac18d1b85189d
7
+ data.tar.gz: 6a3e4e412bd2e5b0ccb7d498c11dd841a53c80cdd66a6f8cfded7d39497081a025770bb3c89a78c135acd4099b9324480e8a3d0913f5dfd735498d14833736dd
data/.gitignore CHANGED
@@ -12,3 +12,5 @@
12
12
 
13
13
  /Gemfile.lock
14
14
  /Gemfile.lock
15
+
16
+ /examples/__snapshots__/
data/Rakefile CHANGED
@@ -3,19 +3,29 @@ require "rspec/core/rake_task"
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- def info(message)
7
- puts "\033[1m#{message}\033[0m"
6
+ module Color
7
+ def self.bold(msg); "\e[1m#{msg}\e[22m" end
8
+ def self.pink(msg); "\e[35m#{msg}\e[0m" end
9
+ def self.cyan(msg); "\e[36m#{msg}\e[0m" end
8
10
  end
9
11
 
10
12
  task :examples do
11
- info "==>> Running RSpec..."
12
- ruby "examples/rspec.rb -f progress"
13
+ suites = [
14
+ ["RSpec", "examples/rspec.rb -f progress --no-color"],
15
+ ["Minitest", "examples/minitest.rb"],
16
+ ["TestUnit", "examples/test_unit.rb --no-use-color"]
17
+ ]
13
18
 
14
- info "\n\n==>> Running Minitest..."
15
- ruby "examples/minitest.rb"
16
-
17
- info "\n\n==>> Running TestUnit..."
18
- ruby "examples/test_unit.rb"
19
+ rm_rf "examples/__snapshots__/"
20
+ suites.each do |name, test_file|
21
+ puts Color.bold("==== #{name} ==============================")
22
+ puts Color.cyan("==>> Running #{name} for the first time...")
23
+ ruby test_file
24
+ puts "\n\n"
25
+ puts Color.pink("==>> Running #{name} against saved snapshots...")
26
+ ruby test_file
27
+ puts "\n\n"
28
+ end
19
29
  end
20
30
 
21
31
  task :default => :spec
@@ -13,6 +13,10 @@ class ExampleTest < Minitest::Test
13
13
  def test_named_snapshot
14
14
  assert_snapshot "named.minitest.test.txt", "named"
15
15
  end
16
+
17
+ define_method "test_escapes_regex_[]" do
18
+ assert_snapshot "hello"
19
+ end
16
20
  end
17
21
 
18
22
  class ExampleSpec < Minitest::Spec
@@ -26,4 +30,8 @@ class ExampleSpec < Minitest::Spec
26
30
  it "takes a named snapshot" do
27
31
  _("named").must_match_snapshot "named.minitest.spec.txt"
28
32
  end
33
+
34
+ it "escapes regex []" do
35
+ _("hello").must_match_snapshot
36
+ end
29
37
  end
@@ -4,6 +4,7 @@ require "snapshot_testing/rspec"
4
4
 
5
5
  RSpec.configure do |config|
6
6
  config.include SnapshotTesting::RSpec
7
+ config.color = false
7
8
  end
8
9
 
9
10
  RSpec.describe "Example" do
@@ -21,4 +22,8 @@ RSpec.describe "Example" do
21
22
 
22
23
  expect(message).to match_snapshot("named.rspec.txt")
23
24
  end
25
+
26
+ it "escapes regex []" do
27
+ expect("hello").to match_snapshot
28
+ end
24
29
  end
@@ -13,4 +13,8 @@ class ExampleTest < Test::Unit::TestCase
13
13
  def test_named_snapshot
14
14
  assert_snapshot "named.unit.txt", "named"
15
15
  end
16
+
17
+ define_method "test_escapes_regex_[]" do
18
+ assert_snapshot "hello"
19
+ end
16
20
  end
@@ -92,6 +92,11 @@ module SnapshotTesting
92
92
  # the file location of the current test
93
93
  attr_reader :path
94
94
 
95
+ # a Regexp that will match a snapshot name
96
+ def name_pattern
97
+ /^#{Regexp.escape(name)}\s\d+$/
98
+ end
99
+
95
100
  # should we update failing snapshots?
96
101
  def update?
97
102
  @update
@@ -107,14 +112,14 @@ module SnapshotTesting
107
112
  # remove stale snapshots
108
113
  def prune_snapshots
109
114
  stale = snapshots.keys - visited
110
- stale = stale.grep(/^#{name}\s\d+$/)
115
+ stale = stale.grep(name_pattern)
111
116
  stale.each { |key| snapshots.delete(key) }
112
117
  self.removed = stale.length
113
118
  end
114
119
 
115
120
  # the number of obsolete snapshots
116
121
  def obsolete
117
- (snapshots.keys - visited).grep(/^#{name}\s\d+$/).length
122
+ (snapshots.keys - visited).grep(name_pattern).length
118
123
  end
119
124
 
120
125
  # write all snapshots to the filesystem
@@ -1,3 +1,3 @@
1
1
  module SnapshotTesting
2
- VERSION = "0.3.3"
2
+ VERSION = "0.3.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snapshot_testing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ray Zane
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-12-31 00:00:00.000000000 Z
11
+ date: 2020-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -109,13 +109,6 @@ files:
109
109
  - Rakefile
110
110
  - bin/console
111
111
  - bin/setup
112
- - examples/__snapshots__/minitest.rb.snap
113
- - examples/__snapshots__/named.minitest.spec.txt
114
- - examples/__snapshots__/named.minitest.test.txt
115
- - examples/__snapshots__/named.rspec.txt
116
- - examples/__snapshots__/named.unit.txt
117
- - examples/__snapshots__/rspec.rb.snap
118
- - examples/__snapshots__/test_unit.rb.snap
119
112
  - examples/minitest.rb
120
113
  - examples/rspec.rb
121
114
  - examples/test_unit.rb
@@ -146,8 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
146
139
  - !ruby/object:Gem::Version
147
140
  version: '0'
148
141
  requirements: []
149
- rubyforge_project:
150
- rubygems_version: 2.7.6
142
+ rubygems_version: 3.0.3
151
143
  signing_key:
152
144
  specification_version: 4
153
145
  summary: Proper snapshot support for RSpec.
@@ -1,15 +0,0 @@
1
- snapshots["test_0001_takes a snapshot 1"] = <<-SNAP
2
- hello
3
- SNAP
4
-
5
- snapshots["test_0001_takes a snapshot 2"] = <<-SNAP
6
- goodbye
7
- SNAP
8
-
9
- snapshots["test_snapshot 1"] = <<-SNAP
10
- hello
11
- SNAP
12
-
13
- snapshots["test_snapshot 2"] = <<-SNAP
14
- goodbye
15
- SNAP
@@ -1,3 +0,0 @@
1
- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam diam
2
- urna, dignissim a faucibus eu, malesuada vitae tellus. Aliquam dignissim
3
- volutpat fermentum. Nam ultricies risus ac ornare venenatis.
@@ -1 +0,0 @@
1
- named
@@ -1,7 +0,0 @@
1
- snapshots["takes a snapshot 1"] = <<-SNAP
2
- hello
3
- SNAP
4
-
5
- snapshots["takes a snapshot 2"] = <<-SNAP
6
- goodbye
7
- SNAP
@@ -1,7 +0,0 @@
1
- snapshots["test_snapshot 1"] = <<-SNAP
2
- hello
3
- SNAP
4
-
5
- snapshots["test_snapshot 2"] = <<-SNAP
6
- goodbye
7
- SNAP