mcmire-matchy 0.5.0 → 0.5.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/lib/matchy.rb +7 -4
- data/lib/matchy/assertions.rb +16 -0
- data/lib/matchy/expectation_builder.rb +8 -4
- data/lib/matchy/matcher_builder.rb +1 -9
- data/lib/matchy/version.rb +1 -1
- metadata +2 -1
data/lib/matchy.rb
CHANGED
@@ -74,6 +74,7 @@ module Matchy
|
|
74
74
|
end
|
75
75
|
|
76
76
|
def init
|
77
|
+
require 'matchy/assertions'
|
77
78
|
require 'matchy/expectation_builder'
|
78
79
|
require 'matchy/modals'
|
79
80
|
require 'matchy/matcher_builder'
|
@@ -86,9 +87,12 @@ module Matchy
|
|
86
87
|
require 'matchy/built_in/operator_expectations'
|
87
88
|
require 'matchy/built_in/change_expectations'
|
88
89
|
|
89
|
-
# Track the current testcase and
|
90
|
-
# provide it to the operator matchers.
|
91
90
|
Matchy.test_case_class.class_eval do
|
91
|
+
include Matchy::Expectations::TestCaseExtensions
|
92
|
+
include Matchy::Assertions
|
93
|
+
|
94
|
+
# Track the current testcase and
|
95
|
+
# provide it to the operator matchers.
|
92
96
|
alias_method :old_run_method_aliased_by_matchy, :run
|
93
97
|
def run(whatever, *args, &block)
|
94
98
|
$current_test_case = self
|
@@ -96,8 +100,7 @@ module Matchy
|
|
96
100
|
end
|
97
101
|
end
|
98
102
|
|
99
|
-
|
100
|
-
Object.send(:include, Matchy::CustomMatcher)
|
103
|
+
Object.class_eval { include Matchy::CustomMatcher }
|
101
104
|
end
|
102
105
|
end
|
103
106
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Matchy
|
2
|
+
module Assertions
|
3
|
+
# Asserts that the given matcher returns true when +target+ is passed to #matches?
|
4
|
+
def assert_accepts(matcher, target)
|
5
|
+
success = matcher.matches?(target)
|
6
|
+
assert_block(matcher.failure_message) { success }
|
7
|
+
end
|
8
|
+
|
9
|
+
# Asserts that the given matcher returns false when +target+ is passed to #matches?
|
10
|
+
def assert_rejects(matcher, target)
|
11
|
+
success = !matcher.matches?(target)
|
12
|
+
assert_block(matcher.negative_failure_message) { success }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -1,9 +1,13 @@
|
|
1
1
|
module Matchy
|
2
2
|
module ExpectationBuilder
|
3
|
-
def self.build_expectation(
|
4
|
-
return Matchy::Expectations::OperatorExpectation.new(
|
3
|
+
def self.build_expectation(should_succeed, matcher, object)
|
4
|
+
return Matchy::Expectations::OperatorExpectation.new(object, should_succeed) unless matcher
|
5
5
|
|
6
|
-
|
6
|
+
if should_succeed
|
7
|
+
$current_test_case.assert_accepts(matcher, object)
|
8
|
+
else
|
9
|
+
$current_test_case.assert_rejects(matcher, object)
|
10
|
+
end
|
7
11
|
end
|
8
12
|
end
|
9
|
-
end
|
13
|
+
end
|
@@ -34,18 +34,10 @@ module Matchy
|
|
34
34
|
@match_block.call(given, self)
|
35
35
|
end
|
36
36
|
|
37
|
-
def fail!(which)
|
38
|
-
@test_case.flunk(which ? failure_message : negative_failure_message)
|
39
|
-
end
|
40
|
-
|
41
|
-
def pass!(which)
|
42
|
-
@test_case.assert true
|
43
|
-
end
|
44
|
-
|
45
37
|
alias_method :failure_message, :positive_failure_message
|
46
38
|
end
|
47
39
|
|
48
40
|
Class.new(&body).new(match_block, self)
|
49
41
|
end
|
50
42
|
end
|
51
|
-
end
|
43
|
+
end
|
data/lib/matchy/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mcmire-matchy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy McAnally
|
@@ -28,6 +28,7 @@ files:
|
|
28
28
|
- Rakefile
|
29
29
|
- countloc.rb
|
30
30
|
- lib/matchy.rb
|
31
|
+
- lib/matchy/assertions.rb
|
31
32
|
- lib/matchy/built_in/change_expectations.rb
|
32
33
|
- lib/matchy/built_in/enumerable_expectations.rb
|
33
34
|
- lib/matchy/built_in/error_expectations.rb
|