minitest-spec-expect 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ *.gem
data/README.md ADDED
@@ -0,0 +1,164 @@
1
+ # minitest-spec-expect
2
+ Expect syntax for [minitest](http://docs.seattlerb.org/minitest/index.html). Made out of love for
3
+ both rspec2's expect syntax and minitest's lightweight feel.
4
+ ## Install
5
+ In your Gemfile:
6
+ ```ruby
7
+ gem 'minitest-spec-expect'
8
+ ```
9
+ or from the command line:
10
+ ```
11
+ $ gem install minitest-spec-expect
12
+ ```
13
+ ## Usage
14
+ Wrap the object under test in an `expect()` object. Then call a minitest expectation on it,
15
+ substituting `must` and `wont` with `to` and `to_not`.
16
+
17
+ For example:
18
+ ```ruby
19
+ describe Integer do
20
+ describe '#+' do
21
+ it 'adds numbers correctly' do
22
+ expect(1 + 1).to_equal 2
23
+ end
24
+
25
+ it 'does not add numbers incorrectly' do
26
+ expect(1 + 1).to_not_equal 3
27
+ end
28
+ end
29
+ end
30
+ ```
31
+ That's equivalent to:
32
+ ```ruby
33
+ describe Integer do
34
+ describe '#+' do
35
+ it 'adds numbers correctly' do
36
+ (1 + 1).must_equal 2
37
+ end
38
+
39
+ it 'does not add numbers incorrectly' do
40
+ (1 + 1).wont_equal 3
41
+ end
42
+ end
43
+ end
44
+ ```
45
+ ## API
46
+ Please see the minitest [expectation](http://docs.seattlerb.org/minitest/Minitest/Expectations.html)
47
+ and [assertion](http://docs.seattlerb.org/minitest/Minitest/Assertions.html) docs for more details
48
+ on implementations for the `must` and `wont` methods transposed to `to` and `to_not` methods transposed
49
+ here.
50
+ ### `#*be`
51
+ ```ruby
52
+ expect(1).to_be :<, 2
53
+ expect(1).to_not_be :>, 2
54
+ ```
55
+ ### `#*be_close_to/#*be_within_delta`
56
+ ```ruby
57
+ expect(Math::PI).to_be_close_to 22.0/7.0, 0.01
58
+ expect(Math::PI).to_be_within_delta 22.0/7.0, 0.01
59
+ expect(Math::PI).to_not_be_close_to 22.0/6.0, 0.01
60
+ expect(Math::PI).to_not_be_within_delta 22.0/6.0, 0.01
61
+ ```
62
+ ### `#*be_empty`
63
+ ```ruby
64
+ expect([]).to_be_empty
65
+ expect({awwyeah: :minitest}).to_not_be_empty
66
+ ```
67
+ ### `#*be_instance_of`
68
+ ```ruby
69
+ expect([]).to_be_instance_of Array
70
+ expect([]).to_not_be_instance_of Hash
71
+ ```
72
+ ### `#*be_kind_of`
73
+ ```ruby
74
+ expect([]).to_be_kind_of Enumerable
75
+ expect([]).to_not_be_kind_of NilClass
76
+ ```
77
+ ### `#*be_nil`
78
+ ```ruby
79
+ expect(nil).to_be_nil
80
+ expect(:something).to_not_be_nil
81
+ ```
82
+ ### `#*be_same_as`
83
+ ```ruby
84
+ expect(obj = Object.new).to_be_same_as obj
85
+ an_object = Object.new
86
+ expect(Object.new).to_not_be_same_as an_object
87
+ ```
88
+ ### `#to_be_silent`
89
+ (`#must_be_silent` availble with Minitest 5.0)
90
+ ```ruby
91
+ expect(->{''}).to_be_silent
92
+ ```
93
+ ### `#*be_within_epsilon`
94
+ ```ruby
95
+ expect(4).to_be_within_epsilon 3.5, 0.15
96
+ expect(4).to_not_be_within_epsilon 3.5, 0.11
97
+ ```
98
+ ### `#*equal`
99
+ ```ruby
100
+ expect('4d3d3d3d').to_equal '4d3d3d3d'
101
+ expect('4d3d3d3d').to_not_equal 'tayne'
102
+ ```
103
+ ### `#*include`
104
+ ```ruby
105
+ expect(['tim', 'eric']).to_include 'eric'
106
+ expect(['tim', 'eric']).to_not_include 'brule'
107
+ ```
108
+ ### `#*match`
109
+ ```ruby
110
+ expect(/(fart)*/).to_match 'fartfartfartfart'
111
+ expect(/fart/).to_not_match 'barf'
112
+ ```
113
+ ### `#to_output`
114
+ (`#must_output` availble with Minitest 5.0)
115
+ ```ruby
116
+ expect(->{ puts 'barf' }).to_output "barf\n"
117
+ ```
118
+ ### `#to_raise`
119
+ ```ruby
120
+ expect(->{ raise RuntimeError }).to_raise RuntimeError
121
+ ```
122
+ ### `#*respond_to`
123
+ ```ruby
124
+ expect(Object.new).to_respond_to :must_respond_to
125
+ expect(Object.new).to_not_respond_to :fart_factory
126
+ ```
127
+ ### `#*throw`
128
+ ```ruby
129
+ expect(->{ throw StandardError }).to_throw StandardError
130
+ ```
131
+ ## Contribute
132
+ 1. Fork the repo.
133
+ 2. Create a branch.
134
+ 3. Make sure specs are green (`$ rake test`)
135
+ 3. Open a pull request.
136
+
137
+ ##### A note on the current specs
138
+ The specs at `spec/integration_spec.rb` test a couple of minitest expectations that aren't included
139
+ in previous minitest versions to 5.0. To install the newest minitest, do `$ sudo gem install
140
+ minitest`. Because of the way Ruby installs and loads its native libraries, `sudo` before
141
+ `gem install` is necessary, unfortunately.
142
+
143
+ ## License
144
+ The MIT License (MIT)
145
+
146
+ Copyright (c) 2013 Dave Jachimiak
147
+
148
+ Permission is hereby granted, free of charge, to any person obtaining a copy
149
+ of this software and associated documentation files (the "Software"), to deal
150
+ in the Software without restriction, including without limitation the rights
151
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
152
+ copies of the Software, and to permit persons to whom the Software is
153
+ furnished to do so, subject to the following conditions:
154
+
155
+ The above copyright notice and this permission notice shall be included in
156
+ all copies or substantial portions of the Software.
157
+
158
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
159
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
160
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
161
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
162
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
163
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
164
+ THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'rake/testtask'
2
+
3
+ desc 'run the tests'
4
+ Rake::TestTask.new do |t|
5
+ t.pattern = 'spec/integration_spec.rb'
6
+ end
@@ -0,0 +1,23 @@
1
+ module Kernel
2
+ def expect object
3
+ Minitest::Spec::Expect.new object
4
+ end
5
+ end
6
+
7
+ module Minitest
8
+ class Spec
9
+ class Expect
10
+ require 'minitest/spec/expect_syntax'
11
+
12
+ OBJECT = 'object'
13
+
14
+ attr_reader OBJECT.to_sym
15
+
16
+ def initialize object
17
+ @object = object
18
+ end
19
+
20
+ Minitest::Spec::ExpectSyntax.new(self).set_expectations
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,7 @@
1
+ module Minitest
2
+ class Spec
3
+ class Expect
4
+ VERSION = '0.0.1'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,57 @@
1
+ require 'minitest/spec'
2
+
3
+ module Minitest
4
+ class Spec
5
+ class ExpectSyntax
6
+ TRANSPOSITIONS = {'must' => 'to', 'wont' => 'to_not'}
7
+ INTERESTING_AUXILIARY_VERB_REGEXES = [/must/, /wont/]
8
+
9
+ attr_reader :expect_class
10
+
11
+ def initialize expect_class
12
+ @expect_class = expect_class
13
+ end
14
+
15
+ def set_expectations
16
+ spec_expectation_names.each do |spec_expectation_name|
17
+ set_expectation spec_expectation_name
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def spec_expectation_names
24
+ Object.instance_methods.select { |method_name| expectation? method_name }
25
+ end
26
+
27
+ def expectation? method_name
28
+ !!INTERESTING_AUXILIARY_VERB_REGEXES.detect do |regex|
29
+ method_name.to_s.match regex
30
+ end
31
+ end
32
+
33
+ def set_expectation expectation_name
34
+ expect_class.class_eval <<-EOM
35
+ #{expect_method expectation_name }
36
+ EOM
37
+ end
38
+
39
+ def expect_method expectation_name
40
+ """
41
+ def #{expect_method_name expectation_name } *args
42
+ #{expect_class::OBJECT}.#{expectation_name} *args
43
+ end
44
+ """
45
+ end
46
+
47
+ def expect_method_name expectation_name
48
+ TRANSPOSITIONS.inject('') do |memo, transposition|
49
+ string = memo.empty? ? expectation_name.to_s : memo
50
+
51
+ string.gsub transposition.first, transposition.last
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ $:.push File.expand_path("../lib", __FILE__)
4
+ require 'minitest/spec/expect/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'minitest-spec-expect'
8
+ s.description = 'Expect syntax for minitest specs.'
9
+ s.summary = 'Use the expect syntax with transposed minitest expectations.'
10
+ s.authors = ['Dave Jachimiak']
11
+ s.email = 'dave.jachimiak@gmail.com'
12
+ s.homepage = 'http://github.com/davejachimiak/minitest-expect'
13
+ s.version = Minitest::Spec::Expect::VERSION
14
+ s.files = `git ls-files`.split("\n").reject do |file_name|
15
+ /\.gem$/.match file_name
16
+ end
17
+ s.test_files = `git ls-files -- spec`.split("\n")
18
+ s.require_paths = ['lib']
19
+ end
@@ -0,0 +1,122 @@
1
+ $:.unshift File.expand_path("../../lib", __FILE__)
2
+
3
+ require 'minitest/spec/expect'
4
+ require 'minitest/autorun'
5
+
6
+ describe 'expect syntax' do
7
+ it 'supports must_be as to_be' do
8
+ expect(1).to_be :<, 2
9
+ end
10
+
11
+ it 'supports wont_be as to_not_be' do
12
+ expect(1).to_not_be :>, 2
13
+ end
14
+
15
+ it 'supports must_be_close_to as to_be_close_to (within_delta)' do
16
+ expect(Math::PI).to_be_close_to 22.0/7.0, 0.01
17
+ expect(Math::PI).to_be_within_delta 22.0/7.0, 0.01
18
+ end
19
+
20
+ it 'supports wont_be_close_to as to_not_be_close_to (within_delta)' do
21
+ expect(Math::PI).to_not_be_close_to 22.0/6.0, 0.01
22
+ expect(Math::PI).to_not_be_within_delta 22.0/6.0, 0.01
23
+ end
24
+
25
+ it 'supports must_be_empty as to_be_empty' do
26
+ expect([]).to_be_empty
27
+ end
28
+
29
+ it 'supports wont_be_empty as to_not_be_empty' do
30
+ expect({awwyeah: :minitest}).to_not_be_empty
31
+ end
32
+
33
+ it 'supports must_be_instance_of as to_be_instance_of' do
34
+ expect([]).to_be_instance_of Array
35
+ end
36
+
37
+ it 'supports wont_be_instance_of as to_not_be_instance_of' do
38
+ expect([]).to_not_be_instance_of Hash
39
+ end
40
+
41
+ it 'supports must_be_kind_of as to_be_kind_of' do
42
+ expect([]).to_be_kind_of Enumerable
43
+ end
44
+
45
+ it 'supports wont_be_kind_of as to_not_be_kind_of' do
46
+ expect([]).to_not_be_kind_of NilClass
47
+ end
48
+
49
+ it 'supports must_be_nil as to_be_nil' do
50
+ expect(nil).to_be_nil
51
+ end
52
+
53
+ it 'supports wont_be_nil as to_not_be_nil' do
54
+ expect(:something).to_not_be_nil
55
+ end
56
+
57
+ it 'supports must_be_same_as as to_be_same_as' do
58
+ expect(obj = Object.new).to_be_same_as obj
59
+ end
60
+
61
+ it 'supports wont_be_same_as as to_not_be_same_as' do
62
+ object_one = Object.new
63
+
64
+ expect(Object.new).to_not_be_same_as object_one
65
+ end
66
+
67
+ it 'supports must_be_silent as to_be_silent' do
68
+ expect(->{''}).to_be_silent
69
+ end
70
+
71
+ it 'supports must_be_within_epsilon as to_be_within_epsilon' do
72
+ expect(4).to_be_within_epsilon 3.5, 0.15
73
+ end
74
+
75
+ it 'supports wont_be_within_epsilon as to_not_be_within_epsilon' do
76
+ expect(4).to_not_be_within_epsilon 3.5, 0.11
77
+ end
78
+
79
+ it 'supports must_equal as to_equal' do
80
+ expect('4d3d3d3d').to_equal '4d3d3d3d'
81
+ end
82
+
83
+ it 'supports wont_equal as to_not_equal' do
84
+ expect('4d3d3d3d').to_not_equal 'tayne'
85
+ end
86
+
87
+ it 'supports must_include as to_include' do
88
+ expect(['tim', 'eric']).to_include 'eric'
89
+ end
90
+
91
+ it 'supports wont_include as to_not_include' do
92
+ expect(['tim', 'eric']).to_not_include 'brule'
93
+ end
94
+
95
+ it 'supports must_match as to_match' do
96
+ expect(/(fart)*/).to_match 'fartfartfartfart'
97
+ end
98
+
99
+ it 'supports wont_match as to_not_match' do
100
+ expect(/fart/).to_not_match 'barf'
101
+ end
102
+
103
+ it 'supports must_output as to_output' do
104
+ expect(->{ puts 'barf' }).to_output "barf\n"
105
+ end
106
+
107
+ it 'supports must_raise as to_raise' do
108
+ expect(->{ raise RuntimeError }).to_raise RuntimeError
109
+ end
110
+
111
+ it 'supports must_respond_to as to_respond_to' do
112
+ expect(Object.new).to_respond_to :must_respond_to
113
+ end
114
+
115
+ it 'supports wont_respond_to as to_not_respond_to' do
116
+ expect(Object.new).to_not_respond_to :fart_factory
117
+ end
118
+
119
+ it 'supports must_throw as to_throw' do
120
+ expect(->{ throw StandardError }).to_throw StandardError
121
+ end
122
+ end
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: minitest-spec-expect
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Dave Jachimiak
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-16 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Expect syntax for minitest specs.
15
+ email: dave.jachimiak@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - .gitignore
21
+ - README.md
22
+ - Rakefile
23
+ - lib/minitest/spec/expect.rb
24
+ - lib/minitest/spec/expect/version.rb
25
+ - lib/minitest/spec/expect_syntax.rb
26
+ - minitest-spec-expect.gemspec
27
+ - spec/integration_spec.rb
28
+ homepage: http://github.com/davejachimiak/minitest-expect
29
+ licenses: []
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ requirements: []
47
+ rubyforge_project:
48
+ rubygems_version: 1.8.25
49
+ signing_key:
50
+ specification_version: 3
51
+ summary: Use the expect syntax with transposed minitest expectations.
52
+ test_files:
53
+ - spec/integration_spec.rb