attestify 0.1.0.pre.1

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: 7b89b143f940ebbeb5be5c9f14d4d76e2211ec52
4
+ data.tar.gz: 897b052d0d6b336246c716a561099b6996b96e3e
5
+ SHA512:
6
+ metadata.gz: 0a2cf3fa488d7ad4f2ede463bd7380daf27807e94729aa66bef74a8b5756ead081e6ddc528581f66e54bb5973b442469befe3f104218e75822af799664742262
7
+ data.tar.gz: 7de390a92c1f0cc8bda31846f4104344b55ce4be600a43301a95295c6ddb49e94814f5536ce447505d2dca1725137af16ef069f74160fac57a58c7e1fab2a0a5
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,37 @@
1
+ AllCops:
2
+ Exclude:
3
+ - bin/**/*
4
+ - tmp/**/*
5
+ - vendor/**/*
6
+ DisplayCopNames: true
7
+
8
+ Metrics/AbcSize:
9
+ Exclude:
10
+ - test/**/*_test.rb
11
+
12
+ Metrics/ClassLength:
13
+ Exclude:
14
+ - test/**/*_test.rb
15
+
16
+ Metrics/LineLength:
17
+ Max: 120
18
+
19
+ Metrics/MethodLength:
20
+ Exclude:
21
+ - test/**/*_test.rb
22
+
23
+ Style/ClassAndModuleChildren:
24
+ Exclude:
25
+ - test/**/*_test.rb
26
+
27
+ Style/SignalException:
28
+ EnforcedStyle: only_raise
29
+
30
+ Style/SpaceInsideBlockBraces:
31
+ EnforcedStyleForEmptyBraces: space
32
+
33
+ Style/StringLiterals:
34
+ EnforcedStyle: double_quotes
35
+
36
+ Style/StringLiteralsInInterpolation:
37
+ EnforcedStyle: double_quotes
@@ -0,0 +1,8 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2
5
+ before_install: gem install bundler -v 1.12.5
6
+ cache: bundler
7
+ script:
8
+ - bundle exec rake
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at mike@virata-stone.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in attestify.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Mike Virata-Stone
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,75 @@
1
+ [![Build Status](https://travis-ci.org/smellsblue/attestify.svg?branch=master)](https://travis-ci.org/smellsblue/attestify)
2
+ [![Code Climate](https://codeclimate.com/github/smellsblue/attestify/badges/gpa.svg)](https://codeclimate.com/github/smellsblue/attestify)
3
+
4
+ # Attestify
5
+
6
+ Attestify has a few key goals:
7
+ * Be fast
8
+ * Be slim
9
+ * Be (mostly) API compatible with [Minitest](https://github.com/seattlerb/minitest)
10
+ * Allow multiple failed assertions
11
+
12
+ While the first 3 goals are probably self explanatory, you might
13
+ scratch your head a bit at the last. If you have ever used
14
+ [QUnit](https://qunitjs.com/), then you may already be familiar with
15
+ this style of testing. Essentially, your entire test runs every time,
16
+ _regardless of failures_. The only thing that will stop a test from
17
+ continuing is an exception.
18
+
19
+ To give a quick example of how this might benefit you, consider the
20
+ following code:
21
+
22
+ ```
23
+ def test_some_functionality_involving_an_array
24
+ some_object = SomeCode.that_returns_an_object
25
+ assert_equal 42, some_object.an_attribute
26
+ assert_equal 4, some_object.another_attribute
27
+ assert_equal 2, some_object.a_final_attribute
28
+ end
29
+ ```
30
+
31
+ Now, what would happen if every assertion would fail? In most Ruby
32
+ test frameworks, you will get a single message about the first
33
+ failure. Sometimes the later assertions would give incredibly useful
34
+ information for diagnosing the test failure. You could break it up
35
+ into 3 tests, but sometimes the setup code is incredibly slow, or all
36
+ the attributes are related to the one test case.
37
+
38
+ In Attestify, every assertion that fails will be reported, giving you
39
+ the full picture of what your tests could tell you.
40
+
41
+ ## Installation
42
+
43
+ Add this line to your application's Gemfile:
44
+
45
+ ```ruby
46
+ gem "attestify"
47
+ ```
48
+
49
+ And then execute:
50
+
51
+ $ bundle
52
+
53
+ Or install it yourself as:
54
+
55
+ $ gem install attestify
56
+
57
+ ## Usage
58
+
59
+ This section is still to come, but in the meantime, write your tests
60
+ as if they were Minitest tests, but replace `Minitest::` with
61
+ `Attestify::`.
62
+
63
+ ## Development
64
+
65
+ 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.
66
+
67
+ 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).
68
+
69
+ ## Contributing
70
+
71
+ Bug reports and pull requests are welcome on GitHub at https://github.com/smellsblue/attestify. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
72
+
73
+ ## License
74
+
75
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+ require "rubocop/rake_task"
3
+ RuboCop::RakeTask.new(:rubocop)
4
+ Attestify::RakeTask.new(:test)
5
+ task default: [:rubocop, :test]
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "attestify"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "attestify"
8
+ spec.version = Attestify::VERSION
9
+ spec.authors = ["Mike Virata-Stone"]
10
+ spec.email = ["mike@virata-stone.com"]
11
+
12
+ spec.summary = "A new way to test your code"
13
+ spec.description = "A small framework for testing your code. It keeps track of assertion failures as well as " \
14
+ "test failures."
15
+ spec.homepage = "https://github.com/smellsblue/attestify"
16
+ spec.license = "MIT"
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.12"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rubocop", "0.40.0"
26
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "attestify"
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,3 @@
1
+ #!/usr/bin/env ruby
2
+ require "attestify"
3
+ Attestify::CLI.start
@@ -0,0 +1,20 @@
1
+ # :nodoc:
2
+ module Attestify
3
+ autoload :AssertionResults, "attestify/assertion_results"
4
+ autoload :Assertions, "attestify/assertions"
5
+ autoload :CLI, "attestify/cli"
6
+ autoload :ColorReporter, "attestify/color_reporter"
7
+ autoload :Mock, "attestify/mock"
8
+ autoload :RakeTask, "attestify/rake_task"
9
+ autoload :Reporter, "attestify/reporter"
10
+ autoload :SkippedError, "attestify/skipped_error"
11
+ autoload :Test, "attestify/test"
12
+ autoload :TestList, "attestify/test_list"
13
+ autoload :TestRunner, "attestify/test_runner"
14
+ autoload :Timer, "attestify/timer"
15
+ autoload :VERSION, "attestify/version"
16
+
17
+ def self.root
18
+ @root ||= File.realpath(File.expand_path("../..", __FILE__)).freeze
19
+ end
20
+ end
@@ -0,0 +1,93 @@
1
+ module Attestify
2
+ # Stores the results of running assertions (and other test related
3
+ # results).
4
+ class AssertionResults
5
+ attr_reader :error, :passed, :failed, :total, :failure_details
6
+
7
+ def initialize
8
+ @passed = 0
9
+ @failed = 0
10
+ @total = 0
11
+ @failure_details = []
12
+ end
13
+
14
+ def error=(exception)
15
+ @failure_details << Attestify::AssertionResults::FailureDetail.for_error(exception)
16
+ @error = exception
17
+ end
18
+
19
+ def record(passed, message = nil, backtrace_locations = nil)
20
+ if passed
21
+ @passed += 1
22
+ else
23
+ @failure_details << Attestify::AssertionResults::FailureDetail.new(message, backtrace_locations)
24
+ @failed += 1
25
+ end
26
+
27
+ @total += 1
28
+ end
29
+
30
+ def errored
31
+ if skipped?
32
+ 0
33
+ elsif error
34
+ 1
35
+ else
36
+ 0
37
+ end
38
+ end
39
+
40
+ def skipped?
41
+ error.is_a?(Attestify::SkippedError)
42
+ end
43
+
44
+ def errored?
45
+ error
46
+ end
47
+
48
+ def failed?
49
+ @failed > 0
50
+ end
51
+
52
+ def passed?
53
+ !errored? && !failed?
54
+ end
55
+
56
+ # Contains details of a failure, including the message and
57
+ # backtrace information.
58
+ class FailureDetail
59
+ attr_reader :message, :backtrace_locations, :type
60
+ ATTESTIFY_LIB = File.join(Attestify.root, "lib").freeze
61
+
62
+ def initialize(message, backtrace_locations, type = :failure)
63
+ @message = message
64
+ @backtrace_locations = simplify_backtrace_locations(backtrace_locations)
65
+ @type = type
66
+ end
67
+
68
+ def self.for_error(exception)
69
+ new("#{exception.class.name}: #{exception.message}", exception.backtrace_locations, :error)
70
+ end
71
+
72
+ private
73
+
74
+ def simplify_backtrace_locations(backtrace_locations)
75
+ result = backtrace_locations.dup
76
+ result.pop while !result.empty? && !location_in_attestify?(result.last)
77
+ result.pop while !result.empty? && location_in_attestify?(result.last)
78
+ result
79
+ rescue
80
+ # In case of a disaster, use the original locations, otherwise
81
+ # tests that should fail would seem to succeed.
82
+ return backtrace_locations
83
+ end
84
+
85
+ def location_in_attestify?(location)
86
+ path = File.realpath(location.absolute_path)
87
+ return false if path.size < ATTESTIFY_LIB.size
88
+ return false unless path[0...ATTESTIFY_LIB.size] == ATTESTIFY_LIB
89
+ path[ATTESTIFY_LIB.size] == File::SEPARATOR
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,334 @@
1
+ require "stringio"
2
+ require "tempfile"
3
+
4
+ module Attestify
5
+ # Assertion methods that record assertion results via the
6
+ # `assertions` method. The `assertions` method is expected to return
7
+ # an Attestify::AssertionResults.
8
+ module Assertions # rubocop:disable Metrics/ModuleLength
9
+ autoload :OutputAssertion, "attestify/assertions/output_assertion"
10
+
11
+ def assert(value, message = nil)
12
+ record_assert(value) { message || "Failed assertion." }
13
+ end
14
+
15
+ def assert_empty(object, message = nil)
16
+ if object.respond_to?(:empty?)
17
+ record_assert(object.empty?) { message || "Expected #{object.inspect} to be empty" }
18
+ else
19
+ record_assert(false) { message || "Expected #{object.inspect} to be empty, but it didn't respond_to(:empty?)" }
20
+ end
21
+ end
22
+
23
+ def assert_equal(expected, actual, message = nil)
24
+ record_assert(expected == actual) { message || "Expected #{expected.inspect} == #{actual.inspect}" }
25
+ end
26
+
27
+ def assert_in_delta(expected, actual, delta = 0.001, message = nil)
28
+ record_assert((expected - actual).abs < delta) do
29
+ message || "Expected #{expected.inspect} == #{actual.inspect} within #{delta.inspect}"
30
+ end
31
+ end
32
+
33
+ def assert_includes(collection, object, message = nil)
34
+ if collection.respond_to?(:include?)
35
+ record_assert(collection.include?(object)) do
36
+ message || "Expected #{collection.inspect} to include?(#{object.inspect})"
37
+ end
38
+ else
39
+ record_assert(false) do
40
+ message || "Expected #{collection.inspect} to include?(#{object.inspect}), " \
41
+ "but it didn't respond_to(:include?)"
42
+ end
43
+ end
44
+ end
45
+
46
+ def assert_instance_of(clazz, object, message = nil)
47
+ if clazz.is_a?(Module)
48
+ record_assert(object.instance_of?(clazz)) do
49
+ message || "Expected #{object.inspect} to be an instance_of?(#{clazz.inspect})"
50
+ end
51
+ else
52
+ record_assert(false) do
53
+ message || "Expected #{object.inspect} to be an instance_of?(#{clazz.inspect}), " \
54
+ "but #{clazz.inspect} is not a Class or Module"
55
+ end
56
+ end
57
+ end
58
+
59
+ def assert_kind_of(clazz, object, message = nil)
60
+ if clazz.is_a?(Module)
61
+ record_assert(object.is_a?(clazz)) do
62
+ message || "Expected #{object.inspect} to be a kind_of?(#{clazz.inspect})"
63
+ end
64
+ else
65
+ record_assert(false) do
66
+ message || "Expected #{object.inspect} to be a kind_of?(#{clazz.inspect}), " \
67
+ "but #{clazz.inspect} is not a Class or Module"
68
+ end
69
+ end
70
+ end
71
+
72
+ def assert_match(matcher, object, message = nil)
73
+ record_assert(matcher =~ object) { message || "Expected #{matcher.inspect} =~ #{object.inspect}" }
74
+ end
75
+
76
+ def assert_nil(object, message = nil)
77
+ record_assert(object.nil?) { message || "Expected #{object.inspect} to be nil" }
78
+ end
79
+
80
+ def assert_operator(left_operand, operator, right_operand, message = nil)
81
+ if left_operand.respond_to?(operator)
82
+ record_assert(left_operand.send(operator, right_operand)) do
83
+ message || "Expected #{left_operand.inspect} #{operator} #{right_operand.inspect}"
84
+ end
85
+ else
86
+ record_assert(false) do
87
+ message || "Expected #{left_operand.inspect} #{operator} #{right_operand.inspect}, " \
88
+ "but #{left_operand.inspect} didn't respond_to?(#{operator})"
89
+ end
90
+ end
91
+ end
92
+
93
+ def assert_output(expected_stdout = nil, expected_stderr = nil, message = nil)
94
+ stdout, stderr = capture_io { yield }
95
+ assertion = Attestify::Assertions::OutputAssertion.new(expected_stdout, expected_stderr, stdout, stderr, message)
96
+ record_assert(assertion.assert) { assertion.message }
97
+ end
98
+
99
+ def assert_predicate(object, predicate, message = nil)
100
+ if object.respond_to?(predicate)
101
+ record_assert(object.send(predicate)) { message || "Expected #{object.inspect} to be #{predicate}" }
102
+ else
103
+ record_assert(false) do
104
+ message || "Expected #{object.inspect} to be #{predicate}, " \
105
+ "but #{object.inspect} didn't respond_to?(#{predicate})"
106
+ end
107
+ end
108
+ end
109
+
110
+ def assert_raises(*exceptions)
111
+ message = exceptions.pop if exceptions.last.is_a?(String)
112
+ exceptions = [StandardError] if exceptions.empty?
113
+ yield
114
+ record_assert(false) { message || "Expected one of: #{exceptions.inspect} to be raised, but nothing was raised" }
115
+ return nil
116
+ rescue => e
117
+ record_assert(exceptions.any? { |x| e.is_a?(x) }) do
118
+ message || "Expected one of: #{exceptions.inspect} to be raised, but instead got: #{e.class.name}"
119
+ end
120
+
121
+ return e
122
+ end
123
+
124
+ def assert_respond_to(object, method, message = nil)
125
+ if method.is_a?(String) || method.is_a?(Symbol)
126
+ record_assert(object.respond_to?(method)) do
127
+ message || "Expected #{object.inspect} to respond_to?(#{method.inspect})"
128
+ end
129
+ else
130
+ record_assert(false) do
131
+ message || "Expected #{object.inspect} to respond_to?(#{method.inspect}), " \
132
+ "but #{method.inspect} is not a String or Symbol"
133
+ end
134
+ end
135
+ end
136
+
137
+ def assert_same(expected, actual, message = nil)
138
+ record_assert(expected.equal?(actual)) { message || "Expected #{expected.inspect} is equal?(#{actual.inspect})" }
139
+ end
140
+
141
+ def assert_silent(message = nil)
142
+ stdout, stderr = capture_io { yield }
143
+ assertion = Attestify::Assertions::OutputAssertion.new("", "", stdout, stderr, message)
144
+
145
+ record_assert(assertion.assert) do
146
+ message || "Expected silence, but instead got: $stdout: #{stdout.inspect}, and $stderr: #{stderr.inspect}"
147
+ end
148
+ end
149
+
150
+ def assert_42(expected, message = nil) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/LineLength, Metrics/MethodLength, Metrics/PerceivedComplexity
151
+ record_assert(
152
+ if expected.is_a?(Numeric)
153
+ expected == 42
154
+ elsif expected.is_a?(String)
155
+ expected == "42" || expected.casecmp("forty-two") == 0
156
+ elsif expected.respond_to?("42?")
157
+ expected.send("42?")
158
+ elsif expected.respond_to?(:forty_two?)
159
+ expected.forty_two?
160
+ end
161
+ ) do
162
+ message || "Answer to the Ultimate Question of Life, The Universe, and Everything is Incorrect"
163
+ end
164
+ end
165
+
166
+ def capture_io # rubocop:disable Metrics/MethodLength
167
+ original_out = $stdout
168
+ original_err = $stderr
169
+ out = StringIO.new
170
+ err = StringIO.new
171
+ $stdout = out
172
+ $stderr = err
173
+ Object.send :remove_const, :STDOUT
174
+ Object.send :remove_const, :STDERR
175
+ Object.const_set :STDOUT, out
176
+ Object.const_set :STDERR, err
177
+ yield
178
+ [out.string, err.string]
179
+ ensure
180
+ $stdout = original_out
181
+ $stderr = original_err
182
+ Object.send :remove_const, :STDOUT
183
+ Object.send :remove_const, :STDERR
184
+ Object.const_set :STDOUT, original_out
185
+ Object.const_set :STDERR, original_err
186
+ end
187
+
188
+ def capture_subprocess_io # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
189
+ original_out = STDOUT.dup
190
+ original_err = STDERR.dup
191
+ out = Tempfile.new("attestify.out")
192
+ err = Tempfile.new("attestify.err")
193
+ STDOUT.reopen(out.path, "w")
194
+ STDERR.reopen(err.path, "w")
195
+ yield
196
+ out.rewind
197
+ err.rewind
198
+ [out.read, err.read]
199
+ ensure
200
+ STDOUT.reopen(original_out)
201
+ STDERR.reopen(original_err)
202
+ out.close
203
+ err.close
204
+ out.unlink
205
+ err.unlink
206
+ end
207
+
208
+ def flunk(message = nil)
209
+ record_assert(false) { message || "Flunked assertion." }
210
+ end
211
+
212
+ def pass(_message = nil)
213
+ record_assert(true)
214
+ end
215
+
216
+ def refute(value, message = nil)
217
+ record_assert(!value) { message || "Failed refutation." }
218
+ end
219
+
220
+ def refute_empty(object, message = nil)
221
+ if object.respond_to?(:empty?)
222
+ record_assert(!object.empty?) { message || "Expected #{object.inspect} to not be empty" }
223
+ else
224
+ pass
225
+ end
226
+ end
227
+
228
+ def refute_equal(expected, actual, message = nil)
229
+ record_assert(expected != actual) { message || "Expected #{expected.inspect} != #{actual.inspect}" }
230
+ end
231
+
232
+ def refute_in_delta(expected, actual, delta = 0.001, message = nil)
233
+ record_assert((expected - actual).abs >= delta) do
234
+ message || "Expected #{expected.inspect} != #{actual.inspect} within #{delta.inspect}"
235
+ end
236
+ end
237
+
238
+ def refute_includes(collection, object, message = nil)
239
+ if collection.respond_to?(:include?)
240
+ record_assert(!collection.include?(object)) do
241
+ message || "Expected #{collection.inspect} to not include?(#{object.inspect})"
242
+ end
243
+ else
244
+ pass
245
+ end
246
+ end
247
+
248
+ def refute_instance_of(clazz, object, message = nil)
249
+ if clazz.is_a?(Module)
250
+ record_assert(!object.instance_of?(clazz)) do
251
+ message || "Expected #{object.inspect} to not be an instance_of?(#{clazz.inspect})"
252
+ end
253
+ else
254
+ pass
255
+ end
256
+ end
257
+
258
+ def refute_kind_of(clazz, object, message = nil)
259
+ if clazz.is_a?(Module)
260
+ record_assert(!object.is_a?(clazz)) do
261
+ message || "Expected #{object.inspect} to not be a kind_of?(#{clazz.inspect})"
262
+ end
263
+ else
264
+ pass
265
+ end
266
+ end
267
+
268
+ def refute_match(matcher, object, message = nil)
269
+ record_assert(!(matcher =~ object)) { message || "Expected not #{matcher.inspect} =~ #{object.inspect}" }
270
+ end
271
+
272
+ def refute_nil(object, message = nil)
273
+ record_assert(!object.nil?) { message || "Expected #{object.inspect} to not be nil" }
274
+ end
275
+
276
+ def refute_operator(left_operand, operator, right_operand, message = nil)
277
+ if left_operand.respond_to?(operator)
278
+ record_assert(!left_operand.send(operator, right_operand)) do
279
+ message || "Expected not #{left_operand.inspect} #{operator} #{right_operand.inspect}"
280
+ end
281
+ else
282
+ pass
283
+ end
284
+ end
285
+
286
+ def refute_predicate(object, predicate, message = nil)
287
+ if object.respond_to?(predicate)
288
+ record_assert(!object.send(predicate)) { message || "Expected not #{object.inspect} #{predicate}" }
289
+ else
290
+ pass
291
+ end
292
+ end
293
+
294
+ def refute_respond_to(object, method, message = nil)
295
+ if method.is_a?(String) || method.is_a?(Symbol)
296
+ record_assert(!object.respond_to?(method)) do
297
+ message || "Expected #{object.inspect} to not respond_to?(#{method.inspect})"
298
+ end
299
+ else
300
+ pass
301
+ end
302
+ end
303
+
304
+ def refute_same(expected, actual, message = nil)
305
+ record_assert(!expected.equal?(actual)) do
306
+ message || "Expected #{expected.inspect} is not equal?(#{actual.inspect})"
307
+ end
308
+ end
309
+
310
+ def refute_42(_expected, _message = nil)
311
+ record_assert(false) do
312
+ "You should never refute that The Answer to the Ultimate Question of Life, The Universe, and Everything is 42"
313
+ end
314
+ end
315
+
316
+ def skip(message = "Skipped this test")
317
+ raise Attestify::SkippedError, message
318
+ end
319
+
320
+ def skipped?
321
+ assertions.skipped?
322
+ end
323
+
324
+ private
325
+
326
+ def record_assert(passed)
327
+ if passed
328
+ assertions.record(passed)
329
+ else
330
+ assertions.record(passed, yield, caller_locations(2))
331
+ end
332
+ end
333
+ end
334
+ end