petitest-assertions 0.2.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: 45c6d34b569274c63497613ec7e8ec3e76527f74
4
+ data.tar.gz: 11f253d0ecc8388344ec76f5bf53e6b153ca4ee7
5
+ SHA512:
6
+ metadata.gz: 1269a014eff1108750de8248636a93f8f68264ce0edd047a92c06e3fbcf445500aae306845dddb9dde81d6846459605abd2bbee083a12425c92600dd1b92a2be
7
+ data.tar.gz: 868c0fa52319aa73dbfce9df502574f764907a3629409056261494c893816845a50387c9a6aee1f2c5caef8e33472dff6737ef6893aa2c21b2e66e935ea7044e
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
@@ -0,0 +1,3 @@
1
+ ## v0.2.0
2
+
3
+ - 1st Release :tada:
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in petitest-assertions.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Ryo Nakamura
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,107 @@
1
+ # Petitest::Assertions
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/petitest-assertions.svg)](https://rubygems.org/gems/petitest-assertions)
4
+ [![Documentation](http://img.shields.io/badge/docs-rdoc.info-blue.svg)](http://www.rubydoc.info/github/petitest/petitest-assertions)
5
+
6
+ Assertions for [Petitest](https://github.com/petitest/petitest-assertions).
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem "petitest-assertions"
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ ```bash
19
+ bundle
20
+ ```
21
+
22
+ Or install it yourself as:
23
+
24
+ ```bash
25
+ gem install petitest-assertions
26
+ ```
27
+
28
+ ## Usage
29
+
30
+ ### Setup
31
+
32
+ 1. Require `"petitest/assertions"`
33
+ 2. Include `Petitest::Assertions` into your test groups
34
+
35
+ ```ruby
36
+ require "petitest/autorun"
37
+ require "petitest/assertions"
38
+
39
+ class ExampleTest < Petitest::TestGroup
40
+ include ::Petitest::Assertions
41
+
42
+ # ... test cases ...
43
+ end
44
+ ```
45
+
46
+ ### assert_equal
47
+
48
+ ```ruby
49
+ assert_equal(2, 1 + 1)
50
+ ```
51
+
52
+ ### assert_match
53
+
54
+ ```ruby
55
+ assert_match(/foo/, "fooooo")
56
+ ```
57
+
58
+ ### assert_operator
59
+
60
+ ```ruby
61
+ assert_operator(2, :>, 1)
62
+ ```
63
+
64
+ ### assert_output
65
+
66
+ ```ruby
67
+ assert_output(/foo/, nil) do
68
+ puts "fooooo"
69
+ end
70
+ ```
71
+
72
+ ### assert_output
73
+
74
+ ```ruby
75
+ assert_output(nil, /foo/) do
76
+ $stdout.puts "fooooo"
77
+ end
78
+ ```
79
+
80
+ ### assert_output
81
+
82
+ ```ruby
83
+ assert_output(/foo/, /bar/) do
84
+ puts "fooooo"
85
+ $stdout.puts "barrrr"
86
+ end
87
+ ```
88
+
89
+ ### assert_raise
90
+
91
+ ```ruby
92
+ assert_raise(::StandardError) do
93
+ raise
94
+ end
95
+ ```
96
+
97
+ ### assert_to_be
98
+
99
+ ```ruby
100
+ assert_to_be(:empty, [])
101
+ ```
102
+
103
+ ### assert_to_have
104
+
105
+ ```ruby
106
+ assert_to_have(:key, :foo, foo: :bar)
107
+ ```
@@ -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,125 @@
1
+ require "petitest"
2
+ require "petitest/assertions/version"
3
+ require "stringio"
4
+
5
+ module Petitest
6
+ module Assertions
7
+ # @param expected [#==]
8
+ # @param actual [Object]
9
+ # @param message [String, nil]
10
+ def assert_equal(expected, actual, message = nil)
11
+ message ||= "Expected #{expected.inspect} to be equal to #{actual.inspect}"
12
+ assert(message) do
13
+ expected == actual
14
+ end
15
+ end
16
+
17
+ # @param expected [#===]
18
+ # @param actual [Object]
19
+ # @param message [String, nil]
20
+ def assert_match(expected, actual, message = nil)
21
+ message ||= "Expected #{expected.inspect} === #{actual.inspect}"
22
+ assert(message) do
23
+ expected === actual
24
+ end
25
+ end
26
+
27
+ # @param left [Object]
28
+ # @param operator [Symbol]
29
+ # @param right [Object]
30
+ def assert_operator(left, operator, right, message = nil)
31
+ message ||= "Expected #{left.inspect} #{operator} #{right.inspect}"
32
+ assert(message) do
33
+ left.__send__(operator, right)
34
+ end
35
+ end
36
+
37
+ # @param pattern_for_stdout [#===, nil]
38
+ # @param pattern_for_stderr [#===, nil]
39
+ # @param right [Object]
40
+ def assert_output(pattern_for_stdout, pattern_for_stderr = nil, message = nil, &block)
41
+ output_from_stdout, output_from_stderr = capture_stdout_and_stderr(&block)
42
+ unless pattern_for_stdout.nil?
43
+ assert(message || "Expected stdout output to match with #{pattern_for_stdout.inspect}") do
44
+ pattern_for_stdout === output_from_stdout
45
+ end
46
+ end
47
+ unless pattern_for_stdout.nil?
48
+ assert(message || "Expected stderr output to match with #{pattern_for_stdout.inspect}") do
49
+ pattern_for_stdout === output_from_stdout
50
+ end
51
+ end
52
+ end
53
+
54
+ # @param args [Array<Class, String>]
55
+ def assert_raise(*args, &block)
56
+ message = args.pop if args.last.is_a?(::String)
57
+ expected_exception_classes = args
58
+ expected_exception_classes << ::Exception if expected_exception_classes.empty?
59
+ expected_exception_classes_text = expected_exception_classes.map(&:inspect).join(" or ")
60
+ message ||= "Expected #{expected_exception_classes_text} to be raised, but not"
61
+ assert(message) do
62
+ actual = begin
63
+ block.call
64
+ nil
65
+ rescue *expected_exception_classes => exception
66
+ exception
67
+ rescue ::SignalException, ::SystemExit
68
+ raise
69
+ rescue ::Exception => exception
70
+ exception
71
+ end
72
+ expected_exception_classes.any? do |klass|
73
+ klass === actual
74
+ end
75
+ end
76
+ end
77
+
78
+ # @param phrase [Symbol]
79
+ # @param args [Array]
80
+ def assert_to_be(phrase, *args)
81
+ actual = args.pop
82
+ method_name = "#{phrase}?"
83
+ args_text = "(#{args.map(&:inspect).join(', ')})" unless args.empty?
84
+ message = "Expected #{actual.inspect}.#{method_name}#{args_text} to be truthy"
85
+ assert(message) do
86
+ actual.__send__(method_name, *args)
87
+ end
88
+ end
89
+
90
+ # @param phrase [Symbol]
91
+ # @param args [Array]
92
+ def assert_to_have(phrase, *args)
93
+ actual = args.pop
94
+ method_name = "has_#{phrase}?"
95
+ args_text = "(#{args.map(&:inspect).join(', ')})" unless args.empty?
96
+ message = "Expected #{actual.inspect}.#{method_name}#{args_text} to be truthy"
97
+ assert(message) do
98
+ actual.__send__(method_name, *args)
99
+ end
100
+ end
101
+
102
+ private
103
+
104
+ # @return [Array<String>]
105
+ def capture_stdout_and_stderr(&block)
106
+ dummy_stdout = ::StringIO.new
107
+ dummy_stderr = ::StringIO.new
108
+ original_stdout = $stdout
109
+ original_stderr = $stderr
110
+ $stdout = dummy_stdout
111
+ $stderr = dummy_stderr
112
+ block.call
113
+ [
114
+ dummy_stdout.string,
115
+ dummy_stderr.string,
116
+ ]
117
+ ensure
118
+ $stdout = original_stdout
119
+ $stderr = original_stderr
120
+ end
121
+ end
122
+ end
123
+
124
+ path = ::File.expand_path("../..", __FILE__)
125
+ ::Petitest.configuration.backtrace_filters << -> (line) { line.start_with?(path) }
@@ -0,0 +1,5 @@
1
+ module Petitest
2
+ module Assertions
3
+ VERSION = "0.2.0"
4
+ end
5
+ end
@@ -0,0 +1,22 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "petitest/assertions/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "petitest-assertions"
7
+ spec.version = Petitest::Assertions::VERSION
8
+ spec.authors = ["Ryo Nakamura"]
9
+ spec.email = ["r7kamura@gmail.com"]
10
+ spec.summary = "Assertions for Petitest."
11
+ spec.homepage = "https://github.com/petitest/petitest-assertions"
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
15
+ f.match(%r{^(test|spec|features)/})
16
+ end
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_dependency "petitest", ">= 0.2.0"
20
+ spec.add_development_dependency "bundler", "~> 1.14"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: petitest-assertions
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Ryo Nakamura
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-03-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: petitest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.2.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.14'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.14'
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
+ description:
56
+ email:
57
+ - r7kamura@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - CHANGELOG.md
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - lib/petitest/assertions.rb
69
+ - lib/petitest/assertions/version.rb
70
+ - petitest-assertions.gemspec
71
+ homepage: https://github.com/petitest/petitest-assertions
72
+ licenses:
73
+ - MIT
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.5.2
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: Assertions for Petitest.
95
+ test_files: []