minitest-matchers_vaccine 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4e677b775a9ec040f8d9d706b2452d21170435f2
4
+ data.tar.gz: f4ba7684cad0e2bbaf7d88fc851a81bd0d07de83
5
+ SHA512:
6
+ metadata.gz: 41cffe4d9b92720a6663f0295f6ad8eb4742292bead75e859b4630a8845d6c66c027fe9c59c806e6ccadcace2d3286befa3a7331a045988842e0d387cc08602b
7
+ data.tar.gz: f2fbf63c98625915e1c31b817c0e85366b8c134630c874cd9295a47a3d11ad6485778c5b2b792319f43093429fb49f3fe842e0aae81e1a2278011b73e2a6c188
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Ryan McGeary
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,130 @@
1
+ # Minitest::MatchersVaccine [![Gem Version](http://img.shields.io/gem/v/minitest-matchers_vaccine.svg)](https://rubygems.org/gems/minitest-matchers_vaccine) [![Build Status](https://secure.travis-ci.org/rmm5t/minitest-matchers_vaccine.svg)](http://travis-ci.org/rmm5t/minitest-matchers_vaccine) [![Code Climate](http://img.shields.io/codeclimate/github/rmm5t/minitest-matchers_vaccine.svg)](https://codeclimate.com/github/rmm5t/minitest-matchers_vaccine)
2
+
3
+ Adds matcher support to minitest without all the other RSpec-style expectation
4
+ _infections_.
5
+
6
+ Using matchers with RSpec-style expectations requires that we _infect_ the
7
+ objects that we are testing with new methods. Matcher implementations are
8
+ typically overkill, but there are a lot of good testing libraries that still
9
+ insist on standardizing on matchers. These matchers still have some value, and
10
+ this gem tries to extract that value with straight-forward assertions that
11
+ adhere to the matcher spec.
12
+
13
+ **Why not use
14
+ [minitest-matchers](https://github.com/wojtekmach/minitest-matchers)?** This
15
+ gem is actually heavily inspired by and based upon the assertions in
16
+ minitest-matchers; however, everything else that minitest-matchers brings to
17
+ the table is unnecessary unless you're bent on a true RSpec-style syntax.
18
+
19
+ ## How You Can Help
20
+
21
+ **If you like this project, please help. [Donate via Gittip][gittip] or [buy me a coffee with Bitcoin][bitcoin].**<br>
22
+ [![Gittip](http://img.shields.io/gittip/rmm5t.svg)][gittip]
23
+ [![Bitcoin](http://img.shields.io/badge/bitcoin-buy%20me%20a%20coffee-brightgreen.svg)][bitcoin]
24
+
25
+ **[Bitcoin][bitcoin]**: `1rmm5tv6f997JK5bLcGbRCZyVjZUPkQ2m`<br>
26
+ [![Bitcoin Donation][bitcoin-qr-small]][bitcoin-qr-big]
27
+
28
+ ## Need Help?
29
+
30
+ **You can [book a session with me on Codementor][codementor].**<br>
31
+ [![Book a Codementor session](http://img.shields.io/badge/codementor-book%20a%20session-orange.svg)][codementor]
32
+
33
+ [gittip]: https://www.gittip.com/rmm5t/ "Donate to rmm5t for open source!"
34
+ [bitcoin]: https://blockchain.info/address/1rmm5tv6f997JK5bLcGbRCZyVjZUPkQ2m "Buy rmm5t a coffee for open source!"
35
+ [bitcoin-scheme]: bitcoin:1rmm5tv6f997JK5bLcGbRCZyVjZUPkQ2m?amount=0.01&label=Coffee%20to%20rmm5t%20for%20Open%20Source "Buy rmm5t a coffee for open source!"
36
+ [bitcoin-qr-small]: http://chart.apis.google.com/chart?cht=qr&chs=150x150&chl=bitcoin%3A1rmm5tv6f997JK5bLcGbRCZyVjZUPkQ2m%3Famount%3D0.01%26label%3DCoffee%2520to%2520rmm5t%2520for%2520Open%2520Source
37
+ [bitcoin-qr-big]: http://chart.apis.google.com/chart?cht=qr&chs=500x500&chl=bitcoin%3A1rmm5tv6f997JK5bLcGbRCZyVjZUPkQ2m%3Famount%3D0.01%26label%3DCoffee%2520to%2520rmm5t%2520for%2520Open%2520Source
38
+ [codementor]: https://www.codementor.io/rmm5t?utm_campaign=profile&utm_source=button-rmm5t&utm_medium=shields "Book a session with rmm5t on Codementor!"
39
+
40
+ ## Installation
41
+
42
+ Add this line to your application's Gemfile:
43
+
44
+ gem "minitest-matchers_vaccine"
45
+
46
+ And then execute:
47
+
48
+ $ bundle
49
+
50
+ Or install it yourself as:
51
+
52
+ $ gem install minitest-matchers_vaccine
53
+
54
+ ## Usage
55
+
56
+ Includes both `assert_must` and `assert_wont` assertions, but also includes
57
+ `must` and `wont` facilitator assertions that automatically default to
58
+ using the current `subject` method or `@subject` instance variable.
59
+
60
+ **NOTE:** This gem does not allow matchers to be used with an expectation
61
+ syntax. Let's avoid infecting the objects we're testing.
62
+
63
+ ### MiniTest::Test
64
+
65
+ ```ruby
66
+ class UserTest < Minitest::Test
67
+ def setup
68
+ @subject = User.new
69
+ end
70
+
71
+ def test_fields_and_associations
72
+ must have_db_column :name
73
+ must belong_to :account
74
+ assert_must have_many(:widgets), @subject
75
+ end
76
+
77
+ def test_validations
78
+ must have_valid(:email).when("a@a.com", "foo@bar.com", "dave@abc.io")
79
+ wont have_valid(:email).when(nil, "foo", "foo@bar", "@bar.com")
80
+ end
81
+
82
+ # Works with matchers in other libs
83
+ def test_stripping
84
+ assert_must strip_attribute(:name), User.new
85
+ end
86
+ end
87
+ ```
88
+
89
+ ### MiniTest::Spec
90
+
91
+ ```ruby
92
+ describe User do
93
+ subject { User.new }
94
+
95
+ # Works with shoulda-matchers
96
+ it "should have fields and association" do
97
+ must have_db_column :name
98
+ must belong_to :account
99
+ must have_many :widgets
100
+ end
101
+
102
+ # Works with valid_attribute
103
+ it "should validate" do
104
+ must have_valid(:email).when("a@a.com", "foo@bar.com", "dave@abc.io")
105
+ wont have_valid(:email).when(nil, "foo", "foo@bar", "@bar.com")
106
+ end
107
+
108
+ # Works with matchers in other libs
109
+ it "should strip attributes" do
110
+ must strip_attribute :name
111
+ end
112
+ end
113
+ ```
114
+
115
+ ## Contributing
116
+
117
+ 1. Fork it ( https://github.com/rmm5t/minitest-matchers_vaccine/fork )
118
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
119
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
120
+ 4. Push to the branch (`git push origin my-new-feature`)
121
+ 5. Create a new Pull Request
122
+
123
+ ## Credits
124
+
125
+ The idea was originally inspired by the assertions implementation in [minitest-matchers](https://github.com/wojtekmach/minitest-matchers).
126
+
127
+ ## License
128
+
129
+ Copyright (c) 2014 Ryan McGeary released under the [MIT
130
+ license](http://en.wikipedia.org/wiki/MIT_License)
@@ -0,0 +1,5 @@
1
+ module Minitest
2
+ module MatchersVaccine
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,86 @@
1
+ require "minitest/matchers_vaccine/version"
2
+
3
+ # Borrowed and modified from minitest-matchers, but we don't need all the
4
+ # other RSpec-style expectation "infections."
5
+ module MiniTest
6
+ module Assertions
7
+ ##
8
+ # Passes if matcher.matches?(subject) returns true
9
+ #
10
+ # Example:
11
+ #
12
+ # def test_validations
13
+ # assert_must be_valid, @user
14
+ # end
15
+ def assert_must(matcher, subject, msg = nil)
16
+ msg = message(msg) do
17
+ if matcher.respond_to? :failure_message
18
+ matcher.failure_message # RSpec 3.x, 1.1
19
+ else
20
+ matcher.failure_message_for_should # RSpec 2.x, 1.2
21
+ end
22
+ end
23
+
24
+ assert matcher.matches?(subject), msg
25
+ end
26
+
27
+ ##
28
+ # Facilitator to assert_must for use with minitest-spec. If no subject
29
+ # given, defaults to matching against the current `subject` or the
30
+ # instance variable `@subject`.
31
+ #
32
+ # Example:
33
+ #
34
+ # subject { Order.new }
35
+ #
36
+ # it "should have associations" do
37
+ # must belong_to :account
38
+ # must have_many :line_items
39
+ # end
40
+ def must(matcher, subject = @subject || subject, msg = nil)
41
+ assert_must matcher, subject, msg
42
+ end
43
+
44
+ ##
45
+ # Passes if matcher.matches?(subject) returns false
46
+ #
47
+ # Example:
48
+ #
49
+ # def test_validations
50
+ # assert_wont be_valid, @user
51
+ # end
52
+ def assert_wont(matcher, subject, msg = nil)
53
+ msg = message(msg) do
54
+ if matcher.respond_to? :failure_message_when_negated # RSpec 3.x
55
+ matcher.failure_message_when_negated # RSpec 3.x
56
+ elsif matcher.respond_to? :failure_message_for_should_not
57
+ matcher.failure_message_for_should_not # RSpec 2.x, 1.2
58
+ else
59
+ matcher.negative_failure_message # RSpec 1.1
60
+ end
61
+ end
62
+
63
+ if matcher.respond_to? :does_not_match?
64
+ assert matcher.does_not_match?(subject), msg
65
+ else
66
+ refute matcher.matches?(subject), msg
67
+ end
68
+ end
69
+
70
+ ##
71
+ # Facilitator to assert_wont for use with minitest-spec. If no subject
72
+ # given, defaults to matching against the current `subject` or the
73
+ # instance variable `@subject`.
74
+ #
75
+ # Example:
76
+ #
77
+ # subject { User.new }
78
+ #
79
+ # it "should validate" do
80
+ # wont have_valid(:email).when("foo", "foo@bar", "@bar.com")
81
+ # end
82
+ def wont(matcher, subject = @subject || subject, msg = nil)
83
+ assert_wont matcher, subject, msg
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,131 @@
1
+ require "minitest/autorun"
2
+ require "minitest/matchers_vaccine"
3
+
4
+ module InstanceOf
5
+ def be_instance_of klass
6
+ Matcher.new klass
7
+ end
8
+
9
+ class Matcher
10
+ def initialize klass
11
+ @klass = klass
12
+ end
13
+
14
+ def description
15
+ "be instance of #{@klass}"
16
+ end
17
+
18
+ def matches? subject
19
+ @subject = subject
20
+ @subject.instance_of? @klass
21
+ end
22
+
23
+ def failure_message
24
+ "expected to " + description
25
+ end
26
+
27
+ def failure_message_when_negated
28
+ "expected not to " + description
29
+ end
30
+ end
31
+ end
32
+
33
+ describe "#assert_must" do
34
+ include InstanceOf
35
+
36
+ it "should be capable of passing" do
37
+ assert_equal true, assert_must(be_instance_of(Array), [:hello])
38
+ assert_equal true, assert_must(be_instance_of(String), "hello")
39
+ end
40
+
41
+ it "should be capable of failing" do
42
+ assert_raises(Minitest::Assertion) { assert_must(be_instance_of(String), [:hello]) }
43
+ assert_raises(Minitest::Assertion) { assert_must(be_instance_of(Array), "hello") }
44
+ end
45
+ end
46
+
47
+ describe "#assert_wont" do
48
+ include InstanceOf
49
+
50
+ it "should be capable of passing" do
51
+ assert_equal false, assert_wont(be_instance_of(String), [:hello])
52
+ assert_equal false, assert_wont(be_instance_of(Array), "hello")
53
+ end
54
+
55
+ it "should be capable of failing" do
56
+ assert_raises(Minitest::Assertion) { assert_wont(be_instance_of(Array), [:hello]) }
57
+ assert_raises(Minitest::Assertion) { assert_wont(be_instance_of(String), "hello") }
58
+ end
59
+ end
60
+
61
+ describe "#must" do
62
+ include InstanceOf
63
+
64
+ describe "given a subject" do
65
+ subject { [:hello] }
66
+
67
+ it "should be capable of passing" do
68
+ assert_equal true, must(be_instance_of(Array))
69
+ end
70
+
71
+ it "should be capable of failing" do
72
+ assert_raises(Minitest::Assertion) { must be_instance_of String }
73
+ end
74
+ end
75
+
76
+ describe "given a @subject" do
77
+ before do
78
+ @subject = "hello"
79
+ end
80
+
81
+ it "should be capable of passing" do
82
+ assert_equal true, must(be_instance_of(String))
83
+ end
84
+
85
+ it "should be capable of failing" do
86
+ assert_raises(Minitest::Assertion) { must be_instance_of Array }
87
+ end
88
+ end
89
+
90
+ describe "without a subject" do
91
+ it "should error" do
92
+ assert_raises(NameError) { must be_instance_of Array }
93
+ end
94
+ end
95
+ end
96
+
97
+ describe "#wont" do
98
+ include InstanceOf
99
+
100
+ describe "given a subject" do
101
+ subject { [:hello] }
102
+
103
+ it "should be capable of passing" do
104
+ assert_equal false, wont(be_instance_of(String))
105
+ end
106
+
107
+ it "should be capable of failing" do
108
+ assert_raises(Minitest::Assertion) { wont be_instance_of Array }
109
+ end
110
+ end
111
+
112
+ describe "given a @subject" do
113
+ before do
114
+ @subject = "hello"
115
+ end
116
+
117
+ it "should be capable of passing" do
118
+ assert_equal false, wont(be_instance_of(Array))
119
+ end
120
+
121
+ it "should be capable of failing" do
122
+ assert_raises(Minitest::Assertion) { wont be_instance_of String }
123
+ end
124
+ end
125
+
126
+ describe "without a subject" do
127
+ it "should error" do
128
+ assert_raises(NameError) { wont be_instance_of Array }
129
+ end
130
+ end
131
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: minitest-matchers_vaccine
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Ryan McGeary
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minitest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.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.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Adds matcher support to minitest without all the other RSpec-style expectation
56
+ "infections."
57
+ email:
58
+ - ryan@mcgeary.org
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - LICENSE.txt
64
+ - README.md
65
+ - lib/minitest/matchers_vaccine.rb
66
+ - lib/minitest/matchers_vaccine/version.rb
67
+ - test/matchers_test.rb
68
+ homepage: https://github.com/rmm5t/minitest-matchers_vaccine
69
+ licenses:
70
+ - MIT
71
+ metadata: {}
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '1.9'
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubyforge_project:
88
+ rubygems_version: 2.2.2
89
+ signing_key:
90
+ specification_version: 4
91
+ summary: Adds support for RSpec-style matchers to minitest.
92
+ test_files:
93
+ - test/matchers_test.rb