rspec-expectations 2.0.0.a1 → 2.0.0.a2
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +3 -3
- data/.gitignore +1 -0
- data/License.txt +2 -2
- data/Rakefile +17 -10
- data/Upgrade.markdown +38 -0
- data/lib/rspec/expectations.rb +1 -0
- data/lib/rspec/expectations/extensions.rb +1 -0
- data/lib/rspec/expectations/extensions/rspec/core/example_group.rb +19 -0
- data/lib/rspec/expectations/version.rb +16 -0
- data/lib/rspec/matchers.rb +0 -2
- data/lib/rspec/matchers/exist.rb +2 -2
- data/lib/rspec/matchers/extensions/instance_exec.rb +27 -19
- data/lib/rspec/matchers/include.rb +17 -16
- data/lib/rspec/matchers/matcher.rb +71 -25
- data/rspec-expectations.gemspec +66 -19
- data/spec/rspec/matchers/be_close_spec.rb +50 -0
- data/spec/rspec/matchers/be_instance_of_spec.rb +36 -0
- data/spec/rspec/matchers/be_kind_of_spec.rb +33 -0
- data/spec/rspec/matchers/be_spec.rb +311 -0
- data/spec/rspec/matchers/change_spec.rb +349 -0
- data/spec/rspec/matchers/compatibility_spec.rb +28 -0
- data/spec/rspec/matchers/description_generation_spec.rb +160 -0
- data/spec/rspec/matchers/dsl_spec.rb +25 -0
- data/spec/rspec/matchers/eql_spec.rb +33 -0
- data/spec/rspec/matchers/equal_spec.rb +57 -0
- data/spec/rspec/matchers/exist_spec.rb +65 -0
- data/spec/rspec/matchers/has_spec.rb +81 -0
- data/spec/rspec/matchers/have_spec.rb +407 -0
- data/spec/rspec/matchers/include_spec.rb +88 -0
- data/spec/rspec/matchers/match_array_spec.rb +108 -0
- data/spec/rspec/matchers/match_spec.rb +57 -0
- data/spec/rspec/matchers/matcher_methods_spec.rb +63 -0
- data/spec/rspec/matchers/matcher_spec.rb +289 -0
- data/spec/rspec/matchers/matchers_spec.rb +2 -0
- data/spec/rspec/matchers/operator_matcher_spec.rb +191 -0
- data/spec/rspec/matchers/raise_error_spec.rb +333 -0
- data/spec/rspec/matchers/respond_to_spec.rb +116 -0
- data/spec/rspec/matchers/satisfy_spec.rb +36 -0
- data/spec/rspec/matchers/throw_symbol_spec.rb +96 -0
- data/spec/spec_helper.rb +13 -1
- data/spec/support/classes.rb +51 -0
- metadata +60 -15
- data/VERSION +0 -1
- data/VERSION.yml +0 -5
- data/lib/rspec/matchers/simple_matcher.rb +0 -133
- data/lib/rspec/matchers/wrap_expectation.rb +0 -55
- data/spec/rspec/expectations/wrap_expectation_spec.rb +0 -30
- data/spec/support/macros.rb +0 -29
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
2.0.0.a1
|
data/VERSION.yml
DELETED
@@ -1,133 +0,0 @@
|
|
1
|
-
module Rspec
|
2
|
-
module Matchers
|
3
|
-
class SimpleMatcher
|
4
|
-
attr_writer :failure_message, :negative_failure_message, :description
|
5
|
-
|
6
|
-
def initialize(description, &match_block)
|
7
|
-
@description = description
|
8
|
-
@match_block = match_block
|
9
|
-
@failure_message = @negative_failure_message = nil
|
10
|
-
end
|
11
|
-
|
12
|
-
def matches?(given)
|
13
|
-
@given = given
|
14
|
-
case @match_block.arity
|
15
|
-
when 2
|
16
|
-
@match_block.call(@given, self)
|
17
|
-
else
|
18
|
-
@match_block.call(@given)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def description
|
23
|
-
@description || explanation
|
24
|
-
end
|
25
|
-
|
26
|
-
def failure_message_for_should
|
27
|
-
@failure_message || (@description.nil? ? explanation : %[expected #{@description.inspect} but got #{@given.inspect}])
|
28
|
-
end
|
29
|
-
|
30
|
-
def failure_message_for_should_not
|
31
|
-
@negative_failure_message || (@description.nil? ? explanation : %[expected not to get #{@description.inspect}, but got #{@given.inspect}])
|
32
|
-
end
|
33
|
-
|
34
|
-
def explanation
|
35
|
-
"No description provided. See RDoc for simple_matcher()"
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
# simple_matcher makes it easy for you to create your own custom matchers
|
40
|
-
# in just a few lines of code when you don't need all the power of a
|
41
|
-
# completely custom matcher object.
|
42
|
-
#
|
43
|
-
# The <tt>description</tt> argument will appear as part of any failure
|
44
|
-
# message, and is also the source for auto-generated descriptions.
|
45
|
-
#
|
46
|
-
# The <tt>match_block</tt> can have an arity of 1 or 2. The first block
|
47
|
-
# argument will be the given value. The second, if the block accepts it
|
48
|
-
# will be the matcher itself, giving you access to set custom failure
|
49
|
-
# messages in favor of the defaults.
|
50
|
-
#
|
51
|
-
# The <tt>match_block</tt> should return a boolean: <tt>true</tt>
|
52
|
-
# indicates a match, which will pass if you use <tt>should</tt> and fail
|
53
|
-
# if you use <tt>should_not</tt>. false (or nil) indicates no match,
|
54
|
-
# which will do the reverse: fail if you use <tt>should</tt> and pass if
|
55
|
-
# you use <tt>should_not</tt>.
|
56
|
-
#
|
57
|
-
# An error in the <tt>match_block</tt> will bubble up, resulting in a
|
58
|
-
# failure.
|
59
|
-
#
|
60
|
-
# == Example with default messages
|
61
|
-
#
|
62
|
-
# def be_even
|
63
|
-
# simple_matcher("an even number") { |given| given % 2 == 0 }
|
64
|
-
# end
|
65
|
-
#
|
66
|
-
# describe 2 do
|
67
|
-
# it "should be even" do
|
68
|
-
# 2.should be_even
|
69
|
-
# end
|
70
|
-
# end
|
71
|
-
#
|
72
|
-
# Given an odd number, this example would produce an error message stating:
|
73
|
-
# expected "an even number", got 3.
|
74
|
-
#
|
75
|
-
# Unfortunately, if you're a fan of auto-generated descriptions, this will
|
76
|
-
# produce "should an even number." Not the most desirable result. You can
|
77
|
-
# control that using custom messages:
|
78
|
-
#
|
79
|
-
# == Example with custom messages
|
80
|
-
#
|
81
|
-
# def rhyme_with(expected)
|
82
|
-
# simple_matcher("rhyme with #{expected.inspect}") do |given, matcher|
|
83
|
-
# matcher.failure_message = "expected #{given.inspect} to rhyme with #{expected.inspect}"
|
84
|
-
# matcher.negative_failure_message = "expected #{given.inspect} not to rhyme with #{expected.inspect}"
|
85
|
-
# given.rhymes_with? expected
|
86
|
-
# end
|
87
|
-
# end
|
88
|
-
#
|
89
|
-
# # OR
|
90
|
-
#
|
91
|
-
# def rhyme_with(expected)
|
92
|
-
# simple_matcher do |given, matcher|
|
93
|
-
# matcher.description = "rhyme with #{expected.inspect}"
|
94
|
-
# matcher.failure_message = "expected #{given.inspect} to rhyme with #{expected.inspect}"
|
95
|
-
# matcher.negative_failure_message = "expected #{given.inspect} not to rhyme with #{expected.inspect}"
|
96
|
-
# given.rhymes_with? expected
|
97
|
-
# end
|
98
|
-
# end
|
99
|
-
#
|
100
|
-
# describe "pecan" do
|
101
|
-
# it "should rhyme with 'be gone'" do
|
102
|
-
# nut = "pecan"
|
103
|
-
# nut.extend Rhymer
|
104
|
-
# nut.should rhyme_with("be gone")
|
105
|
-
# end
|
106
|
-
# end
|
107
|
-
#
|
108
|
-
# The resulting messages would be:
|
109
|
-
# description: rhyme with "be gone"
|
110
|
-
# failure_message: expected "pecan" to rhyme with "be gone"
|
111
|
-
# negative failure_message: expected "pecan" not to rhyme with "be gone"
|
112
|
-
#
|
113
|
-
# == Wrapped Expectations
|
114
|
-
#
|
115
|
-
# Because errors will bubble up, it is possible to wrap other expectations
|
116
|
-
# in a SimpleMatcher.
|
117
|
-
#
|
118
|
-
# def be_even
|
119
|
-
# simple_matcher("an even number") { |given| (given % 2).should == 0 }
|
120
|
-
# end
|
121
|
-
#
|
122
|
-
# BE VERY CAREFUL when you do this. Only use wrapped expectations for
|
123
|
-
# matchers that will always be used in only the positive
|
124
|
-
# (<tt>should</tt>) or negative (<tt>should_not</tt>), but not both.
|
125
|
-
# The reason is that is you wrap a <tt>should</tt> and call the wrapper
|
126
|
-
# with <tt>should_not</tt>, the correct result (the <tt>should</tt>
|
127
|
-
# failing), will fail when you want it to pass.
|
128
|
-
#
|
129
|
-
def simple_matcher(description=nil, &match_block)
|
130
|
-
SimpleMatcher.new(description, &match_block)
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
module Rspec
|
2
|
-
module Matchers
|
3
|
-
# wraps an expectation in a block that will return true if the
|
4
|
-
# expectation passes and false if it fails (without bubbling up
|
5
|
-
# the failure).
|
6
|
-
#
|
7
|
-
# This is intended to be used in the context of a simple matcher,
|
8
|
-
# and is especially useful for wrapping multiple expectations or
|
9
|
-
# one or more assertions from test/unit extensions when running
|
10
|
-
# with test/unit.
|
11
|
-
#
|
12
|
-
# == Examples
|
13
|
-
#
|
14
|
-
# def eat_cheese(cheese)
|
15
|
-
# simple_matcher do |mouse, matcher|
|
16
|
-
# matcher.failure_message = "expected #{mouse} to eat cheese"
|
17
|
-
# wrap_expectation do |matcher|
|
18
|
-
# assert_eats_cheese(mouse)
|
19
|
-
# end
|
20
|
-
# end
|
21
|
-
# end
|
22
|
-
#
|
23
|
-
# describe Mouse do
|
24
|
-
# it "eats cheese" do
|
25
|
-
# Mouse.new.should eat_cheese
|
26
|
-
# end
|
27
|
-
# end
|
28
|
-
#
|
29
|
-
# You might be wondering "why would I do this if I could just say"
|
30
|
-
# assert_eats_cheese?", a fair question, indeed. You might prefer
|
31
|
-
# to replace the word assert with something more aligned with the
|
32
|
-
# rest of your code examples. You are using rspec, after all.
|
33
|
-
#
|
34
|
-
# The other benefit you get is that you can use the negative version
|
35
|
-
# of the matcher:
|
36
|
-
#
|
37
|
-
# describe Cat do
|
38
|
-
# it "does not eat cheese" do
|
39
|
-
# Cat.new.should_not eat_cheese
|
40
|
-
# end
|
41
|
-
# end
|
42
|
-
#
|
43
|
-
# So in the event there is no assert_does_not_eat_cheese available,
|
44
|
-
# you're all set!
|
45
|
-
def wrap_expectation(matcher, &block)
|
46
|
-
begin
|
47
|
-
block.call(matcher)
|
48
|
-
return true
|
49
|
-
rescue Exception => e
|
50
|
-
matcher.failure_message = e.message
|
51
|
-
return false
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../../spec_helper.rb'
|
2
|
-
|
3
|
-
module Rspec
|
4
|
-
module Matchers
|
5
|
-
describe "wrap_expectation" do
|
6
|
-
|
7
|
-
def stub_matcher
|
8
|
-
@_stub_matcher ||= simple_matcher do
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def failing_matcher
|
13
|
-
@_failing_matcher ||= simple_matcher do
|
14
|
-
1.should == 2
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should return true if there is no error" do
|
19
|
-
wrap_expectation stub_matcher do
|
20
|
-
end.should be_true
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should return false if there is an error" do
|
24
|
-
wrap_expectation failing_matcher do
|
25
|
-
raise "error"
|
26
|
-
end.should be_false
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
data/spec/support/macros.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
module Macros
|
2
|
-
def treats_method_missing_as_private(options = {:noop => true, :subject => nil})
|
3
|
-
it "should have method_missing as private" do
|
4
|
-
with_ruby 1.8 do
|
5
|
-
described_class.private_instance_methods.should include("method_missing")
|
6
|
-
end
|
7
|
-
with_ruby 1.9 do
|
8
|
-
described_class.private_instance_methods.should include(:method_missing)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should not respond_to? method_missing (because it's private)" do
|
13
|
-
formatter = options[:subject] || described_class.new({ }, StringIO.new)
|
14
|
-
formatter.should_not respond_to(:method_missing)
|
15
|
-
end
|
16
|
-
|
17
|
-
if options[:noop]
|
18
|
-
it "should respond_to? all messages" do
|
19
|
-
formatter = described_class.new({ }, StringIO.new)
|
20
|
-
formatter.should respond_to(:just_about_anything)
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should respond_to? anything, when given the private flag" do
|
24
|
-
formatter = described_class.new({ }, StringIO.new)
|
25
|
-
formatter.respond_to?(:method_missing, true).should be_true
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|