rspec-on_failure 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/Changelog.md +19 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +37 -0
- data/License +18 -0
- data/Rakefile +6 -0
- data/Readme.md +56 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/rspec-on_failure.rb +68 -0
- data/lib/rspec-on_failure/version.rb +5 -0
- data/rspec-on_failure.gemspec +25 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 13004a6760304fdc2c7c1b82de0304a145dd4bff
|
4
|
+
data.tar.gz: a7b0fd2c717851e015fab0f4b4edc80e3e67ac96
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 52598956efcfd11f080ade057e545f96704c75c5e52c758897063b0d9860bcefbdf5057022bc016aaba181322977ee451719f6d6e559e4d0a5c67ae221f87804
|
7
|
+
data.tar.gz: d548e7a5cfd53052f199c402d0f2d5037c96833f0f1555030bac909e39464cb2da858d8a73d21bf216e9b6060fbedb61f306b50646564fb26c1787efcc8ad032
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Changelog.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
This project follows [semver 2.0.0](http://semver.org/spec/v2.0.0.html) and the
|
4
|
+
recommendations of [keepachangelog.com](http://keepachangelog.com/).
|
5
|
+
|
6
|
+
## (Unreleased)
|
7
|
+
|
8
|
+
## 1.0.1 (2019-10-18)
|
9
|
+
- Rename to rspec-on_failure
|
10
|
+
|
11
|
+
## 1.0.0 (2019-10-18)
|
12
|
+
|
13
|
+
### Breaking changes
|
14
|
+
- Rescue a broader set of exceptions, not just `RSpec::Expectations::ExpectationNotMetError`
|
15
|
+
|
16
|
+
### Fixed
|
17
|
+
- It was failing to trigger the `on_failure` block when the failure was due to an
|
18
|
+
exception other than a `ExpectationNotMetError`, like `Capybara::ElementNotFound`.
|
19
|
+
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rspec-on_failure (1.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
byebug (11.0.1)
|
10
|
+
diff-lcs (1.3)
|
11
|
+
rake (13.0.0)
|
12
|
+
rspec (3.9.0)
|
13
|
+
rspec-core (~> 3.9.0)
|
14
|
+
rspec-expectations (~> 3.9.0)
|
15
|
+
rspec-mocks (~> 3.9.0)
|
16
|
+
rspec-core (3.9.0)
|
17
|
+
rspec-support (~> 3.9.0)
|
18
|
+
rspec-expectations (3.9.0)
|
19
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
20
|
+
rspec-support (~> 3.9.0)
|
21
|
+
rspec-mocks (3.9.0)
|
22
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
23
|
+
rspec-support (~> 3.9.0)
|
24
|
+
rspec-support (3.9.0)
|
25
|
+
|
26
|
+
PLATFORMS
|
27
|
+
ruby
|
28
|
+
|
29
|
+
DEPENDENCIES
|
30
|
+
bundler (>= 2.0)
|
31
|
+
byebug
|
32
|
+
rake (>= 10.0)
|
33
|
+
rspec (~> 3.0)
|
34
|
+
rspec-on_failure!
|
35
|
+
|
36
|
+
BUNDLED WITH
|
37
|
+
2.0.2
|
data/License
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Copyright (c) 2019 Tyler Rick
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
4
|
+
associated documentation files (the "Software"), to deal in the Software without restriction,
|
5
|
+
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
6
|
+
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
7
|
+
furnished to do so, subject to the following conditions:
|
8
|
+
|
9
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial
|
10
|
+
portions of the Software.
|
11
|
+
|
12
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
13
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
14
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
15
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
16
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
17
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
18
|
+
SOFTWARE.
|
data/Rakefile
ADDED
data/Readme.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# RSpecOnFailure
|
2
|
+
|
3
|
+
Provide additional debugging information to be printed if a test fails.
|
4
|
+
|
5
|
+
In case the debugging information you want to display on failure cannot be easily determined *prior*
|
6
|
+
to evaluating the expectation. This won't work as expected, for example:
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
expect(user).to be_valid, user.errors.full_messages
|
10
|
+
```
|
11
|
+
|
12
|
+
because `user.errors.full_messages` gets evaluated too soon. This will show the list of errors as it
|
13
|
+
was *prior* to calling `user.valid?` (that is, an empty array), rather than the list of errors as it
|
14
|
+
was *after* validating therecord, which is what we actually want.
|
15
|
+
|
16
|
+
Instead, you can do this, which defers evaluation of the debug information until the time of the
|
17
|
+
failure:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
on_failure ->{ user.errors.full_messages } do
|
21
|
+
expect(user).to be_valid
|
22
|
+
end
|
23
|
+
```
|
24
|
+
|
25
|
+
If no block is given, the provided on_failure proc remains in effect until the end of the current
|
26
|
+
example.
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
on_failure ->{ user.errors.full_messages }
|
30
|
+
expect(user).to be_valid
|
31
|
+
expect(user.errors[:name]).to include "is required"
|
32
|
+
```
|
33
|
+
|
34
|
+
## Installation
|
35
|
+
|
36
|
+
Add this line to your application's Gemfile:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
group :test do
|
40
|
+
gem 'rspec-on_failure'
|
41
|
+
end
|
42
|
+
```
|
43
|
+
|
44
|
+
And then execute:
|
45
|
+
|
46
|
+
$ bundle
|
47
|
+
|
48
|
+
## Development
|
49
|
+
|
50
|
+
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.
|
51
|
+
|
52
|
+
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).
|
53
|
+
|
54
|
+
## Contributing
|
55
|
+
|
56
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/TylerRick/rspec-on_failure.
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rspec-on_failure"
|
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(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require "rspec-on_failure/version"
|
3
|
+
|
4
|
+
module RSpecOnFailure
|
5
|
+
# Provide additional debugging information to be printed if a test fails.
|
6
|
+
#
|
7
|
+
# In case the debugging information you want to display on failure cannot be easily determined prior
|
8
|
+
# to evaluating the expectation. This won't work as expected, for example:
|
9
|
+
#
|
10
|
+
# expect(user).to be_valid, user.errors.full_messages
|
11
|
+
#
|
12
|
+
# because user.errors.full_messages is evaluated *before* it actually calls user.valid?, so it will be empty.
|
13
|
+
#
|
14
|
+
# Instead, you can do this, which defers evaluation of the debug information until the time of the
|
15
|
+
# failure:
|
16
|
+
#
|
17
|
+
# on_failure ->{ user.errors.full_messages } do
|
18
|
+
# expect(user).to be_valid
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
# If no block is given, the provided on_failure proc remains in effect until the end of the current
|
22
|
+
# example.
|
23
|
+
#
|
24
|
+
# on_failure ->{ user.errors.full_messages }
|
25
|
+
# expect(user).to be_valid
|
26
|
+
# expect(user.errors[:name]).to include "is required"
|
27
|
+
#
|
28
|
+
def on_failure(on_failure_proc)
|
29
|
+
if block_given?
|
30
|
+
on_failure_call_proc(on_failure_proc) do
|
31
|
+
yield
|
32
|
+
end
|
33
|
+
else
|
34
|
+
# The provided proc remains in effect until the end of the current example
|
35
|
+
@_on_failure_proc = on_failure_proc
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def on_failure_call_proc(on_failure_proc)
|
40
|
+
begin
|
41
|
+
yield
|
42
|
+
rescue RSpec::Support::AllExceptionsExceptOnesWeMustNotRescue
|
43
|
+
run_failure_call_proc on_failure_proc
|
44
|
+
raise
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def run_failure_call_proc(on_failure_proc, *args)
|
49
|
+
return unless on_failure_proc
|
50
|
+
result = on_failure_proc.call *[args].first(on_failure_proc.arity)
|
51
|
+
p result unless result.nil?
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
RSpec.configure do |config|
|
56
|
+
config.include RSpecOnFailure
|
57
|
+
config.after(:each) do |example|
|
58
|
+
begin
|
59
|
+
if example.exception and RSpec::Support::AllExceptionsExceptOnesWeMustNotRescue === example.exception
|
60
|
+
run_failure_call_proc example.metadata[:on_failure], example
|
61
|
+
#puts %(@_on_failure_proc=#{(@_on_failure_proc).inspect})
|
62
|
+
run_failure_call_proc @_on_failure_proc, example
|
63
|
+
end
|
64
|
+
ensure
|
65
|
+
@_on_failure_proc = nil
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "rspec-on_failure/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rspec-on_failure"
|
8
|
+
spec.version = RSpecOnFailure.version
|
9
|
+
spec.authors = ["Tyler Rick"]
|
10
|
+
spec.email = ["tyler@tylerrick.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Provide additional debugging information to be printed if a test fails.}
|
13
|
+
spec.homepage = "https://github.com/TylerRick/rspec-on_failure"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
16
|
+
f.match(%r{^(test|spec|features)/})
|
17
|
+
end
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", ">= 2.0"
|
23
|
+
spec.add_development_dependency "rake", ">= 10.0"
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec-on_failure
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tyler Rick
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-10-22 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: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
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
|
+
description:
|
56
|
+
email:
|
57
|
+
- tyler@tylerrick.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- Changelog.md
|
66
|
+
- Gemfile
|
67
|
+
- Gemfile.lock
|
68
|
+
- License
|
69
|
+
- Rakefile
|
70
|
+
- Readme.md
|
71
|
+
- bin/console
|
72
|
+
- bin/setup
|
73
|
+
- lib/rspec-on_failure.rb
|
74
|
+
- lib/rspec-on_failure/version.rb
|
75
|
+
- rspec-on_failure.gemspec
|
76
|
+
homepage: https://github.com/TylerRick/rspec-on_failure
|
77
|
+
licenses: []
|
78
|
+
metadata: {}
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 2.6.14.3
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: Provide additional debugging information to be printed if a test fails.
|
99
|
+
test_files: []
|