minitest-matchers 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.autotest ADDED
@@ -0,0 +1,26 @@
1
+ # -*- ruby -*-
2
+
3
+ require "autotest/restart"
4
+
5
+ Autotest.add_hook :initialize do |at|
6
+ at.testlib = "minitest/autorun"
7
+ at.add_exception "tmp"
8
+
9
+ # at.extra_files << "../some/external/dependency.rb"
10
+ #
11
+ # at.libs << ":../some/external"
12
+ #
13
+ # at.add_exception "vendor"
14
+ #
15
+ # at.add_mapping(/dependency.rb/) do |f, _|
16
+ # at.files_matching(/test_.*rb$/)
17
+ # end
18
+ #
19
+ # %w(TestA TestB).each do |klass|
20
+ # at.extra_class_map[klass] = "test/test_misc.rb"
21
+ # end
22
+ end
23
+
24
+ # Autotest.add_hook :run_command do |at|
25
+ # system "rake build"
26
+ # end
data/.gemtest ADDED
File without changes
data/History.txt ADDED
@@ -0,0 +1,6 @@
1
+ === 1.0.0 / 2011-08-30
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
data/Manifest.txt ADDED
@@ -0,0 +1,7 @@
1
+ .autotest
2
+ History.txt
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ lib/minitest/matchers.rb
7
+ test/test_minitest_matchers.rb
data/README.txt ADDED
@@ -0,0 +1,63 @@
1
+ = minitest-matchers
2
+
3
+ * http://github.com/zenspider/minitest-matchers
4
+
5
+ == DESCRIPTION:
6
+
7
+ minitest-matchers adds support for RSpec/Shoulda-style matchers to
8
+ MiniTest::Spec.
9
+
10
+ A matcher is a class that must implement #description and #matches?
11
+ methods. Expactations are then builded using these two methods.
12
+
13
+ == FEATURES/PROBLEMS:
14
+
15
+ * Enables you to define reusable matcher classes
16
+
17
+ == SYNOPSIS:
18
+
19
+ * see https://github.com/bcardarella/valid_attribute (support coming soon hopefully!)
20
+
21
+ class Post < ActiveRecord::Base
22
+ validates :title, :presence => true, :length => 4..20
23
+ end
24
+
25
+ describe Post do
26
+ subject { Post.new }
27
+
28
+ must { have_valid(:title).when("Hello") }
29
+ wont { have_valid(:title).when(nil, "", "Bad") }
30
+ end
31
+
32
+ == REQUIREMENTS:
33
+
34
+ * minitest > 2.5.0
35
+
36
+ == INSTALL:
37
+
38
+ * sudo gem install minitest-matchers
39
+
40
+ == LICENSE:
41
+
42
+ (The MIT License)
43
+
44
+ Copyright (c) Ryan Davis, seattle.rb, Wojciech Mach
45
+
46
+ Permission is hereby granted, free of charge, to any person obtaining
47
+ a copy of this software and associated documentation files (the
48
+ 'Software'), to deal in the Software without restriction, including
49
+ without limitation the rights to use, copy, modify, merge, publish,
50
+ distribute, sublicense, and/or sell copies of the Software, and to
51
+ permit persons to whom the Software is furnished to do so, subject to
52
+ the following conditions:
53
+
54
+ The above copyright notice and this permission notice shall be
55
+ included in all copies or substantial portions of the Software.
56
+
57
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
58
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
59
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
60
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
61
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
62
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
63
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ # -*- ruby -*-
2
+
3
+ require "rubygems"
4
+ require "hoe"
5
+
6
+ Hoe.plugin :minitest
7
+
8
+ Hoe.spec "minitest-matchers" do
9
+ developer "Ryan Davis", "ryand-ruby@zenspider.com"
10
+ developer "Wojciech Mach", "wojtek@wojtekmach.pl"
11
+ end
12
+
13
+ # vim: syntax=ruby
@@ -0,0 +1,55 @@
1
+ require "minitest/spec"
2
+
3
+ module MiniTest::Matchers
4
+ VERSION = "1.0.0"
5
+
6
+ def must &block
7
+ matcher = yield
8
+ check_matcher matcher
9
+
10
+ failure_message = if matcher.respond_to? :failure_message
11
+ matcher.failure_message
12
+ else
13
+ "expected to " + matcher.description
14
+ end
15
+
16
+ it "must #{matcher.description}" do
17
+ assert matcher.matches?(subject), failure_message
18
+ end
19
+
20
+ matcher
21
+ end
22
+
23
+ def wont &block
24
+ matcher = yield
25
+ check_matcher matcher
26
+
27
+ failure_message = if matcher.respond_to? :negative_failure_message
28
+ matcher.negative_failure_message
29
+ else
30
+ "expected not to " + matcher.description
31
+ end
32
+
33
+ it "wont #{matcher.description}" do
34
+ if matcher.respond_to? :does_not_match
35
+ assert matcher.does_not_match?(subject), failure_message
36
+ else
37
+ refute matcher.matches?(subject), failure_message
38
+ end
39
+ end
40
+
41
+ matcher
42
+ end
43
+
44
+ def check_matcher matcher
45
+ [:description, :matches?].each do |m|
46
+ if !matcher.respond_to?(m) || matcher.send(:description).nil?
47
+ fail "Matcher must respond to #{m}"
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ class MiniTest::Spec
54
+ extend MiniTest::Matchers
55
+ end
@@ -0,0 +1,82 @@
1
+ require "minitest/autorun"
2
+ require "minitest/matchers"
3
+
4
+ class BadMatcher; end
5
+
6
+ class KindOfMatcher
7
+ def initialize klass
8
+ @klass = klass
9
+ end
10
+
11
+ def description; "be kind of #{@klass}" end
12
+
13
+ def matches? subject; subject.kind_of? @klass end
14
+ end
15
+
16
+ class BadSpec < MiniTest::Spec; end
17
+ class GoodSpec < MiniTest::Spec
18
+ subject { [1, 2, 3] }
19
+ end
20
+
21
+ describe MiniTest::Matchers do
22
+ let(:bad_spec) { Class.new(BadSpec) }
23
+ let(:good_spec) { Class.new(GoodSpec) }
24
+
25
+ describe "check_matcher" do
26
+ it "requires spec to have subject" do
27
+ proc { bad_spec.must { BadMatcher.new } }.must_raise RuntimeError
28
+ end
29
+
30
+ it "requires matcher to have #description and #matches?" do
31
+ proc { good_spec.must { BadMatcher.new } }.must_raise RuntimeError
32
+ good_spec.must { KindOfMatcher.new(Object) }.must_be_kind_of KindOfMatcher
33
+ end
34
+ end
35
+
36
+ describe "must" do
37
+ subject do
38
+ Class.new(good_spec) do
39
+ must { KindOfMatcher.new String }
40
+ end
41
+ end
42
+
43
+ let(:spec) { subject.new "A spec" }
44
+
45
+ it "defines must expectation" do
46
+ subject.test_methods.grep(/must_be_kind_of/).size.must_equal 1
47
+ end
48
+
49
+ it "passes when matches" do
50
+ subject.send(:subject) { "hello" }
51
+ proc { spec.send subject.test_methods.first }
52
+ end
53
+
54
+ it "raises error when does not match" do
55
+ subject.send(:subject) { 1 }
56
+ proc { spec.send subject.test_methods.first }.must_raise MiniTest::Assertion
57
+ end
58
+ end
59
+
60
+ describe "wont" do
61
+ subject do
62
+ Class.new(good_spec) do
63
+ wont { KindOfMatcher.new String }
64
+ end
65
+ end
66
+ let(:spec) { subject.new "A spec" }
67
+
68
+ it "defines wont expectation" do
69
+ subject.test_methods.grep(/wont_be_kind_of/).size.must_equal 1
70
+ end
71
+
72
+ it "passes when does not match" do
73
+ subject.send(:subject) { 1 }
74
+ proc { spec.send subject.test_methods.first }
75
+ end
76
+
77
+ it "raises error when matches" do
78
+ subject.send(:subject) { "hello" }
79
+ proc { spec.send subject.test_methods.first }.must_raise MiniTest::Assertion
80
+ end
81
+ end
82
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: minitest-matchers
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ryan Davis
9
+ - Wojciech Mach
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2011-09-04 00:00:00.000000000Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: minitest
17
+ requirement: &2152311960 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: '1.6'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: *2152311960
26
+ - !ruby/object:Gem::Dependency
27
+ name: hoe
28
+ requirement: &2152303800 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '2.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: *2152303800
37
+ description: ! 'minitest-matchers adds support for RSpec/Shoulda-style matchers to
38
+
39
+ MiniTest::Spec.
40
+
41
+
42
+ A matcher is a class that must implement #description and #matches?
43
+
44
+ methods. Expactations are then builded using these two methods.'
45
+ email:
46
+ - ryand-ruby@zenspider.com
47
+ - wojtek@wojtekmach.pl
48
+ executables: []
49
+ extensions: []
50
+ extra_rdoc_files:
51
+ - History.txt
52
+ - Manifest.txt
53
+ - README.txt
54
+ files:
55
+ - .autotest
56
+ - History.txt
57
+ - Manifest.txt
58
+ - README.txt
59
+ - Rakefile
60
+ - lib/minitest/matchers.rb
61
+ - test/test_minitest_matchers.rb
62
+ - .gemtest
63
+ homepage: http://github.com/zenspider/minitest-matchers
64
+ licenses: []
65
+ post_install_message:
66
+ rdoc_options:
67
+ - --main
68
+ - README.txt
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project: minitest-matchers
85
+ rubygems_version: 1.8.7
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: minitest-matchers adds support for RSpec/Shoulda-style matchers to MiniTest::Spec
89
+ test_files:
90
+ - test/test_minitest_matchers.rb