minitest-spec-expect 0.0.1 → 0.0.2
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/README.md +4 -0
- data/lib/minitest/spec/expect.rb +10 -12
- data/lib/minitest/spec/expect/version.rb +2 -6
- data/lib/minitest/spec/expect_syntax.rb +30 -43
- data/minitest-spec-expect.gemspec +3 -2
- metadata +2 -2
data/README.md
CHANGED
@@ -10,6 +10,10 @@ or from the command line:
|
|
10
10
|
```
|
11
11
|
$ gem install minitest-spec-expect
|
12
12
|
```
|
13
|
+
Then require it in the file that you require `minitest/autorun`:
|
14
|
+
```ruby
|
15
|
+
require 'minitest/spec/expect'
|
16
|
+
```
|
13
17
|
## Usage
|
14
18
|
Wrap the object under test in an `expect()` object. Then call a minitest expectation on it,
|
15
19
|
substituting `must` and `wont` with `to` and `to_not`.
|
data/lib/minitest/spec/expect.rb
CHANGED
@@ -1,23 +1,21 @@
|
|
1
1
|
module Kernel
|
2
2
|
def expect object
|
3
|
-
|
3
|
+
MiniTest::Spec::Expect.new object
|
4
4
|
end
|
5
5
|
end
|
6
6
|
|
7
|
-
|
8
|
-
class Spec
|
9
|
-
class Expect
|
10
|
-
require 'minitest/spec/expect_syntax'
|
7
|
+
require 'minitest/spec'
|
11
8
|
|
12
|
-
|
9
|
+
class MiniTest::Spec::Expect
|
10
|
+
require 'minitest/spec/expect_syntax'
|
13
11
|
|
14
|
-
|
12
|
+
OBJECT = 'object'
|
15
13
|
|
16
|
-
|
17
|
-
@object = object
|
18
|
-
end
|
14
|
+
attr_reader OBJECT.to_sym
|
19
15
|
|
20
|
-
|
21
|
-
|
16
|
+
def initialize object
|
17
|
+
@object = object
|
22
18
|
end
|
19
|
+
|
20
|
+
MiniTest::Spec::ExpectSyntax.new(self).set_expectations
|
23
21
|
end
|
@@ -1,56 +1,43 @@
|
|
1
|
-
|
1
|
+
class MiniTest::Spec::ExpectSyntax
|
2
|
+
TRANSPOSITIONS = {'must' => 'to', 'wont' => 'to_not'}
|
2
3
|
|
3
|
-
|
4
|
-
class Spec
|
5
|
-
class ExpectSyntax
|
6
|
-
TRANSPOSITIONS = {'must' => 'to', 'wont' => 'to_not'}
|
7
|
-
INTERESTING_AUXILIARY_VERB_REGEXES = [/must/, /wont/]
|
4
|
+
attr_reader :expect_class
|
8
5
|
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
6
|
+
def initialize expect_class
|
7
|
+
@expect_class = expect_class
|
8
|
+
end
|
20
9
|
|
21
|
-
|
10
|
+
def set_expectations
|
11
|
+
spec_expectation_names.each do |spec_expectation_name|
|
12
|
+
set_expectation spec_expectation_name
|
13
|
+
end
|
14
|
+
end
|
22
15
|
|
23
|
-
|
24
|
-
Object.instance_methods.select { |method_name| expectation? method_name }
|
25
|
-
end
|
16
|
+
private
|
26
17
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
31
|
-
end
|
18
|
+
def spec_expectation_names
|
19
|
+
MiniTest::Expectations.instance_methods
|
20
|
+
end
|
32
21
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
22
|
+
def set_expectation expectation_name
|
23
|
+
expect_class.class_eval <<-EOM
|
24
|
+
#{expect_method expectation_name }
|
25
|
+
EOM
|
26
|
+
end
|
38
27
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
end
|
44
|
-
"""
|
28
|
+
def expect_method expectation_name
|
29
|
+
"""
|
30
|
+
def #{expect_method_name expectation_name } *args
|
31
|
+
#{expect_class::OBJECT}.#{expectation_name} *args
|
45
32
|
end
|
33
|
+
"""
|
34
|
+
end
|
46
35
|
|
47
|
-
|
48
|
-
|
49
|
-
|
36
|
+
def expect_method_name expectation_name
|
37
|
+
TRANSPOSITIONS.inject('') do |memo, transposition|
|
38
|
+
string = memo.empty? ? expectation_name.to_s : memo
|
50
39
|
|
51
|
-
|
52
|
-
end
|
53
|
-
end
|
40
|
+
string.gsub transposition.first, transposition.last
|
54
41
|
end
|
55
42
|
end
|
56
43
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
3
|
$:.push File.expand_path("../lib", __FILE__)
|
4
|
+
require 'minitest/spec'
|
4
5
|
require 'minitest/spec/expect/version'
|
5
6
|
|
6
7
|
Gem::Specification.new do |s|
|
@@ -9,8 +10,8 @@ Gem::Specification.new do |s|
|
|
9
10
|
s.summary = 'Use the expect syntax with transposed minitest expectations.'
|
10
11
|
s.authors = ['Dave Jachimiak']
|
11
12
|
s.email = 'dave.jachimiak@gmail.com'
|
12
|
-
s.homepage = 'http://github.com/davejachimiak/minitest-expect'
|
13
|
-
s.version =
|
13
|
+
s.homepage = 'http://github.com/davejachimiak/minitest-spec-expect'
|
14
|
+
s.version = MiniTest::Spec::Expect::VERSION
|
14
15
|
s.files = `git ls-files`.split("\n").reject do |file_name|
|
15
16
|
/\.gem$/.match file_name
|
16
17
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minitest-spec-expect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -25,7 +25,7 @@ files:
|
|
25
25
|
- lib/minitest/spec/expect_syntax.rb
|
26
26
|
- minitest-spec-expect.gemspec
|
27
27
|
- spec/integration_spec.rb
|
28
|
-
homepage: http://github.com/davejachimiak/minitest-expect
|
28
|
+
homepage: http://github.com/davejachimiak/minitest-spec-expect
|
29
29
|
licenses: []
|
30
30
|
post_install_message:
|
31
31
|
rdoc_options: []
|