minitest-great_expectations 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ *.idea
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.3
5
+ - jruby-18mode # JRuby in 1.8 mode
6
+ - jruby-19mode # JRuby in 1.9 mode
7
+ - rbx-18mode
8
+ - rbx-19mode
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Matthew McEachen
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Minitest::GreatExpectations [![Build Status](https://travis-ci.org/mceachen/minitest-great_expectations.png)](https://travis-ci.org/mceachen/minitest-great_expectations)
2
+
3
+ Adds several generally helpful assertions to minitest and minitest-spec that you might be used to
4
+ having, especially if you're coming from rspec:
5
+
6
+ ``` ruby
7
+ [1, 2, 3].must_equal_contents [3, 2, 1]
8
+ [1, 2, 3].must_include_all [1, 2]
9
+ something.works?.should_be_true
10
+ ```
11
+
12
+ These may make it into minitest proper, someday.
13
+
14
+ ## Installation
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ gem 'minitest-great_expectations'
19
+
20
+ And then execute:
21
+
22
+ $ bundle
23
+
24
+ ## Contributing
25
+
26
+ 1. Fork it
27
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
28
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
29
+ 4. Push to the branch (`git push origin my-new-feature`)
30
+ 5. Create new Pull Request
31
+
32
+ ## Changelog
33
+
34
+ ### 0.0.1
35
+
36
+ * First whack
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'yard'
4
+ YARD::Rake::YardocTask.new do |t|
5
+ t.files = ['lib/**/*.rb', 'README.md']
6
+ end
7
+
8
+ require 'rake/testtask'
9
+
10
+ Rake::TestTask.new do |t|
11
+ t.libs.push "lib"
12
+ t.libs.push "test"
13
+ t.pattern = 'test/**/*_test.rb'
14
+ t.verbose = true
15
+ end
16
+
17
+ task :default => :test
@@ -0,0 +1,65 @@
1
+ require "minitest-great_expectations/version"
2
+
3
+ module MiniTest::Assertions
4
+
5
+ # Contents must be the same, but order doesn't matter.
6
+ # (In rspec, this is ```.should =~```)
7
+ def assert_equal_contents(expected, actual, message = nil)
8
+ e_ary = expected.to_a
9
+ a_ary = actual.to_a
10
+ error_msgs = []
11
+ missing_from_actual = e_ary - a_ary
12
+ unless missing_from_actual.empty?
13
+ error_msgs << "Missing expected elements:\n #{mu_pp missing_from_actual}"
14
+ end
15
+ missing_from_expected = a_ary - e_ary
16
+ unless missing_from_expected.empty?
17
+ error_msgs << "Extraneous actual elements:\n #{mu_pp missing_from_expected}"
18
+ end
19
+ unless error_msgs.empty?
20
+ message ||= "Expected:\n #{mu_pp actual}\nto equal contents of:\n #{mu_pp expected}."
21
+ flunk("#{message}\n#{error_msgs.join("\n")}")
22
+ end
23
+ end
24
+
25
+ # Every element in actual must be in expected, but expected may have additional elements.
26
+ def assert_includes_all(expected, actual, message = nil)
27
+ missing_from_expected = expected.to_a - actual.to_a
28
+ unless missing_from_expected.empty?
29
+ message ||= "Expected:\n #{mu_pp actual}\nto contain every element in:\n #{mu_pp expected}."
30
+ flunk("#{message}\nMissing expected elements:\n #{mu_pp missing_from_expected}")
31
+ end
32
+ end
33
+
34
+ # The first parameter must be ```true```, not coercible to true.
35
+ def assert_true(obj, msg = nil)
36
+ msg = message(msg) { "<true> expected but was #{mu_pp obj}" }
37
+ assert obj == true, msg
38
+ end
39
+
40
+ def assert_truthy(obj, msg = nil)
41
+ msg = message(msg) { "Expected truthy, but was #{mu_pp obj}" }
42
+ assert obj, msg
43
+ end
44
+
45
+ # The first parameter must be ```false```, not just coercible to false.
46
+ def assert_false(obj, msg = nil)
47
+ msg = message(msg) { "<false> expected but was #{mu_pp obj}" }
48
+ assert obj == false, msg
49
+ end
50
+
51
+ def assert_falsy(obj, msg = nil)
52
+ msg = message(msg) { "Expected falsy but was #{mu_pp obj}" }
53
+ assert !obj, msg
54
+ end
55
+ end
56
+
57
+ module MiniTest::Expectations
58
+ infect_an_assertion :assert_equal_contents, :must_equal_contents
59
+ infect_an_assertion :assert_includes_all, :must_include_all
60
+ infect_an_assertion :assert_true, :must_be_true, :unary
61
+ infect_an_assertion :assert_truthy, :must_be_truthy, :unary
62
+ infect_an_assertion :assert_false, :must_be_false, :unary
63
+ infect_an_assertion :assert_falsy, :must_be_falsy, :unary
64
+ end
65
+
@@ -0,0 +1,5 @@
1
+ module Minitest
2
+ module GreatExpectations
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'minitest-great_expectations/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "minitest-great_expectations"
8
+ gem.version = Minitest::GreatExpectations::VERSION
9
+ gem.authors = ["Matthew McEachen"]
10
+ gem.email = ["matthew+github@mceachen.org"]
11
+ gem.description = %q{Adds several generally-useful matchers and expectations to minitest and minitest/spec}
12
+ gem.summary = gem.description
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^test/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_development_dependency 'rake'
21
+ gem.add_development_dependency 'yard'
22
+ gem.add_development_dependency 'minitest'
23
+ end
@@ -0,0 +1,197 @@
1
+ require 'minitest_helper'
2
+
3
+ describe "assert_equal_contents" do
4
+ it "passes for same order" do
5
+ a = [1, 2, 3]
6
+ b = a.dup
7
+ assert_equal_contents(a, b)
8
+ end
9
+ it "passes for different order" do
10
+ a = [1, 2, 3]
11
+ b = a.shuffle
12
+ assert_equal_contents(a, b)
13
+ end
14
+ it "complains about missing actual" do
15
+ l = lambda { assert_equal_contents([1, 2, 3], [1, 2]) }
16
+ error = assert_raises(MiniTest::Assertion, &l)
17
+ error.message.must_match /missing expected.*\[3\]/im
18
+ end
19
+ it "complains about extra actual" do
20
+ l = lambda { assert_equal_contents([1, 2], [1, 2, 3]) }
21
+ error = assert_raises(MiniTest::Assertion, &l)
22
+ error.message.must_match /extraneous actual.*\[3\]/im
23
+ end
24
+ end
25
+
26
+ describe "must_equal_contents" do
27
+ it "passes for same order" do
28
+ a = [1, 2, 3]
29
+ b = a.dup
30
+ a.must_equal_contents b
31
+ end
32
+ it "passes for different order" do
33
+ a = [1, 2, 3]
34
+ b = a.shuffle
35
+ a.must_equal_contents b
36
+ end
37
+ it "complains about missing actual" do
38
+ l = lambda { assert_equal_contents([1, 2, 3], [1, 2]) }
39
+ error = assert_raises(MiniTest::Assertion, &l)
40
+ error.message.must_match /missing expected.*\[3\]/im
41
+ end
42
+ it "complains about extra actual" do
43
+ l = lambda { assert_equal_contents([1, 2], [1, 2, 3]) }
44
+ error = assert_raises(MiniTest::Assertion, &l)
45
+ error.message.must_match /extraneous actual.*\[3\]/im
46
+ end
47
+ end
48
+
49
+ describe "assert_includes_all" do
50
+ it "passes on empty expected" do
51
+ assert_includes_all([], [])
52
+ assert_includes_all([], [1, 2, 3])
53
+ end
54
+ it "passes on non-empty exptected" do
55
+ assert_includes_all([1, 2], [1, 2, 3])
56
+ end
57
+ it "fails with missing expected" do
58
+ l = lambda { assert_includes_all([1, 2, 3], [1, 2]) }
59
+ error = assert_raises(MiniTest::Assertion, &l)
60
+ error.message.must_match /missing expected.*\[3\]/im
61
+ end
62
+ end
63
+
64
+ describe "must_include_all" do
65
+ it "passes on empty expected" do
66
+ [].must_include_all []
67
+ [1, 2, 3].must_include_all []
68
+ end
69
+ it "passes on non-empty exptected" do
70
+ [1, 2, 3].must_include_all [1, 2]
71
+ end
72
+ it "fails with missing expected" do
73
+ l = lambda { [1, 2].must_include_all [1, 2, 3] }
74
+ error = assert_raises(MiniTest::Assertion, &l)
75
+ error.message.must_match /missing expected.*\[3\]/im
76
+ end
77
+ end
78
+
79
+ describe "assert_true" do
80
+ #it "passes for true" do
81
+ # assert_true(true)
82
+ #end
83
+ #it "fails for truthy" do
84
+ # l = lambda { assert_true(1) }
85
+ # error = assert_raises(MiniTest::Assertion, &l)
86
+ # error.message.must_match /<true> expected/im
87
+ #end
88
+ end
89
+
90
+ describe "must_be_true" do
91
+ it "passes for true" do
92
+ true.must_be_true # < certainly my proudest coding moment
93
+ end
94
+ it "fails for truthy" do
95
+ l = lambda { 1.must_be_true }
96
+ error = assert_raises(MiniTest::Assertion, &l)
97
+ error.message.must_match /<true> expected/im
98
+ end
99
+ end
100
+
101
+ describe "assert_truthy" do
102
+ it "passes for truthy" do
103
+ assert_truthy(true)
104
+ assert_truthy(1)
105
+ assert_truthy("")
106
+ end
107
+
108
+ def assert_not_truthy(value)
109
+ l = lambda { assert_truthy(value) }
110
+ error = assert_raises(MiniTest::Assertion, &l)
111
+ error.message.must_match /Expected truthy/im
112
+ end
113
+
114
+ it "fails properly for falsy values" do
115
+ assert_not_truthy(false)
116
+ assert_not_truthy(nil)
117
+ end
118
+ end
119
+
120
+ describe "must_be_truthy" do
121
+ it "passes for truthy" do
122
+ true.must_be_truthy
123
+ 1.must_be_truthy
124
+ "".must_be_truthy
125
+ end
126
+
127
+ def assert_not_truthy(value)
128
+ l = lambda { assert_truthy(value) }
129
+ error = assert_raises(MiniTest::Assertion, &l)
130
+ error.message.must_match /Expected truthy/im
131
+ end
132
+
133
+ it "fails properly for falsy values" do
134
+ assert_not_truthy(false)
135
+ assert_not_truthy(nil)
136
+ end
137
+ end
138
+
139
+ describe "assert_false" do
140
+ it "passes for false" do
141
+ assert_false(false)
142
+ end
143
+ it "fails for falsy" do
144
+ l = lambda { assert_false(nil) }
145
+ error = assert_raises(MiniTest::Assertion, &l)
146
+ error.message.must_match /<false> expected/im
147
+ end
148
+ end
149
+
150
+ describe "must_be_false" do
151
+ it "passes for false" do
152
+ false.must_be_false
153
+ end
154
+ it "fails for falsy" do
155
+ l = lambda { nil.must_be_false }
156
+ error = assert_raises(MiniTest::Assertion, &l)
157
+ error.message.must_match /<false> expected/im
158
+ end
159
+ end
160
+
161
+ describe "assert_falsy" do
162
+ it "passes for falsy" do
163
+ assert_falsy(false)
164
+ assert_falsy(nil)
165
+ end
166
+
167
+ def assert_not_falsy(value)
168
+ l = lambda { assert_falsy(value) }
169
+ error = assert_raises(MiniTest::Assertion, &l)
170
+ error.message.must_match /Expected falsy/im
171
+ end
172
+
173
+ it "fails properly for falsy values" do
174
+ assert_not_falsy(true)
175
+ assert_not_falsy(1)
176
+ assert_not_falsy("")
177
+ end
178
+ end
179
+
180
+ describe "must_be_falsy" do
181
+ it "passes for falsy" do
182
+ false.must_be_falsy
183
+ nil.must_be_falsy
184
+ end
185
+
186
+ def assert_not_falsy(value)
187
+ l = lambda { assert_falsy(value) }
188
+ error = assert_raises(MiniTest::Assertion, &l)
189
+ error.message.must_match /Expected falsy/im
190
+ end
191
+
192
+ it "fails properly for falsy values" do
193
+ assert_not_falsy(true)
194
+ assert_not_falsy(1)
195
+ assert_not_falsy("")
196
+ end
197
+ end
@@ -0,0 +1,2 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest-great_expectations'
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: minitest-great_expectations
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Matthew McEachen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: yard
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: minitest
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Adds several generally-useful matchers and expectations to minitest and
63
+ minitest/spec
64
+ email:
65
+ - matthew+github@mceachen.org
66
+ executables: []
67
+ extensions: []
68
+ extra_rdoc_files: []
69
+ files:
70
+ - .gitignore
71
+ - .travis.yml
72
+ - Gemfile
73
+ - LICENSE.txt
74
+ - README.md
75
+ - Rakefile
76
+ - lib/minitest-great_expectations.rb
77
+ - lib/minitest-great_expectations/version.rb
78
+ - minitest-great_expectations.gemspec
79
+ - test/great_expectations_test.rb
80
+ - test/minitest_helper.rb
81
+ homepage: ''
82
+ licenses: []
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ segments:
94
+ - 0
95
+ hash: 3643161029749768267
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ segments:
103
+ - 0
104
+ hash: 3643161029749768267
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 1.8.23
108
+ signing_key:
109
+ specification_version: 3
110
+ summary: Adds several generally-useful matchers and expectations to minitest and minitest/spec
111
+ test_files:
112
+ - test/great_expectations_test.rb
113
+ - test/minitest_helper.rb
114
+ has_rdoc: