rspec-expectations 2.12.1 → 2.13.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog.md +31 -0
- data/README.md +1 -1
- data/features/built_in_matchers/be.feature +6 -4
- data/features/built_in_matchers/be_within.feature +3 -1
- data/features/built_in_matchers/cover.feature +2 -0
- data/features/built_in_matchers/end_with.feature +2 -0
- data/features/built_in_matchers/equality.feature +9 -15
- data/features/built_in_matchers/exist.feature +2 -0
- data/features/built_in_matchers/expect_error.feature +14 -8
- data/features/built_in_matchers/have.feature +11 -5
- data/features/built_in_matchers/include.feature +53 -0
- data/features/built_in_matchers/match.feature +2 -0
- data/features/built_in_matchers/operators.feature +17 -11
- data/features/built_in_matchers/predicates.feature +21 -13
- data/features/built_in_matchers/respond_to.feature +7 -1
- data/features/built_in_matchers/satisfy.feature +2 -0
- data/features/built_in_matchers/start_with.feature +2 -0
- data/features/built_in_matchers/throw_symbol.feature +6 -0
- data/features/built_in_matchers/types.feature +8 -6
- data/lib/rspec/expectations/deprecation.rb +1 -1
- data/lib/rspec/expectations/differ.rb +8 -8
- data/lib/rspec/expectations/fail_with.rb +17 -3
- data/lib/rspec/expectations/syntax.rb +46 -0
- data/lib/rspec/expectations/version.rb +1 -1
- data/lib/rspec/matchers/built_in/be.rb +7 -3
- data/lib/rspec/matchers/built_in/be_within.rb +13 -4
- data/lib/rspec/matchers/built_in/change.rb +2 -2
- data/lib/rspec/matchers/built_in/equal.rb +5 -1
- data/lib/rspec/matchers/built_in/exist.rb +1 -1
- data/lib/rspec/matchers/built_in/have.rb +8 -8
- data/lib/rspec/matchers/built_in/include.rb +19 -3
- data/lib/rspec/matchers/built_in/respond_to.rb +1 -1
- data/lib/rspec/matchers/extensions/instance_eval_with_args.rb +1 -1
- data/lib/rspec/matchers/matcher.rb +4 -3
- data/lib/rspec/matchers/operator_matcher.rb +1 -1
- data/lib/rspec/matchers/pretty.rb +5 -1
- data/spec/rspec/expectations/differ_spec.rb +8 -15
- data/spec/rspec/expectations/expectation_target_spec.rb +18 -8
- data/spec/rspec/expectations/extensions/kernel_spec.rb +15 -15
- data/spec/rspec/expectations/fail_with_spec.rb +41 -16
- data/spec/rspec/expectations/handler_spec.rb +13 -13
- data/spec/rspec/expectations/syntax_spec.rb +70 -8
- data/spec/rspec/matchers/base_matcher_spec.rb +14 -12
- data/spec/rspec/matchers/be_close_spec.rb +1 -1
- data/spec/rspec/matchers/be_instance_of_spec.rb +14 -8
- data/spec/rspec/matchers/be_kind_of_spec.rb +12 -8
- data/spec/rspec/matchers/be_spec.rb +212 -148
- data/spec/rspec/matchers/be_within_spec.rb +91 -42
- data/spec/rspec/matchers/change_spec.rb +52 -38
- data/spec/rspec/matchers/configuration_spec.rb +19 -15
- data/spec/rspec/matchers/cover_spec.rb +19 -19
- data/spec/rspec/matchers/description_generation_spec.rb +86 -86
- data/spec/rspec/matchers/dsl_spec.rb +7 -7
- data/spec/rspec/matchers/eq_spec.rb +17 -11
- data/spec/rspec/matchers/eql_spec.rb +10 -10
- data/spec/rspec/matchers/equal_spec.rb +27 -9
- data/spec/rspec/matchers/exist_spec.rb +35 -21
- data/spec/rspec/matchers/has_spec.rb +33 -29
- data/spec/rspec/matchers/have_spec.rb +165 -151
- data/spec/rspec/matchers/include_matcher_integration_spec.rb +30 -0
- data/spec/rspec/matchers/include_spec.rb +282 -124
- data/spec/rspec/matchers/match_array_spec.rb +90 -49
- data/spec/rspec/matchers/match_spec.rb +21 -21
- data/spec/rspec/matchers/matcher_spec.rb +85 -48
- data/spec/rspec/matchers/matchers_spec.rb +12 -6
- data/spec/rspec/matchers/method_missing_spec.rb +5 -1
- data/spec/rspec/matchers/operator_matcher_spec.rb +216 -237
- data/spec/rspec/matchers/raise_error_spec.rb +132 -132
- data/spec/rspec/matchers/respond_to_spec.rb +109 -112
- data/spec/rspec/matchers/satisfy_spec.rb +16 -16
- data/spec/rspec/matchers/start_with_end_with_spec.rb +36 -32
- data/spec/rspec/matchers/throw_symbol_spec.rb +24 -24
- data/spec/rspec/matchers/yield_spec.rb +7 -7
- data/spec/spec_helper.rb +46 -19
- data/spec/support/in_sub_process.rb +27 -20
- metadata +81 -83
@@ -25,7 +25,7 @@ module RSpec
|
|
25
25
|
end
|
26
26
|
|
27
27
|
PERSISTENT_INSTANCE_VARIABLES = [
|
28
|
-
:@name, :@declarations, :@diffable,
|
28
|
+
:@name, :@declarations, :@diffable,
|
29
29
|
:@match_block, :@match_for_should_not_block,
|
30
30
|
:@expected_exception
|
31
31
|
].to_set
|
@@ -37,6 +37,7 @@ module RSpec
|
|
37
37
|
instance_variables.map {|ivar| ivar.intern}.each do |ivar|
|
38
38
|
instance_variable_set(ivar, nil) unless (PERSISTENT_INSTANCE_VARIABLES + [:@expected]).include?(ivar)
|
39
39
|
end
|
40
|
+
@messages = {}
|
40
41
|
making_declared_methods_public do
|
41
42
|
instance_eval_with_args(*@expected, &@declarations)
|
42
43
|
end
|
@@ -230,7 +231,7 @@ module RSpec
|
|
230
231
|
|
231
232
|
def method_missing(method, *args, &block)
|
232
233
|
if matcher_execution_context.respond_to?(method)
|
233
|
-
matcher_execution_context.
|
234
|
+
matcher_execution_context.__send__ method, *args, &block
|
234
235
|
else
|
235
236
|
super(method, *args, &block)
|
236
237
|
end
|
@@ -272,7 +273,7 @@ module RSpec
|
|
272
273
|
if @messages.has_key?(key)
|
273
274
|
@messages[key].arity == 1 ? @messages[key].call(@actual) : @messages[key].call
|
274
275
|
else
|
275
|
-
|
276
|
+
__send__("default_#{key}")
|
276
277
|
end
|
277
278
|
end
|
278
279
|
|
@@ -32,7 +32,7 @@ module RSpec
|
|
32
32
|
def self.use_custom_matcher_or_delegate(operator)
|
33
33
|
define_method(operator) do |expected|
|
34
34
|
if uses_generic_implementation_of?(operator) && matcher = OperatorMatcher.get(@actual.class, operator)
|
35
|
-
@actual.
|
35
|
+
@actual.__send__(::RSpec::Matchers.last_should, matcher.new(expected))
|
36
36
|
else
|
37
37
|
eval_match(@actual, operator, expected)
|
38
38
|
end
|
@@ -7,7 +7,7 @@ module RSpec
|
|
7
7
|
|
8
8
|
def to_sentence(words)
|
9
9
|
return "" unless words
|
10
|
-
words = Array(words).map{|w| w
|
10
|
+
words = Array(words).map { |w| to_word(w) }
|
11
11
|
case words.length
|
12
12
|
when 0
|
13
13
|
""
|
@@ -34,6 +34,10 @@ module RSpec
|
|
34
34
|
result
|
35
35
|
end
|
36
36
|
|
37
|
+
def to_word(item)
|
38
|
+
item.respond_to?(:description) ? item.description : item.inspect
|
39
|
+
end
|
40
|
+
|
37
41
|
def name_to_sentence
|
38
42
|
split_words(name)
|
39
43
|
end
|
@@ -36,7 +36,7 @@ module RSpec
|
|
36
36
|
EOD
|
37
37
|
|
38
38
|
diff = differ.diff_as_string(expected, actual)
|
39
|
-
diff.
|
39
|
+
expect(diff).to eql(expected_diff)
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
@@ -71,15 +71,7 @@ EOD
|
|
71
71
|
EOD
|
72
72
|
|
73
73
|
diff = differ.diff_as_object(expected,actual)
|
74
|
-
diff.
|
75
|
-
end
|
76
|
-
|
77
|
-
it "outputs a message if the diff is empty" do
|
78
|
-
diff = differ.diff_as_object('foo', 'foo')
|
79
|
-
diff.should eq(
|
80
|
-
"foo.==(foo) returned false even though the diff between " \
|
81
|
-
"foo and foo is empty. Check the implementation of foo.==."
|
82
|
-
)
|
74
|
+
expect(diff).to eq expected_diff
|
83
75
|
end
|
84
76
|
|
85
77
|
it "outputs unified diff message of two arrays" do
|
@@ -101,7 +93,7 @@ EOD
|
|
101
93
|
EOD
|
102
94
|
|
103
95
|
diff = differ.diff_as_object(expected,actual)
|
104
|
-
diff.
|
96
|
+
expect(diff).to eq expected_diff
|
105
97
|
end
|
106
98
|
|
107
99
|
it "outputs unified diff message of two hashes" do
|
@@ -120,7 +112,7 @@ EOD
|
|
120
112
|
EOD
|
121
113
|
|
122
114
|
diff = differ.diff_as_object(expected,actual)
|
123
|
-
diff.
|
115
|
+
expect(diff).to eq expected_diff
|
124
116
|
end
|
125
117
|
|
126
118
|
it "outputs unified diff of single line strings" do
|
@@ -135,7 +127,7 @@ EOD
|
|
135
127
|
EOD
|
136
128
|
|
137
129
|
diff = differ.diff_as_object(expected,actual)
|
138
|
-
diff.
|
130
|
+
expect(diff).to eq expected_diff
|
139
131
|
end
|
140
132
|
|
141
133
|
it "outputs unified diff of multi line strings" do
|
@@ -151,7 +143,7 @@ EOD
|
|
151
143
|
EOD
|
152
144
|
|
153
145
|
diff = differ.diff_as_object(expected,actual)
|
154
|
-
diff.
|
146
|
+
expect(diff).to eq expected_diff
|
155
147
|
end
|
156
148
|
end
|
157
149
|
end
|
@@ -168,10 +160,11 @@ EOD
|
|
168
160
|
|
169
161
|
|
170
162
|
diff = differ.diff_as_string(expected,actual)
|
171
|
-
diff.
|
163
|
+
expect(diff).to eq expected_diff
|
172
164
|
end
|
173
165
|
end
|
174
166
|
|
175
167
|
end
|
176
168
|
end
|
177
169
|
end
|
170
|
+
|
@@ -8,24 +8,28 @@ module RSpec
|
|
8
8
|
describe ExpectationTarget do
|
9
9
|
context 'when constructed via #expect' do
|
10
10
|
it 'constructs a new instance targetting the given argument' do
|
11
|
-
expect(7).target.
|
11
|
+
expect(expect(7).target).to eq(7)
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'constructs a new instance targetting the given block' do
|
15
15
|
block = lambda {}
|
16
|
-
expect(&block).target.
|
16
|
+
expect(expect(&block).target).to be(block)
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'raises an ArgumentError when given an argument and a block' do
|
20
|
-
|
20
|
+
expect {
|
21
|
+
expect(7) { }
|
22
|
+
}.to raise_error(ArgumentError)
|
21
23
|
end
|
22
24
|
|
23
25
|
it 'raises an ArgumentError when given neither an argument nor a block' do
|
24
|
-
|
26
|
+
expect {
|
27
|
+
expect
|
28
|
+
}.to raise_error(ArgumentError)
|
25
29
|
end
|
26
30
|
|
27
31
|
it 'can be passed nil' do
|
28
|
-
expect(nil).target.
|
32
|
+
expect(expect(nil).target).to be_nil
|
29
33
|
end
|
30
34
|
|
31
35
|
it 'passes a valid positive expectation' do
|
@@ -38,13 +42,19 @@ module RSpec
|
|
38
42
|
end
|
39
43
|
|
40
44
|
it 'fails an invalid positive expectation' do
|
41
|
-
|
45
|
+
expect {
|
46
|
+
expect(5).to eq(4)
|
47
|
+
}.to fail_with(/expected: 4.*got: 5/m)
|
42
48
|
end
|
43
49
|
|
44
50
|
it 'fails an invalid negative expectation' do
|
45
51
|
message = /expected 5 not to be a kind of Fixnum/
|
46
|
-
|
47
|
-
|
52
|
+
expect {
|
53
|
+
expect(5).to_not be_a(Fixnum)
|
54
|
+
}.to fail_with(message)
|
55
|
+
expect {
|
56
|
+
expect(5).not_to be_a(Fixnum)
|
57
|
+
}.to fail_with(message)
|
48
58
|
end
|
49
59
|
|
50
60
|
it 'does not support operator matchers from #to' do
|
@@ -7,18 +7,18 @@ describe Object, "#should" do
|
|
7
7
|
@matcher.stub!(:matches?).and_return(true)
|
8
8
|
@matcher.stub!(:failure_message_for_should)
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
it "accepts and interacts with a matcher" do
|
12
|
-
@matcher.should_receive(:matches?).with(@target).and_return(true)
|
13
|
-
@target.
|
12
|
+
@matcher.should_receive(:matches?).with(@target).and_return(true)
|
13
|
+
expect(@target).to @matcher
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
it "asks for a failure_message_for_should when matches? returns false" do
|
17
17
|
@matcher.should_receive(:matches?).with(@target).and_return(false)
|
18
18
|
@matcher.should_receive(:failure_message_for_should).and_return("the failure message")
|
19
|
-
|
20
|
-
@target.
|
21
|
-
}.
|
19
|
+
expect {
|
20
|
+
expect(@target).to @matcher
|
21
|
+
}.to fail_with("the failure message")
|
22
22
|
end
|
23
23
|
|
24
24
|
context "on interpretters that have BasicObject", :if => defined?(BasicObject) do
|
@@ -39,7 +39,7 @@ describe Object, "#should" do
|
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'works properly on BasicObject-subclassed proxy objects' do
|
42
|
-
proxy_class.new(Object.new).
|
42
|
+
expect(proxy_class.new(Object.new)).to be_proxied
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
@@ -49,19 +49,19 @@ describe Object, "#should_not" do
|
|
49
49
|
@target = "target"
|
50
50
|
@matcher = mock("matcher")
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
it "accepts and interacts with a matcher" do
|
54
54
|
@matcher.should_receive(:matches?).with(@target).and_return(false)
|
55
55
|
@matcher.stub!(:failure_message_for_should_not)
|
56
|
-
|
57
|
-
@target.
|
56
|
+
|
57
|
+
expect(@target).not_to @matcher
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
it "asks for a failure_message_for_should_not when matches? returns true" do
|
61
61
|
@matcher.should_receive(:matches?).with(@target).and_return(true)
|
62
62
|
@matcher.should_receive(:failure_message_for_should_not).and_return("the failure message for should not")
|
63
|
-
|
64
|
-
@target.
|
65
|
-
}.
|
63
|
+
expect {
|
64
|
+
expect(@target).not_to @matcher
|
65
|
+
}.to fail_with("the failure message for should not")
|
66
66
|
end
|
67
67
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe RSpec::Expectations, "#fail_with with diff" do
|
@@ -9,62 +10,86 @@ describe RSpec::Expectations, "#fail_with with diff" do
|
|
9
10
|
|
10
11
|
it "calls differ if expected/actual are not strings (or numbers or procs)" do
|
11
12
|
differ.should_receive(:diff_as_object).and_return("diff")
|
12
|
-
|
13
|
+
expect {
|
13
14
|
RSpec::Expectations.fail_with "the message", Object.new, Object.new
|
14
|
-
}.
|
15
|
+
}.to fail_with("the message\nDiff:diff")
|
15
16
|
end
|
16
17
|
|
17
18
|
context "with two strings" do
|
18
19
|
context "and actual is multiline" do
|
19
20
|
it "calls differ" do
|
20
21
|
differ.should_receive(:diff_as_string).and_return("diff")
|
21
|
-
|
22
|
+
expect {
|
22
23
|
RSpec::Expectations.fail_with "the message", "expected\nthis", "actual"
|
23
|
-
}.
|
24
|
+
}.to fail_with("the message\nDiff:diff")
|
24
25
|
end
|
25
26
|
end
|
26
27
|
|
27
28
|
context "and expected is multiline" do
|
28
29
|
it "calls differ" do
|
29
30
|
differ.should_receive(:diff_as_string).and_return("diff")
|
30
|
-
|
31
|
+
expect {
|
31
32
|
RSpec::Expectations.fail_with "the message", "expected", "actual\nthat"
|
32
|
-
}.
|
33
|
+
}.to fail_with("the message\nDiff:diff")
|
33
34
|
end
|
34
35
|
end
|
35
36
|
|
36
37
|
context "and both are single line strings" do
|
37
38
|
it "does not call differ" do
|
38
39
|
differ.should_not_receive(:diff_as_string)
|
39
|
-
|
40
|
+
expect {
|
40
41
|
RSpec::Expectations.fail_with("the message", "expected", "actual")
|
41
|
-
}.
|
42
|
+
}.to fail_with("the message")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context "and they are UTF-16LE encoded", :if => String.method_defined?(:encode) do
|
47
|
+
it 'does not diff when they are not multiline' do
|
48
|
+
differ.should_not_receive(:diff_as_string)
|
49
|
+
|
50
|
+
str_1 = "This is a pile of poo: 💩".encode("UTF-16LE")
|
51
|
+
str_2 = "This is a pile of poo: 💩".encode("UTF-16LE")
|
52
|
+
|
53
|
+
expect {
|
54
|
+
RSpec::Expectations.fail_with("the message", str_1, str_2)
|
55
|
+
}.to fail_with("the message")
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'diffs when they are multiline' do
|
59
|
+
differ.should_receive(:diff_as_string).and_return("diff")
|
60
|
+
|
61
|
+
str_1 = "This is a pile of poo:\n💩".encode("UTF-16LE")
|
62
|
+
str_2 = "This is a pile of poo:\n💩".encode("UTF-16LE")
|
63
|
+
|
64
|
+
expect {
|
65
|
+
RSpec::Expectations.fail_with("the message", str_1, str_2)
|
66
|
+
}.to fail_with("the message\nDiff:diff")
|
42
67
|
end
|
43
68
|
end
|
44
69
|
end
|
45
70
|
|
46
71
|
it "does not call differ if no expected/actual" do
|
47
|
-
|
72
|
+
expect {
|
48
73
|
RSpec::Expectations.fail_with "the message"
|
49
|
-
}.
|
74
|
+
}.to fail_with("the message")
|
50
75
|
end
|
51
76
|
|
52
77
|
it "does not call differ expected is Numeric" do
|
53
|
-
|
78
|
+
expect {
|
54
79
|
RSpec::Expectations.fail_with "the message", 1, "1"
|
55
|
-
}.
|
80
|
+
}.to fail_with("the message")
|
56
81
|
end
|
57
82
|
|
58
83
|
it "does not call differ when actual is Numeric" do
|
59
|
-
|
84
|
+
expect {
|
60
85
|
RSpec::Expectations.fail_with "the message", "1", 1
|
61
|
-
}.
|
86
|
+
}.to fail_with("the message")
|
62
87
|
end
|
63
88
|
|
64
89
|
it "does not call differ if expected or actual are procs" do
|
65
|
-
|
90
|
+
expect {
|
66
91
|
RSpec::Expectations.fail_with "the message", lambda {}, lambda {}
|
67
|
-
}.
|
92
|
+
}.to fail_with("the message")
|
68
93
|
end
|
69
94
|
end
|
70
95
|
|
@@ -59,7 +59,7 @@ module RSpec
|
|
59
59
|
matcher = mock("matcher")
|
60
60
|
actual = Object.new
|
61
61
|
matcher.should_receive(:matches?).with(actual).and_return(:this_value)
|
62
|
-
RSpec::Expectations::PositiveExpectationHandler.handle_matcher(actual, matcher).
|
62
|
+
expect(RSpec::Expectations::PositiveExpectationHandler.handle_matcher(actual, matcher)).to eq :this_value
|
63
63
|
end
|
64
64
|
|
65
65
|
it "calls failure_message_for_should if the matcher implements it" do
|
@@ -129,7 +129,7 @@ module RSpec
|
|
129
129
|
actual = Object.new
|
130
130
|
matcher.should_receive(:matches?).with(actual).and_return(false)
|
131
131
|
matcher.stub!(:negative_failure_message).and_return("ignore")
|
132
|
-
RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher).
|
132
|
+
expect(RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher)).to be_false
|
133
133
|
end
|
134
134
|
|
135
135
|
|
@@ -185,20 +185,20 @@ module RSpec
|
|
185
185
|
include ExampleExpectations
|
186
186
|
|
187
187
|
it "handles submitted args" do
|
188
|
-
5.
|
189
|
-
5.
|
190
|
-
|
191
|
-
|
192
|
-
5.
|
193
|
-
5.
|
194
|
-
|
195
|
-
|
188
|
+
expect(5).to arbitrary_matcher(:expected => 5)
|
189
|
+
expect(5).to arbitrary_matcher(:expected => "wrong").with(5)
|
190
|
+
expect { expect(5).to arbitrary_matcher(:expected => 4) }.to fail_with("expected 4, got 5")
|
191
|
+
expect { expect(5).to arbitrary_matcher(:expected => 5).with(4) }.to fail_with("expected 4, got 5")
|
192
|
+
expect(5).to_not arbitrary_matcher(:expected => 4)
|
193
|
+
expect(5).to_not arbitrary_matcher(:expected => 5).with(4)
|
194
|
+
expect { expect(5).to_not arbitrary_matcher(:expected => 5) }.to fail_with("expected not 5, got 5")
|
195
|
+
expect { expect(5).to_not arbitrary_matcher(:expected => 4).with(5) }.to fail_with("expected not 5, got 5")
|
196
196
|
end
|
197
197
|
|
198
198
|
it "handles the submitted block" do
|
199
|
-
5.
|
200
|
-
5.
|
201
|
-
5.
|
199
|
+
expect(5).to arbitrary_matcher { 5 }
|
200
|
+
expect(5).to arbitrary_matcher(:expected => 4) { 5 }
|
201
|
+
expect(5).to arbitrary_matcher(:expected => 4).with(5) { 3 }
|
202
202
|
end
|
203
203
|
|
204
204
|
end
|
@@ -2,31 +2,93 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module RSpec
|
4
4
|
module Expectations
|
5
|
-
|
6
|
-
|
5
|
+
describe Syntax do
|
6
|
+
context "when passing a message to an expectation" do
|
7
7
|
let(:warner) { ::Kernel }
|
8
8
|
|
9
|
-
describe "
|
9
|
+
describe "expect(...).to" do
|
10
10
|
it "prints a warning when the message object isn't a String" do
|
11
11
|
warner.should_receive(:warn).with /ignoring.*message/
|
12
|
-
3.
|
12
|
+
expect(3).to eq(3), :not_a_string
|
13
13
|
end
|
14
14
|
|
15
15
|
it "doesn't print a warning when message is a String" do
|
16
16
|
warner.should_not_receive(:warn)
|
17
|
-
3.
|
17
|
+
expect(3).to eq(3), "a string"
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
describe "
|
21
|
+
describe "expect(...).to_not" do
|
22
22
|
it "prints a warning when the message object isn't a String" do
|
23
23
|
warner.should_receive(:warn).with /ignoring.*message/
|
24
|
-
3.
|
24
|
+
expect(3).not_to eq(4), :not_a_string
|
25
25
|
end
|
26
26
|
|
27
27
|
it "doesn't print a warning when message is a String" do
|
28
28
|
warner.should_not_receive(:warn)
|
29
|
-
3.
|
29
|
+
expect(3).not_to eq(4), "a string"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "expression generation" do
|
35
|
+
let(:target) { "foo" }
|
36
|
+
let(:expectation) { "eq('bar')" }
|
37
|
+
let(:positive_expect_example) { "expect(foo).to eq('bar')" }
|
38
|
+
let(:positive_should_example) { "foo.should eq('bar')" }
|
39
|
+
let(:negative_expect_example) { "expect(foo).not_to eq('bar')" }
|
40
|
+
let(:negative_should_example) { "foo.should_not eq('bar')" }
|
41
|
+
|
42
|
+
def positive_expression
|
43
|
+
Syntax.positive_expression(target, expectation)
|
44
|
+
end
|
45
|
+
|
46
|
+
def negative_expression
|
47
|
+
Syntax.negative_expression(target, expectation)
|
48
|
+
end
|
49
|
+
|
50
|
+
context "when only :expect is enabled" do
|
51
|
+
before do
|
52
|
+
expect(Syntax.should_enabled?).to be_false
|
53
|
+
expect(Syntax.expect_enabled?).to be_true
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'generates a positive expression using the expect syntax' do
|
57
|
+
expect(positive_expression).to eq(positive_expect_example)
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'generates a negative expression using the expect syntax' do
|
61
|
+
expect(negative_expression).to eq(negative_expect_example)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context "when both :should and :expect are enabled", :uses_should do
|
66
|
+
before do
|
67
|
+
expect(Syntax.should_enabled?).to be_true
|
68
|
+
expect(Syntax.expect_enabled?).to be_true
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'generates a positive expression using the expect syntax' do
|
72
|
+
expect(positive_expression).to eq(positive_expect_example)
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'generates a negative expression using the expect syntax' do
|
76
|
+
expect(negative_expression).to eq(negative_expect_example)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context "when only :should is enabled", :uses_only_should do
|
81
|
+
before do
|
82
|
+
Syntax.should_enabled?.should be_true
|
83
|
+
Syntax.expect_enabled?.should be_false
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'generates a positive expression using the expect syntax' do
|
87
|
+
positive_expression.should eq(positive_should_example)
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'generates a negative expression using the expect syntax' do
|
91
|
+
negative_expression.should eq(negative_should_example)
|
30
92
|
end
|
31
93
|
end
|
32
94
|
end
|