rspec-expectations 2.14.0 → 3.13.0

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.
Files changed (155) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data/.document +1 -1
  4. data/.yardopts +1 -1
  5. data/Changelog.md +976 -25
  6. data/{License.txt → LICENSE.md} +5 -3
  7. data/README.md +162 -26
  8. data/lib/rspec/expectations/block_snippet_extractor.rb +253 -0
  9. data/lib/rspec/expectations/configuration.rb +230 -0
  10. data/lib/rspec/expectations/expectation_target.rb +127 -51
  11. data/lib/rspec/expectations/fail_with.rb +17 -57
  12. data/lib/rspec/expectations/failure_aggregator.rb +229 -0
  13. data/lib/rspec/expectations/handler.rb +146 -32
  14. data/lib/rspec/expectations/minitest_integration.rb +58 -0
  15. data/lib/rspec/expectations/syntax.rb +68 -100
  16. data/lib/rspec/expectations/version.rb +1 -1
  17. data/lib/rspec/expectations.rb +58 -23
  18. data/lib/rspec/matchers/aliased_matcher.rb +116 -0
  19. data/lib/rspec/matchers/built_in/all.rb +86 -0
  20. data/lib/rspec/matchers/built_in/base_matcher.rb +191 -20
  21. data/lib/rspec/matchers/built_in/be.rb +114 -114
  22. data/lib/rspec/matchers/built_in/be_between.rb +77 -0
  23. data/lib/rspec/matchers/built_in/be_instance_of.rb +15 -4
  24. data/lib/rspec/matchers/built_in/be_kind_of.rb +10 -1
  25. data/lib/rspec/matchers/built_in/be_within.rb +35 -18
  26. data/lib/rspec/matchers/built_in/change.rb +389 -80
  27. data/lib/rspec/matchers/built_in/compound.rb +290 -0
  28. data/lib/rspec/matchers/built_in/contain_exactly.rb +310 -0
  29. data/lib/rspec/matchers/built_in/count_expectation.rb +169 -0
  30. data/lib/rspec/matchers/built_in/cover.rb +3 -0
  31. data/lib/rspec/matchers/built_in/eq.rb +30 -8
  32. data/lib/rspec/matchers/built_in/eql.rb +23 -8
  33. data/lib/rspec/matchers/built_in/equal.rb +55 -22
  34. data/lib/rspec/matchers/built_in/exist.rb +74 -10
  35. data/lib/rspec/matchers/built_in/has.rb +141 -22
  36. data/lib/rspec/matchers/built_in/have_attributes.rb +114 -0
  37. data/lib/rspec/matchers/built_in/include.rb +184 -32
  38. data/lib/rspec/matchers/built_in/match.rb +95 -1
  39. data/lib/rspec/matchers/built_in/operators.rb +128 -0
  40. data/lib/rspec/matchers/built_in/output.rb +207 -0
  41. data/lib/rspec/matchers/built_in/raise_error.rb +192 -44
  42. data/lib/rspec/matchers/built_in/respond_to.rb +154 -28
  43. data/lib/rspec/matchers/built_in/satisfy.rb +39 -9
  44. data/lib/rspec/matchers/built_in/start_or_end_with.rb +94 -0
  45. data/lib/rspec/matchers/built_in/throw_symbol.rb +58 -14
  46. data/lib/rspec/matchers/built_in/yield.rb +240 -161
  47. data/lib/rspec/matchers/built_in.rb +47 -33
  48. data/lib/rspec/matchers/composable.rb +171 -0
  49. data/lib/rspec/matchers/dsl.rb +531 -10
  50. data/lib/rspec/matchers/english_phrasing.rb +58 -0
  51. data/lib/rspec/matchers/fail_matchers.rb +42 -0
  52. data/lib/rspec/matchers/generated_descriptions.rb +14 -8
  53. data/lib/rspec/matchers/matcher_delegator.rb +61 -0
  54. data/lib/rspec/matchers/matcher_protocol.rb +105 -0
  55. data/lib/rspec/matchers/multi_matcher_diff.rb +82 -0
  56. data/lib/rspec/matchers.rb +520 -173
  57. data.tar.gz.sig +0 -0
  58. metadata +141 -242
  59. metadata.gz.sig +2 -0
  60. data/features/README.md +0 -48
  61. data/features/Upgrade.md +0 -53
  62. data/features/built_in_matchers/README.md +0 -90
  63. data/features/built_in_matchers/be.feature +0 -175
  64. data/features/built_in_matchers/be_within.feature +0 -48
  65. data/features/built_in_matchers/cover.feature +0 -47
  66. data/features/built_in_matchers/end_with.feature +0 -48
  67. data/features/built_in_matchers/equality.feature +0 -139
  68. data/features/built_in_matchers/exist.feature +0 -45
  69. data/features/built_in_matchers/expect_change.feature +0 -59
  70. data/features/built_in_matchers/expect_error.feature +0 -144
  71. data/features/built_in_matchers/have.feature +0 -109
  72. data/features/built_in_matchers/include.feature +0 -174
  73. data/features/built_in_matchers/match.feature +0 -52
  74. data/features/built_in_matchers/operators.feature +0 -227
  75. data/features/built_in_matchers/predicates.feature +0 -137
  76. data/features/built_in_matchers/respond_to.feature +0 -84
  77. data/features/built_in_matchers/satisfy.feature +0 -33
  78. data/features/built_in_matchers/start_with.feature +0 -48
  79. data/features/built_in_matchers/throw_symbol.feature +0 -91
  80. data/features/built_in_matchers/types.feature +0 -116
  81. data/features/built_in_matchers/yield.feature +0 -161
  82. data/features/custom_matchers/access_running_example.feature +0 -53
  83. data/features/custom_matchers/define_diffable_matcher.feature +0 -27
  84. data/features/custom_matchers/define_matcher.feature +0 -368
  85. data/features/custom_matchers/define_matcher_outside_rspec.feature +0 -38
  86. data/features/custom_matchers/define_matcher_with_fluent_interface.feature +0 -24
  87. data/features/customized_message.feature +0 -22
  88. data/features/diffing.feature +0 -85
  89. data/features/implicit_docstrings.feature +0 -52
  90. data/features/step_definitions/additional_cli_steps.rb +0 -22
  91. data/features/support/env.rb +0 -14
  92. data/features/syntax_configuration.feature +0 -71
  93. data/features/test_frameworks/test_unit.feature +0 -44
  94. data/lib/rspec/expectations/deprecation.rb +0 -17
  95. data/lib/rspec/expectations/differ.rb +0 -133
  96. data/lib/rspec/expectations/errors.rb +0 -9
  97. data/lib/rspec/expectations/extensions/array.rb +0 -9
  98. data/lib/rspec/expectations/extensions/object.rb +0 -29
  99. data/lib/rspec/expectations/extensions.rb +0 -2
  100. data/lib/rspec/matchers/be_close.rb +0 -9
  101. data/lib/rspec/matchers/built_in/have.rb +0 -124
  102. data/lib/rspec/matchers/built_in/match_array.rb +0 -51
  103. data/lib/rspec/matchers/built_in/start_and_end_with.rb +0 -48
  104. data/lib/rspec/matchers/compatibility.rb +0 -14
  105. data/lib/rspec/matchers/configuration.rb +0 -108
  106. data/lib/rspec/matchers/extensions/instance_eval_with_args.rb +0 -39
  107. data/lib/rspec/matchers/matcher.rb +0 -300
  108. data/lib/rspec/matchers/method_missing.rb +0 -12
  109. data/lib/rspec/matchers/operator_matcher.rb +0 -109
  110. data/lib/rspec/matchers/pretty.rb +0 -70
  111. data/lib/rspec/matchers/test_unit_integration.rb +0 -11
  112. data/lib/rspec-expectations.rb +0 -1
  113. data/spec/rspec/expectations/differ_spec.rb +0 -192
  114. data/spec/rspec/expectations/expectation_target_spec.rb +0 -82
  115. data/spec/rspec/expectations/extensions/kernel_spec.rb +0 -67
  116. data/spec/rspec/expectations/fail_with_spec.rb +0 -114
  117. data/spec/rspec/expectations/handler_spec.rb +0 -227
  118. data/spec/rspec/expectations/syntax_spec.rb +0 -139
  119. data/spec/rspec/matchers/base_matcher_spec.rb +0 -62
  120. data/spec/rspec/matchers/be_close_spec.rb +0 -22
  121. data/spec/rspec/matchers/be_instance_of_spec.rb +0 -63
  122. data/spec/rspec/matchers/be_kind_of_spec.rb +0 -41
  123. data/spec/rspec/matchers/be_spec.rb +0 -516
  124. data/spec/rspec/matchers/be_within_spec.rb +0 -137
  125. data/spec/rspec/matchers/change_spec.rb +0 -553
  126. data/spec/rspec/matchers/configuration_spec.rb +0 -206
  127. data/spec/rspec/matchers/cover_spec.rb +0 -69
  128. data/spec/rspec/matchers/description_generation_spec.rb +0 -190
  129. data/spec/rspec/matchers/dsl_spec.rb +0 -57
  130. data/spec/rspec/matchers/eq_spec.rb +0 -60
  131. data/spec/rspec/matchers/eql_spec.rb +0 -41
  132. data/spec/rspec/matchers/equal_spec.rb +0 -78
  133. data/spec/rspec/matchers/exist_spec.rb +0 -124
  134. data/spec/rspec/matchers/has_spec.rb +0 -122
  135. data/spec/rspec/matchers/have_spec.rb +0 -455
  136. data/spec/rspec/matchers/include_matcher_integration_spec.rb +0 -30
  137. data/spec/rspec/matchers/include_spec.rb +0 -531
  138. data/spec/rspec/matchers/match_array_spec.rb +0 -194
  139. data/spec/rspec/matchers/match_spec.rb +0 -61
  140. data/spec/rspec/matchers/matcher_spec.rb +0 -471
  141. data/spec/rspec/matchers/matchers_spec.rb +0 -37
  142. data/spec/rspec/matchers/method_missing_spec.rb +0 -28
  143. data/spec/rspec/matchers/operator_matcher_spec.rb +0 -223
  144. data/spec/rspec/matchers/raise_error_spec.rb +0 -485
  145. data/spec/rspec/matchers/respond_to_spec.rb +0 -292
  146. data/spec/rspec/matchers/satisfy_spec.rb +0 -44
  147. data/spec/rspec/matchers/start_with_end_with_spec.rb +0 -186
  148. data/spec/rspec/matchers/throw_symbol_spec.rb +0 -116
  149. data/spec/rspec/matchers/yield_spec.rb +0 -514
  150. data/spec/spec_helper.rb +0 -54
  151. data/spec/support/classes.rb +0 -56
  152. data/spec/support/in_sub_process.rb +0 -38
  153. data/spec/support/matchers.rb +0 -22
  154. data/spec/support/ruby_version.rb +0 -10
  155. data/spec/support/shared_examples.rb +0 -13
@@ -1,22 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module RSpec
4
- module Matchers
5
- describe "expect(actual).to be_close(expected, delta)" do
6
- before(:each) do
7
- allow(RSpec).to receive(:deprecate)
8
- end
9
-
10
- it "is deprecated" do
11
- expect(RSpec).to receive(:deprecate).with(/be_close.*/, :replacement => "be_within(0.5).of(3.0)")
12
- be_close(3.0, 0.5)
13
- end
14
-
15
- it "delegates to be_within(delta).of(expected)" do
16
- should_receive(:be_within).with(0.5).and_return( be_within_matcher = double )
17
- be_within_matcher.should_receive(:of).with(3.0)
18
- be_close(3.0, 0.5)
19
- end
20
- end
21
- end
22
- end
@@ -1,63 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module RSpec
4
- module Matchers
5
- [:be_an_instance_of, :be_instance_of].each do |method|
6
- describe "expect(actual).to #{method}(expected)" do
7
- it_behaves_like "an RSpec matcher", :valid_value => 5, :invalid_value => "a" do
8
- let(:matcher) { send(method, Fixnum) }
9
- end
10
-
11
- it "passes if actual is instance of expected class" do
12
- expect(5).to send(method, Fixnum)
13
- end
14
-
15
- it "fails if actual is instance of subclass of expected class" do
16
- expect {
17
- expect(5).to send(method, Numeric)
18
- }.to fail_with(%Q{expected 5 to be an instance of Numeric})
19
- end
20
-
21
- it "fails with failure message for should unless actual is instance of expected class" do
22
- expect {
23
- expect("foo").to send(method, Array)
24
- }.to fail_with(%Q{expected "foo" to be an instance of Array})
25
- end
26
-
27
- it "provides a description" do
28
- matcher = be_an_instance_of(Fixnum)
29
- matcher.matches?(Numeric)
30
- expect(matcher.description).to eq "be an instance of Fixnum"
31
- end
32
-
33
- context "when expected provides an expanded inspect, e.g. AR::Base" do
34
- let(:user_klass) do
35
- Class.new do
36
- def self.inspect
37
- "User(id: integer, name: string)"
38
- end
39
- end
40
- end
41
-
42
- before { stub_const("User", user_klass) }
43
-
44
- it "provides a description including only the class name" do
45
- matcher = be_an_instance_of(User)
46
- expect(matcher.description).to eq "be an instance of User"
47
- end
48
- end
49
- end
50
-
51
- describe "expect(actual).not_to #{method}(expected)" do
52
-
53
- it "fails with failure message for should_not if actual is instance of expected class" do
54
- expect {
55
- expect("foo").not_to send(method, String)
56
- }.to fail_with(%Q{expected "foo" not to be an instance of String})
57
- end
58
-
59
- end
60
-
61
- end
62
- end
63
- end
@@ -1,41 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module RSpec
4
- module Matchers
5
- [:be_a_kind_of, :be_kind_of].each do |method|
6
- describe "expect(actual).to #{method}(expected)" do
7
- it_behaves_like "an RSpec matcher", :valid_value => 5, :invalid_value => "a" do
8
- let(:matcher) { send(method, Fixnum) }
9
- end
10
-
11
- it "passes if actual is instance of expected class" do
12
- expect(5).to send(method, Fixnum)
13
- end
14
-
15
- it "passes if actual is instance of subclass of expected class" do
16
- expect(5).to send(method, Numeric)
17
- end
18
-
19
- it "fails with failure message for should unless actual is kind of expected class" do
20
- expect {
21
- expect("foo").to send(method, Array)
22
- }.to fail_with(%Q{expected "foo" to be a kind of Array})
23
- end
24
-
25
- it "provides a description" do
26
- matcher = be_a_kind_of(String)
27
- matcher.matches?("this")
28
- expect(matcher.description).to eq "be a kind of String"
29
- end
30
- end
31
-
32
- describe "expect(actual).not_to #{method}(expected)" do
33
- it "fails with failure message for should_not if actual is kind of expected class" do
34
- expect {
35
- expect("foo").not_to send(method, String)
36
- }.to fail_with(%Q{expected "foo" not to be a kind of String})
37
- end
38
- end
39
- end
40
- end
41
- end
@@ -1,516 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "expect(...).to be_predicate" do
4
- it "passes when actual returns true for :predicate?" do
5
- actual = double("actual", :happy? => true)
6
- expect(actual).to be_happy
7
- end
8
-
9
- it "passes when actual returns true for :predicates? (present tense)" do
10
- actual = double("actual", :exists? => true, :exist? => true)
11
- expect(actual).to be_exist
12
- end
13
-
14
- it "fails when actual returns false for :predicate?" do
15
- actual = double("actual", :happy? => false)
16
- expect {
17
- expect(actual).to be_happy
18
- }.to fail_with("expected happy? to return true, got false")
19
- end
20
-
21
- it "fails when actual returns false for :predicate?" do
22
- actual = double("actual", :happy? => nil)
23
- expect {
24
- expect(actual).to be_happy
25
- }.to fail_with("expected happy? to return true, got nil")
26
- end
27
-
28
- it "fails when actual does not respond to :predicate?" do
29
- expect {
30
- expect(Object.new).to be_happy
31
- }.to raise_error(NameError, /happy\?/)
32
- end
33
-
34
- it "fails on error other than NameError" do
35
- actual = double("actual")
36
- actual.should_receive(:foo?).and_raise("aaaah")
37
- expect {
38
- expect(actual).to be_foo
39
- }.to raise_error(/aaaah/)
40
- end
41
-
42
- it "fails on error other than NameError (with the present tense predicate)" do
43
- actual = Object.new
44
- actual.should_receive(:foos?).and_raise("aaaah")
45
- expect {
46
- expect(actual).to be_foo
47
- }.to raise_error(/aaaah/)
48
- end
49
- end
50
-
51
- describe "expect(...).not_to be_predicate" do
52
- it "passes when actual returns false for :sym?" do
53
- actual = double("actual", :happy? => false)
54
- expect(actual).not_to be_happy
55
- end
56
-
57
- it "passes when actual returns nil for :sym?" do
58
- actual = double("actual", :happy? => nil)
59
- expect(actual).not_to be_happy
60
- end
61
-
62
- it "fails when actual returns true for :sym?" do
63
- actual = double("actual", :happy? => true)
64
- expect {
65
- expect(actual).not_to be_happy
66
- }.to fail_with("expected happy? to return false, got true")
67
- end
68
-
69
- it "fails when actual does not respond to :sym?" do
70
- expect {
71
- expect(Object.new).not_to be_happy
72
- }.to raise_error(NameError)
73
- end
74
- end
75
-
76
- describe "expect(...).to be_predicate(*args)" do
77
- it "passes when actual returns true for :predicate?(*args)" do
78
- actual = double("actual")
79
- actual.should_receive(:older_than?).with(3).and_return(true)
80
- expect(actual).to be_older_than(3)
81
- end
82
-
83
- it "fails when actual returns false for :predicate?(*args)" do
84
- actual = double("actual")
85
- actual.should_receive(:older_than?).with(3).and_return(false)
86
- expect {
87
- expect(actual).to be_older_than(3)
88
- }.to fail_with("expected older_than?(3) to return true, got false")
89
- end
90
-
91
- it "fails when actual does not respond to :predicate?" do
92
- expect {
93
- expect(Object.new).to be_older_than(3)
94
- }.to raise_error(NameError)
95
- end
96
- end
97
-
98
- describe "expect(...).not_to be_predicate(*args)" do
99
- it "passes when actual returns false for :predicate?(*args)" do
100
- actual = double("actual")
101
- actual.should_receive(:older_than?).with(3).and_return(false)
102
- expect(actual).not_to be_older_than(3)
103
- end
104
-
105
- it "fails when actual returns true for :predicate?(*args)" do
106
- actual = double("actual")
107
- actual.should_receive(:older_than?).with(3).and_return(true)
108
- expect {
109
- expect(actual).not_to be_older_than(3)
110
- }.to fail_with("expected older_than?(3) to return false, got true")
111
- end
112
-
113
- it "fails when actual does not respond to :predicate?" do
114
- expect {
115
- expect(Object.new).not_to be_older_than(3)
116
- }.to raise_error(NameError)
117
- end
118
- end
119
-
120
- describe "expect(...).to be_predicate(&block)" do
121
- it "passes when actual returns true for :predicate?(&block)" do
122
- actual = double("actual")
123
- delegate = double("delegate")
124
- actual.should_receive(:happy?).and_yield
125
- delegate.should_receive(:check_happy).and_return(true)
126
- expect(actual).to be_happy { delegate.check_happy }
127
- end
128
-
129
- it "fails when actual returns false for :predicate?(&block)" do
130
- actual = double("actual")
131
- delegate = double("delegate")
132
- actual.should_receive(:happy?).and_yield
133
- delegate.should_receive(:check_happy).and_return(false)
134
- expect {
135
- expect(actual).to be_happy { delegate.check_happy }
136
- }.to fail_with("expected happy? to return true, got false")
137
- end
138
-
139
- it "fails when actual does not respond to :predicate?" do
140
- delegate = double("delegate", :check_happy => true)
141
- expect {
142
- expect(Object.new).to be_happy { delegate.check_happy }
143
- }.to raise_error(NameError)
144
- end
145
- end
146
-
147
- describe "expect(...).not_to be_predicate(&block)" do
148
- it "passes when actual returns false for :predicate?(&block)" do
149
- actual = double("actual")
150
- delegate = double("delegate")
151
- actual.should_receive(:happy?).and_yield
152
- delegate.should_receive(:check_happy).and_return(false)
153
- expect(actual).not_to be_happy { delegate.check_happy }
154
- end
155
-
156
- it "fails when actual returns true for :predicate?(&block)" do
157
- actual = double("actual")
158
- delegate = double("delegate")
159
- actual.should_receive(:happy?).and_yield
160
- delegate.should_receive(:check_happy).and_return(true)
161
- expect {
162
- expect(actual).not_to be_happy { delegate.check_happy }
163
- }.to fail_with("expected happy? to return false, got true")
164
- end
165
-
166
- it "fails when actual does not respond to :predicate?" do
167
- delegate = double("delegate", :check_happy => true)
168
- expect {
169
- expect(Object.new).not_to be_happy { delegate.check_happy }
170
- }.to raise_error(NameError)
171
- end
172
- end
173
-
174
- describe "expect(...).to be_predicate(*args, &block)" do
175
- it "passes when actual returns true for :predicate?(*args, &block)" do
176
- actual = double("actual")
177
- delegate = double("delegate")
178
- actual.should_receive(:older_than?).with(3).and_yield(3)
179
- delegate.should_receive(:check_older_than).with(3).and_return(true)
180
- expect(actual).to be_older_than(3) { |age| delegate.check_older_than(age) }
181
- end
182
-
183
- it "fails when actual returns false for :predicate?(*args, &block)" do
184
- actual = double("actual")
185
- delegate = double("delegate")
186
- actual.should_receive(:older_than?).with(3).and_yield(3)
187
- delegate.should_receive(:check_older_than).with(3).and_return(false)
188
- expect {
189
- expect(actual).to be_older_than(3) { |age| delegate.check_older_than(age) }
190
- }.to fail_with("expected older_than?(3) to return true, got false")
191
- end
192
-
193
- it "fails when actual does not respond to :predicate?" do
194
- delegate = double("delegate", :check_older_than => true)
195
- expect {
196
- expect(Object.new).to be_older_than(3) { |age| delegate.check_older_than(age) }
197
- }.to raise_error(NameError)
198
- end
199
- end
200
-
201
- describe "expect(...).not_to be_predicate(*args, &block)" do
202
- it "passes when actual returns false for :predicate?(*args, &block)" do
203
- actual = double("actual")
204
- delegate = double("delegate")
205
- actual.should_receive(:older_than?).with(3).and_yield(3)
206
- delegate.should_receive(:check_older_than).with(3).and_return(false)
207
- expect(actual).not_to be_older_than(3) { |age| delegate.check_older_than(age) }
208
- end
209
-
210
- it "fails when actual returns true for :predicate?(*args, &block)" do
211
- actual = double("actual")
212
- delegate = double("delegate")
213
- actual.should_receive(:older_than?).with(3).and_yield(3)
214
- delegate.should_receive(:check_older_than).with(3).and_return(true)
215
- expect {
216
- expect(actual).not_to be_older_than(3) { |age| delegate.check_older_than(age) }
217
- }.to fail_with("expected older_than?(3) to return false, got true")
218
- end
219
-
220
- it "fails when actual does not respond to :predicate?" do
221
- delegate = double("delegate", :check_older_than => true)
222
- expect {
223
- expect(Object.new).not_to be_older_than(3) { |age| delegate.check_older_than(age) }
224
- }.to raise_error(NameError)
225
- end
226
- end
227
-
228
- describe "expect(...).to be_true" do
229
- it "passes when actual equal?(true)" do
230
- expect(true).to be_true
231
- end
232
-
233
- it "passes when actual is 1" do
234
- expect(1).to be_true
235
- end
236
-
237
- it "fails when actual equal?(false)" do
238
- expect {
239
- expect(false).to be_true
240
- }.to fail_with("expected: true value\n got: false")
241
- end
242
- end
243
-
244
- describe "expect(...).to be_false" do
245
- it "passes when actual equal?(false)" do
246
- expect(false).to be_false
247
- end
248
-
249
- it "passes when actual equal?(nil)" do
250
- expect(nil).to be_false
251
- end
252
-
253
- it "fails when actual equal?(true)" do
254
- expect {
255
- expect(true).to be_false
256
- }.to fail_with("expected: false value\n got: true")
257
- end
258
- end
259
-
260
- describe "expect(...).to be_nil" do
261
- it "passes when actual is nil" do
262
- expect(nil).to be_nil
263
- end
264
-
265
- it "fails when actual is not nil" do
266
- expect {
267
- expect(:not_nil).to be_nil
268
- }.to fail_with(/^expected: nil/)
269
- end
270
- end
271
-
272
- describe "expect(...).not_to be_nil" do
273
- it "passes when actual is not nil" do
274
- expect(:not_nil).not_to be_nil
275
- end
276
-
277
- it "fails when actual is nil" do
278
- expect {
279
- expect(nil).not_to be_nil
280
- }.to fail_with(/^expected: not nil/)
281
- end
282
- end
283
-
284
- describe "expect(...).to be <" do
285
- it "passes when < operator returns true" do
286
- expect(3).to be < 4
287
- end
288
-
289
- it "fails when < operator returns false" do
290
- expect {
291
- expect(3).to be < 3
292
- }.to fail_with("expected: < 3\n got: 3")
293
- end
294
-
295
- it "describes itself" do
296
- expect(be.<(4).description).to eq "be < 4"
297
- end
298
- end
299
-
300
- describe "expect(...).to be <=" do
301
- it "passes when <= operator returns true" do
302
- expect(3).to be <= 4
303
- expect(4).to be <= 4
304
- end
305
-
306
- it "fails when <= operator returns false" do
307
- expect {
308
- expect(3).to be <= 2
309
- }.to fail_with("expected: <= 2\n got: 3")
310
- end
311
- end
312
-
313
- describe "expect(...).to be >=" do
314
- it "passes when >= operator returns true" do
315
- expect(4).to be >= 4
316
- expect(5).to be >= 4
317
- end
318
-
319
- it "fails when >= operator returns false" do
320
- expect {
321
- expect(3).to be >= 4
322
- }.to fail_with("expected: >= 4\n got: 3")
323
- end
324
- end
325
-
326
- describe "expect(...).to be >" do
327
- it "passes when > operator returns true" do
328
- expect(5).to be > 4
329
- end
330
-
331
- it "fails when > operator returns false" do
332
- expect {
333
- expect(3).to be > 4
334
- }.to fail_with("expected: > 4\n got: 3")
335
- end
336
- end
337
-
338
- describe "expect(...).to be ==" do
339
- it "passes when == operator returns true" do
340
- expect(5).to be == 5
341
- end
342
-
343
- it "fails when == operator returns false" do
344
- expect {
345
- expect(3).to be == 4
346
- }.to fail_with("expected: == 4\n got: 3")
347
- end
348
-
349
- it 'works when the target overrides `#send`' do
350
- klass = Struct.new(:message) do
351
- def send
352
- :message_sent
353
- end
354
- end
355
-
356
- msg_1 = klass.new("hello")
357
- msg_2 = klass.new("hello")
358
- expect(msg_1).to be == msg_2
359
- end
360
- end
361
-
362
- describe "expect(...).to be =~" do
363
- it "passes when =~ operator returns true" do
364
- expect("a string").to be =~ /str/
365
- end
366
-
367
- it "fails when =~ operator returns false" do
368
- expect {
369
- expect("a string").to be =~ /blah/
370
- }.to fail_with(%Q|expected: =~ /blah/\n got: "a string"|)
371
- end
372
- end
373
-
374
- describe "should be =~", :uses_should do
375
- it "passes when =~ operator returns true" do
376
- "a string".should be =~ /str/
377
- end
378
-
379
- it "fails when =~ operator returns false" do
380
- expect {
381
- "a string".should be =~ /blah/
382
- }.to fail_with(%Q|expected: =~ /blah/\n got: "a string"|)
383
- end
384
- end
385
-
386
- describe "expect(...).to be ===" do
387
- it "passes when === operator returns true" do
388
- expect(Hash).to be === Hash.new
389
- end
390
-
391
- it "fails when === operator returns false" do
392
- expect {
393
- expect(Hash).to be === "not a hash"
394
- }.to fail_with(%[expected: === "not a hash"\n got: Hash])
395
- end
396
- end
397
-
398
- describe "expect(...).not_to with operators" do
399
- it "coaches user to stop using operators with expect().not_to" do
400
- expect {
401
- expect(5).not_to be < 6
402
- }.to raise_error(/`expect\(actual\).not_to be < 6` not only FAILED,\nit is a bit confusing./m)
403
- end
404
- end
405
-
406
- describe "should_not with operators", :uses_only_should do
407
- it "coaches user to stop using operators with should_not" do
408
- lambda {
409
- 5.should_not be < 6
410
- }.should raise_error(/`actual.should_not be < 6` not only FAILED,\nit is a bit confusing./m)
411
- end
412
- end
413
-
414
- describe "expect(...).to be" do
415
- it "passes if actual is truthy" do
416
- expect(true).to be
417
- expect(1).to be
418
- end
419
-
420
- it "fails if actual is false" do
421
- expect {
422
- expect(false).to be
423
- }.to fail_with("expected false to evaluate to true")
424
- end
425
-
426
- it "fails if actual is nil" do
427
- expect {
428
- expect(nil).to be
429
- }.to fail_with("expected nil to evaluate to true")
430
- end
431
-
432
- it "describes itself" do
433
- expect(be.description).to eq "be"
434
- end
435
- end
436
-
437
- describe "expect(...).not_to be" do
438
- it "passes if actual is falsy" do
439
- expect(false).not_to be
440
- expect(nil).not_to be
441
- end
442
-
443
- it "fails on true" do
444
- expect {
445
- expect(true).not_to be
446
- }.to fail_with("expected true to evaluate to false")
447
- end
448
- end
449
-
450
- describe "expect(...).to be(value)" do
451
- it "delegates to equal" do
452
- matcher = equal(5)
453
- self.should_receive(:equal).with(5).and_return(matcher)
454
- expect(5).to be(5)
455
- end
456
- end
457
-
458
- describe "expect(...).not_to be(value)" do
459
- it "delegates to equal" do
460
- matcher = equal(4)
461
- self.should_receive(:equal).with(4).and_return(matcher)
462
- expect(5).not_to be(4)
463
- end
464
- end
465
-
466
- describe "'expect(...).to be' with operator" do
467
- it "includes 'be' in the description" do
468
- expect((be > 6).description).to match(/be > 6/)
469
- expect((be >= 6).description).to match(/be >= 6/)
470
- expect((be <= 6).description).to match(/be <= 6/)
471
- expect((be < 6).description).to match(/be < 6/)
472
- end
473
- end
474
-
475
-
476
- describe "arbitrary predicate with DelegateClass" do
477
- it "accesses methods defined in the delegating class (LH[#48])" do
478
- require 'delegate'
479
- class ArrayDelegate < DelegateClass(Array)
480
- def initialize(array)
481
- @internal_array = array
482
- super(@internal_array)
483
- end
484
-
485
- def large?
486
- @internal_array.size >= 5
487
- end
488
- end
489
-
490
- delegate = ArrayDelegate.new([1,2,3,4,5,6])
491
- expect(delegate).to be_large
492
- end
493
- end
494
-
495
- describe "be_a, be_an" do
496
- it "passes when class matches" do
497
- expect("foobar").to be_a(String)
498
- expect([1,2,3]).to be_an(Array)
499
- end
500
-
501
- it "fails when class does not match" do
502
- expect("foobar").not_to be_a(Hash)
503
- expect([1,2,3]).not_to be_an(Integer)
504
- end
505
- end
506
-
507
- describe "be_an_instance_of" do
508
- it "passes when direct class matches" do
509
- expect(5).to be_an_instance_of(Fixnum)
510
- end
511
-
512
- it "fails when class is higher up hierarchy" do
513
- expect(5).not_to be_an_instance_of(Numeric)
514
- end
515
- end
516
-