rspec-expectations 2.13.0 → 3.0.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 (142) hide show
  1. checksums.yaml +15 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data/Changelog.md +413 -23
  4. data/License.txt +1 -0
  5. data/README.md +109 -80
  6. data/lib/rspec/{matchers → expectations}/configuration.rb +44 -14
  7. data/lib/rspec/expectations/expectation_target.rb +71 -38
  8. data/lib/rspec/expectations/fail_with.rb +12 -44
  9. data/lib/rspec/expectations/handler.rb +135 -35
  10. data/lib/rspec/expectations/minitest_integration.rb +16 -0
  11. data/lib/rspec/expectations/syntax.rb +60 -94
  12. data/lib/rspec/expectations/version.rb +1 -1
  13. data/lib/rspec/expectations.rb +46 -24
  14. data/lib/rspec/matchers/aliased_matcher.rb +41 -0
  15. data/lib/rspec/matchers/built_in/all.rb +78 -0
  16. data/lib/rspec/matchers/built_in/base_matcher.rb +63 -15
  17. data/lib/rspec/matchers/built_in/be.rb +170 -79
  18. data/lib/rspec/matchers/built_in/be_between.rb +77 -0
  19. data/lib/rspec/matchers/built_in/be_instance_of.rb +11 -3
  20. data/lib/rspec/matchers/built_in/be_kind_of.rb +5 -0
  21. data/lib/rspec/matchers/built_in/be_within.rb +40 -16
  22. data/lib/rspec/matchers/built_in/change.rb +275 -74
  23. data/lib/rspec/matchers/built_in/compound.rb +122 -0
  24. data/lib/rspec/matchers/built_in/contain_exactly.rb +256 -0
  25. data/lib/rspec/matchers/built_in/cover.rb +3 -0
  26. data/lib/rspec/matchers/built_in/eq.rb +60 -6
  27. data/lib/rspec/matchers/built_in/eql.rb +17 -5
  28. data/lib/rspec/matchers/built_in/equal.rb +55 -21
  29. data/lib/rspec/matchers/built_in/exist.rb +74 -10
  30. data/lib/rspec/matchers/built_in/has.rb +71 -15
  31. data/lib/rspec/matchers/built_in/include.rb +58 -29
  32. data/lib/rspec/matchers/built_in/match.rb +19 -1
  33. data/lib/rspec/matchers/built_in/operators.rb +119 -0
  34. data/lib/rspec/matchers/built_in/output.rb +150 -0
  35. data/lib/rspec/matchers/built_in/raise_error.rb +91 -33
  36. data/lib/rspec/matchers/built_in/respond_to.rb +42 -20
  37. data/lib/rspec/matchers/built_in/satisfy.rb +19 -3
  38. data/lib/rspec/matchers/built_in/start_and_end_with.rb +54 -18
  39. data/lib/rspec/matchers/built_in/throw_symbol.rb +38 -8
  40. data/lib/rspec/matchers/built_in/yield.rb +237 -55
  41. data/lib/rspec/matchers/built_in.rb +45 -33
  42. data/lib/rspec/matchers/composable.rb +179 -0
  43. data/lib/rspec/matchers/dsl.rb +362 -5
  44. data/lib/rspec/matchers/generated_descriptions.rb +13 -6
  45. data/lib/rspec/matchers/matcher_delegator.rb +37 -0
  46. data/lib/rspec/matchers/pretty.rb +33 -20
  47. data/lib/rspec/matchers.rb +450 -227
  48. data.tar.gz.sig +1 -0
  49. metadata +100 -215
  50. metadata.gz.sig +0 -0
  51. data/features/README.md +0 -49
  52. data/features/Upgrade.md +0 -53
  53. data/features/built_in_matchers/README.md +0 -90
  54. data/features/built_in_matchers/be.feature +0 -175
  55. data/features/built_in_matchers/be_within.feature +0 -48
  56. data/features/built_in_matchers/cover.feature +0 -47
  57. data/features/built_in_matchers/end_with.feature +0 -48
  58. data/features/built_in_matchers/equality.feature +0 -139
  59. data/features/built_in_matchers/exist.feature +0 -45
  60. data/features/built_in_matchers/expect_change.feature +0 -59
  61. data/features/built_in_matchers/expect_error.feature +0 -144
  62. data/features/built_in_matchers/have.feature +0 -109
  63. data/features/built_in_matchers/include.feature +0 -174
  64. data/features/built_in_matchers/match.feature +0 -52
  65. data/features/built_in_matchers/operators.feature +0 -227
  66. data/features/built_in_matchers/predicates.feature +0 -137
  67. data/features/built_in_matchers/respond_to.feature +0 -84
  68. data/features/built_in_matchers/satisfy.feature +0 -33
  69. data/features/built_in_matchers/start_with.feature +0 -48
  70. data/features/built_in_matchers/throw_symbol.feature +0 -91
  71. data/features/built_in_matchers/types.feature +0 -116
  72. data/features/built_in_matchers/yield.feature +0 -146
  73. data/features/custom_matchers/access_running_example.feature +0 -53
  74. data/features/custom_matchers/define_diffable_matcher.feature +0 -27
  75. data/features/custom_matchers/define_matcher.feature +0 -368
  76. data/features/custom_matchers/define_matcher_outside_rspec.feature +0 -38
  77. data/features/custom_matchers/define_matcher_with_fluent_interface.feature +0 -24
  78. data/features/customized_message.feature +0 -22
  79. data/features/diffing.feature +0 -85
  80. data/features/implicit_docstrings.feature +0 -52
  81. data/features/step_definitions/additional_cli_steps.rb +0 -22
  82. data/features/support/env.rb +0 -5
  83. data/features/syntax_configuration.feature +0 -68
  84. data/features/test_frameworks/test_unit.feature +0 -46
  85. data/lib/rspec/expectations/deprecation.rb +0 -38
  86. data/lib/rspec/expectations/differ.rb +0 -115
  87. data/lib/rspec/expectations/errors.rb +0 -9
  88. data/lib/rspec/expectations/extensions/array.rb +0 -9
  89. data/lib/rspec/expectations/extensions/object.rb +0 -39
  90. data/lib/rspec/expectations/extensions.rb +0 -2
  91. data/lib/rspec/matchers/be_close.rb +0 -9
  92. data/lib/rspec/matchers/built_in/have.rb +0 -108
  93. data/lib/rspec/matchers/built_in/match_array.rb +0 -51
  94. data/lib/rspec/matchers/compatibility.rb +0 -14
  95. data/lib/rspec/matchers/extensions/instance_eval_with_args.rb +0 -39
  96. data/lib/rspec/matchers/matcher.rb +0 -300
  97. data/lib/rspec/matchers/method_missing.rb +0 -12
  98. data/lib/rspec/matchers/operator_matcher.rb +0 -109
  99. data/lib/rspec-expectations.rb +0 -1
  100. data/spec/rspec/expectations/differ_spec.rb +0 -170
  101. data/spec/rspec/expectations/expectation_target_spec.rb +0 -75
  102. data/spec/rspec/expectations/extensions/kernel_spec.rb +0 -67
  103. data/spec/rspec/expectations/fail_with_spec.rb +0 -95
  104. data/spec/rspec/expectations/handler_spec.rb +0 -206
  105. data/spec/rspec/expectations/syntax_spec.rb +0 -97
  106. data/spec/rspec/matchers/base_matcher_spec.rb +0 -62
  107. data/spec/rspec/matchers/be_close_spec.rb +0 -22
  108. data/spec/rspec/matchers/be_instance_of_spec.rb +0 -63
  109. data/spec/rspec/matchers/be_kind_of_spec.rb +0 -41
  110. data/spec/rspec/matchers/be_spec.rb +0 -516
  111. data/spec/rspec/matchers/be_within_spec.rb +0 -129
  112. data/spec/rspec/matchers/change_spec.rb +0 -542
  113. data/spec/rspec/matchers/configuration_spec.rb +0 -238
  114. data/spec/rspec/matchers/cover_spec.rb +0 -69
  115. data/spec/rspec/matchers/description_generation_spec.rb +0 -176
  116. data/spec/rspec/matchers/dsl_spec.rb +0 -57
  117. data/spec/rspec/matchers/eq_spec.rb +0 -60
  118. data/spec/rspec/matchers/eql_spec.rb +0 -41
  119. data/spec/rspec/matchers/equal_spec.rb +0 -78
  120. data/spec/rspec/matchers/exist_spec.rb +0 -124
  121. data/spec/rspec/matchers/has_spec.rb +0 -122
  122. data/spec/rspec/matchers/have_spec.rb +0 -445
  123. data/spec/rspec/matchers/include_matcher_integration_spec.rb +0 -30
  124. data/spec/rspec/matchers/include_spec.rb +0 -531
  125. data/spec/rspec/matchers/match_array_spec.rb +0 -194
  126. data/spec/rspec/matchers/match_spec.rb +0 -61
  127. data/spec/rspec/matchers/matcher_spec.rb +0 -471
  128. data/spec/rspec/matchers/matchers_spec.rb +0 -37
  129. data/spec/rspec/matchers/method_missing_spec.rb +0 -28
  130. data/spec/rspec/matchers/operator_matcher_spec.rb +0 -223
  131. data/spec/rspec/matchers/raise_error_spec.rb +0 -395
  132. data/spec/rspec/matchers/respond_to_spec.rb +0 -292
  133. data/spec/rspec/matchers/satisfy_spec.rb +0 -44
  134. data/spec/rspec/matchers/start_with_end_with_spec.rb +0 -186
  135. data/spec/rspec/matchers/throw_symbol_spec.rb +0 -116
  136. data/spec/rspec/matchers/yield_spec.rb +0 -437
  137. data/spec/spec_helper.rb +0 -54
  138. data/spec/support/classes.rb +0 -56
  139. data/spec/support/in_sub_process.rb +0 -38
  140. data/spec/support/matchers.rb +0 -22
  141. data/spec/support/ruby_version.rb +0 -10
  142. data/spec/support/shared_examples.rb +0 -13
@@ -1,238 +0,0 @@
1
- require 'spec_helper'
2
- require 'delegate'
3
-
4
- module RSpec
5
- module Matchers
6
- describe "RSpec::Matchers.configuration" do
7
- it 'returns a memoized configuration instance' do
8
- expect(RSpec::Matchers.configuration).to be_a(RSpec::Matchers::Configuration)
9
- expect(RSpec::Matchers.configuration).to be(RSpec::Matchers.configuration)
10
- end
11
- end
12
-
13
- describe Configuration do
14
- let(:config) { Configuration.new }
15
-
16
- describe "#backtrace_formatter" do
17
- let(:original_backtrace) { %w[ clean-me/a.rb other/file.rb clean-me/b.rb ] }
18
- let(:cleaned_backtrace) { %w[ other/file.rb ] }
19
-
20
- let(:formatted_backtrace) do
21
- config.backtrace_formatter.format_backtrace(original_backtrace)
22
- end
23
-
24
- before do
25
- RSpec.configuration.stub(:backtrace_clean_patterns) { [/clean-me/] }
26
- end
27
-
28
- it "defaults to rspec-core's backtrace formatter when rspec-core is loaded" do
29
- expect(config.backtrace_formatter).to be(RSpec::Core::BacktraceFormatter)
30
- expect(formatted_backtrace).to eq(cleaned_backtrace)
31
- end
32
-
33
- it "defaults to a null formatter when rspec-core is not loaded" do
34
- hide_const("RSpec::Core::BacktraceFormatter")
35
- expect(formatted_backtrace).to eq(original_backtrace)
36
- end
37
-
38
- it "can be set to another backtrace formatter" do
39
- config.backtrace_formatter = stub(:format_backtrace => ['a'])
40
- expect(formatted_backtrace).to eq(['a'])
41
- end
42
- end
43
-
44
- context 'on an interpreter that does not provide BasicObject', :uses_should, :unless => defined?(::BasicObject) do
45
- before { RSpec::Expectations::Syntax.disable_should(Delegator) }
46
-
47
- let(:klass) do
48
- Class.new(SimpleDelegator) do
49
- def delegated?; true; end
50
- end
51
- end
52
-
53
- let(:instance) { klass.new(Object.new) }
54
-
55
- it 'provides a means to manually add it Delegator' do
56
- instance.should_not respond_to(:delegated?) # because #should is being delegated...
57
- config.add_should_and_should_not_to Delegator
58
- instance.should respond_to(:delegated?) # now it should work!
59
- end
60
- end
61
-
62
- shared_examples_for "configuring the expectation syntax" do
63
- # We want a sandboxed method that ensures that we wind up with
64
- # both syntaxes properly enabled when the example ends.
65
- #
66
- # On platforms that fork, using a sub process is the easiest,
67
- # most robust way to achieve that.
68
- #
69
- # On jRuby we just re-enable both syntaxes at the end of the example;
70
- # however, this is a generally inferior approach because it depends on
71
- # the code-under-test working properly; if it doesn't work properly,
72
- # it could leave things in a "broken" state where tons of other examples fail.
73
- if RUBY_PLATFORM == "java"
74
- def sandboxed
75
- orig_syntax = RSpec::Matchers.configuration.syntax
76
- yield
77
- ensure
78
- configure_syntax(orig_syntax)
79
- end
80
- else
81
- include InSubProcess
82
- alias sandboxed in_sub_process
83
- end
84
-
85
- it 'can limit the syntax to :should' do
86
- sandboxed do
87
- configure_syntax :should
88
- configured_syntax.should eq([:should])
89
-
90
- 3.should eq(3)
91
- 3.should_not eq(4)
92
- lambda { expect(6).to eq(6) }.should raise_error(NameError)
93
- end
94
- end
95
-
96
- it 'is a no-op when configured to :should twice' do
97
- sandboxed do
98
- configure_syntax :should
99
-
100
- Expectations::Syntax.default_should_host.
101
- stub(:method_added).
102
- and_raise("no methods should be added here")
103
-
104
- configure_syntax :should
105
- end
106
- end
107
-
108
- it 'can limit the syntax to :expect' do
109
- sandboxed do
110
- configure_syntax :expect
111
- expect(configured_syntax).to eq([:expect])
112
-
113
- expect(3).to eq(3)
114
- expect { 3.should eq(3) }.to raise_error(NameError)
115
- expect { 3.should_not eq(3) }.to raise_error(NameError)
116
- end
117
- end
118
-
119
- it 'is a no-op when configured to :expect twice' do
120
- sandboxed do
121
- RSpec::Matchers.stub(:method_added).and_raise("no methods should be added here")
122
-
123
- configure_syntax :expect
124
- configure_syntax :expect
125
- end
126
- end
127
-
128
- it 'can re-enable the :should syntax' do
129
- sandboxed do
130
- configure_syntax :expect
131
- configure_syntax [:should, :expect]
132
- configured_syntax.should eq([:should, :expect])
133
-
134
- 3.should eq(3)
135
- 3.should_not eq(4)
136
- expect(3).to eq(3)
137
- end
138
- end
139
-
140
- it 'can re-enable the :expect syntax' do
141
- sandboxed do
142
- configure_syntax :should
143
- configure_syntax [:should, :expect]
144
- configured_syntax.should eq([:should, :expect])
145
-
146
- 3.should eq(3)
147
- 3.should_not eq(4)
148
- expect(3).to eq(3)
149
- end
150
- end
151
-
152
- it 'does not add the deprecated #should to ExpectationTarget when only :should is enabled' do
153
- et = Expectations::ExpectationTarget
154
-
155
- sandboxed do
156
- configure_syntax :should
157
- et.new(Proc.new {}).should be_an(et)
158
- et.new(Proc.new {}).should_not be_a(Proc)
159
- end
160
- end
161
-
162
- it 'does not add the deprecated #should to ExpectationTarget when only :expect is enabled' do
163
- sandboxed do
164
- configure_syntax :expect
165
- expect(expect(3)).not_to respond_to(:should)
166
- expect(expect(3)).not_to respond_to(:should_not)
167
- end
168
- end
169
-
170
- context 'when both :expect and :should are enabled' do
171
- before { RSpec.stub(:warn) }
172
-
173
- it 'allows `expect {}.should` to be used' do
174
- sandboxed do
175
- configure_syntax [:should, :expect]
176
- expect { raise "boom" }.should raise_error("boom")
177
- expect { }.should_not raise_error
178
- end
179
- end
180
-
181
- it 'prints a deprecation notice when `expect {}.should` is used' do
182
- sandboxed do
183
- configure_syntax [:should, :expect]
184
-
185
- RSpec.should_receive(:warn).with(/please use `expect \{ \}.to.*instead/)
186
- expect { raise "boom" }.should raise_error("boom")
187
-
188
- RSpec.should_receive(:warn).with(/please use `expect \{ \}.to_not.*instead/)
189
- expect { }.should_not raise_error
190
- end
191
- end
192
- end
193
- end
194
-
195
- describe "configuring rspec-expectations directly" do
196
- it_behaves_like "configuring the expectation syntax" do
197
- def configure_syntax(syntax)
198
- RSpec::Matchers.configuration.syntax = syntax
199
- end
200
-
201
- def configured_syntax
202
- RSpec::Matchers.configuration.syntax
203
- end
204
- end
205
- end
206
-
207
- describe "configuring using the rspec-core config API" do
208
- it_behaves_like "configuring the expectation syntax" do
209
- def configure_syntax(syntax)
210
- RSpec.configure do |rspec|
211
- rspec.expect_with :rspec do |c|
212
- c.syntax = syntax
213
- end
214
- end
215
- end
216
-
217
- def configured_syntax
218
- RSpec.configure do |rspec|
219
- rspec.expect_with :rspec do |c|
220
- return c.syntax
221
- end
222
- end
223
- end
224
- end
225
- end
226
-
227
- it 'enables both syntaxes by default' do
228
- # This is kinda a hack, but since we want to enforce use of
229
- # the expect syntax within our specs here, we have modified the
230
- # config setting, which makes it hard to get at the original
231
- # default value. in spec_helper.rb we store the default value
232
- # in $default_expectation_syntax so we can use it here.
233
- expect($default_expectation_syntax).to match_array([:expect, :should])
234
- end
235
- end
236
- end
237
- end
238
-
@@ -1,69 +0,0 @@
1
- require 'spec_helper'
2
-
3
- if (1..2).respond_to?(:cover?)
4
- describe "expect(...).to cover(expected)" do
5
- it_behaves_like "an RSpec matcher", :valid_value => (1..10), :invalid_value => (20..30) do
6
- let(:matcher) { cover(5) }
7
- end
8
-
9
- context "for a range target" do
10
- it "passes if target covers expected" do
11
- expect((1..10)).to cover(5)
12
- end
13
-
14
- it "fails if target does not cover expected" do
15
- expect {
16
- expect((1..10)).to cover(11)
17
- }.to fail_with("expected 1..10 to cover 11")
18
- end
19
- end
20
- end
21
-
22
- describe "expect(...).to cover(with, multiple, args)" do
23
- context "for a range target" do
24
- it "passes if target covers all items" do
25
- expect((1..10)).to cover(4, 6)
26
- end
27
-
28
- it "fails if target does not cover any one of the items" do
29
- expect {
30
- expect((1..10)).to cover(4, 6, 11)
31
- }.to fail_with("expected 1..10 to cover 4, 6, and 11")
32
- end
33
- end
34
- end
35
-
36
- describe "expect(...).not_to cover(expected)" do
37
- context "for a range target" do
38
- it "passes if target does not cover expected" do
39
- expect((1..10)).not_to cover(11)
40
- end
41
-
42
- it "fails if target covers expected" do
43
- expect {
44
- expect((1..10)).not_to cover(5)
45
- }.to fail_with("expected 1..10 not to cover 5")
46
- end
47
- end
48
- end
49
-
50
- describe "expect(...).not_to cover(with, multiple, args)" do
51
- context "for a range target" do
52
- it "passes if the target does not cover any of the expected" do
53
- expect((1..10)).not_to cover(11, 12, 13)
54
- end
55
-
56
- it "fails if the target covers all of the expected" do
57
- expect {
58
- expect((1..10)).not_to cover(4, 6)
59
- }.to fail_with("expected 1..10 not to cover 4 and 6")
60
- end
61
-
62
- it "fails if the target covers some (but not all) of the expected" do
63
- expect {
64
- expect((1..10)).not_to cover(5, 11)
65
- }.to fail_with("expected 1..10 not to cover 5 and 11")
66
- end
67
- end
68
- end
69
- end
@@ -1,176 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "Matchers should be able to generate their own descriptions" do
4
- after(:each) do
5
- RSpec::Matchers.clear_generated_description
6
- end
7
-
8
- it "expect(...).to eq expected" do
9
- expect("this").to eq "this"
10
- expect(RSpec::Matchers.generated_description).to eq "should eq \"this\""
11
- end
12
-
13
- it "expect(...).to not eq expected" do
14
- expect("this").not_to eq "that"
15
- expect(RSpec::Matchers.generated_description).to eq "should not eq \"that\""
16
- end
17
-
18
- it "expect(...).to be empty (arbitrary predicate)" do
19
- expect([]).to be_empty
20
- expect(RSpec::Matchers.generated_description).to eq "should be empty"
21
- end
22
-
23
- it "expect(...).to not be empty (arbitrary predicate)" do
24
- expect([1]).not_to be_empty
25
- expect(RSpec::Matchers.generated_description).to eq "should not be empty"
26
- end
27
-
28
- it "expect(...).to be true" do
29
- expect(true).to be_true
30
- expect(RSpec::Matchers.generated_description).to eq "should be true"
31
- end
32
-
33
- it "expect(...).to be false" do
34
- expect(false).to be_false
35
- expect(RSpec::Matchers.generated_description).to eq "should be false"
36
- end
37
-
38
- it "expect(...).to be nil" do
39
- expect(nil).to be_nil
40
- expect(RSpec::Matchers.generated_description).to eq "should be nil"
41
- end
42
-
43
- it "expect(...).to be > n" do
44
- expect(5).to be > 3
45
- expect(RSpec::Matchers.generated_description).to eq "should be > 3"
46
- end
47
-
48
- it "expect(...).to be predicate arg1, arg2 and arg3" do
49
- expect(5.0).to be_between(0,10)
50
- expect(RSpec::Matchers.generated_description).to eq "should be between 0 and 10"
51
- end
52
-
53
- it "expect(...).to equal" do
54
- expected = "expected"
55
- expect(expected).to equal(expected)
56
- expect(RSpec::Matchers.generated_description).to eq "should equal \"expected\""
57
- end
58
-
59
- it "expect(...).not_to equal" do
60
- expect(5).not_to equal(37)
61
- expect(RSpec::Matchers.generated_description).to eq "should not equal 37"
62
- end
63
-
64
- it "expect(...).to eql" do
65
- expect("string").to eql("string")
66
- expect(RSpec::Matchers.generated_description).to eq "should eql \"string\""
67
- end
68
-
69
- it "expect(...).not_to eql" do
70
- expect("a").not_to eql(:a)
71
- expect(RSpec::Matchers.generated_description).to eq "should not eql :a"
72
- end
73
-
74
- it "expect(...).to have_key" do
75
- expect({:a => "a"}).to have_key(:a)
76
- expect(RSpec::Matchers.generated_description).to eq "should have key :a"
77
- end
78
-
79
- it "expect(...).to have_some_method" do
80
- object = Object.new
81
- def object.has_eyes_closed?; true; end
82
-
83
- expect(object).to have_eyes_closed
84
- expect(RSpec::Matchers.generated_description).to eq 'should have eyes closed'
85
- end
86
-
87
- it "expect(...).to have_some_method(args*)" do
88
- object = Object.new
89
- def object.has_taste_for?(*args); true; end
90
-
91
- expect(object).to have_taste_for("wine", "cheese")
92
- expect(RSpec::Matchers.generated_description).to eq 'should have taste for "wine", "cheese"'
93
- end
94
-
95
- it "expect(...).to have n items" do
96
- expect(team).to have(3).players
97
- expect(RSpec::Matchers.generated_description).to eq "should have 3 players"
98
- end
99
-
100
- it "expect(...).to have at least n items" do
101
- expect(team).to have_at_least(2).players
102
- expect(RSpec::Matchers.generated_description).to eq "should have at least 2 players"
103
- end
104
-
105
- it "expect(...).to have at most n items" do
106
- expect(team).to have_at_most(4).players
107
- expect(RSpec::Matchers.generated_description).to eq "should have at most 4 players"
108
- end
109
-
110
- it "expect(...).to include" do
111
- expect([1,2,3]).to include(3)
112
- expect(RSpec::Matchers.generated_description).to eq "should include 3"
113
- end
114
-
115
- it "expect(array).not_to match_array [1,2,3]" do
116
- expect([1,2,3]).to match_array [1,2,3]
117
- expect(RSpec::Matchers.generated_description).to eq "should contain exactly 1, 2 and 3"
118
- end
119
-
120
- it "expect(...).to match" do
121
- expect("this string").to match(/this string/)
122
- expect(RSpec::Matchers.generated_description).to eq "should match /this string/"
123
- end
124
-
125
- it "expect(...).to raise_error" do
126
- expect { raise }.to raise_error
127
- expect(RSpec::Matchers.generated_description).to eq "should raise Exception"
128
- end
129
-
130
- it "expect(...).to raise_error with type" do
131
- expect { raise }.to raise_error(RuntimeError)
132
- expect(RSpec::Matchers.generated_description).to eq "should raise RuntimeError"
133
- end
134
-
135
- it "expect(...).to raise_error with type and message" do
136
- expect { raise "there was an error" }.to raise_error(RuntimeError, "there was an error")
137
- expect(RSpec::Matchers.generated_description).to eq "should raise RuntimeError with \"there was an error\""
138
- end
139
-
140
- it "expect(...).to respond_to" do
141
- expect([]).to respond_to(:insert)
142
- expect(RSpec::Matchers.generated_description).to eq "should respond to #insert"
143
- end
144
-
145
- it "expect(...).to throw symbol" do
146
- expect { throw :what_a_mess }.to throw_symbol
147
- expect(RSpec::Matchers.generated_description).to eq "should throw a Symbol"
148
- end
149
-
150
- it "expect(...).to throw symbol (with named symbol)" do
151
- expect { throw :what_a_mess }.to throw_symbol(:what_a_mess)
152
- expect(RSpec::Matchers.generated_description).to eq "should throw :what_a_mess"
153
- end
154
-
155
- def team
156
- Class.new do
157
- def players
158
- [1,2,3]
159
- end
160
- end.new
161
- end
162
- end
163
-
164
- describe "a Matcher with no description" do
165
- def matcher
166
- Class.new do
167
- def matches?(ignore); true; end
168
- def failure_message; ""; end
169
- end.new
170
- end
171
-
172
- it "provides a helpful message when used in a string-less example block" do
173
- expect(5).to matcher
174
- expect(RSpec::Matchers.generated_description).to match /When you call.*description method/m
175
- end
176
- end
@@ -1,57 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "a matcher defined using the matcher DSL" do
4
- def question?
5
- :answer
6
- end
7
-
8
- def ok
9
- "ok"
10
- end
11
-
12
- it "supports calling custom matchers from within other custom matchers" do
13
- RSpec::Matchers.define :be_ok do
14
- match { |actual| actual == ok }
15
- end
16
-
17
- RSpec::Matchers.define :be_well do
18
- match { |actual| expect(actual).to be_ok }
19
- end
20
-
21
- expect(ok).to be_well
22
- end
23
-
24
- it "has access to methods available in the scope of the example" do
25
- RSpec::Matchers::define(:matcher_a) {}
26
- expect(matcher_a.question?).to eq(:answer)
27
- end
28
-
29
- it "raises when method is missing from local scope as well as matcher" do
30
- RSpec::Matchers::define(:matcher_b) {}
31
- expect { matcher_b.i_dont_exist }.to raise_error(NameError)
32
- end
33
-
34
- it "clears user instance variables between invocations" do
35
- RSpec::Matchers::define(:be_just_like) do |expected|
36
- match do |actual|
37
- @foo ||= expected
38
- @foo == actual
39
- end
40
- end
41
-
42
- expect(3).to be_just_like(3)
43
- expect(4).to be_just_like(4)
44
- end
45
-
46
- describe "#respond_to?" do
47
- it "returns true for methods in example scope" do
48
- RSpec::Matchers::define(:matcher_c) {}
49
- expect(matcher_c).to respond_to(:question?)
50
- end
51
-
52
- it "returns false for methods not defined in matcher or example scope" do
53
- RSpec::Matchers::define(:matcher_d) {}
54
- expect(matcher_d).not_to respond_to(:i_dont_exist)
55
- end
56
- end
57
- end
@@ -1,60 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module RSpec
4
- module Matchers
5
- describe "eq" do
6
- it_behaves_like "an RSpec matcher", :valid_value => 1, :invalid_value => 2 do
7
- let(:matcher) { eq(1) }
8
- end
9
-
10
- it "is diffable" do
11
- expect(eq(1)).to be_diffable
12
- end
13
-
14
- it "matches when actual == expected" do
15
- expect(1).to eq(1)
16
- end
17
-
18
- it "does not match when actual != expected" do
19
- expect(1).not_to eq(2)
20
- end
21
-
22
- it "compares by sending == to actual (not expected)" do
23
- called = false
24
- actual = Class.new do
25
- define_method :== do |other|
26
- called = true
27
- end
28
- end.new
29
-
30
- expect(actual).to eq :anything # to trigger the matches? method
31
- expect(called).to be_true
32
- end
33
-
34
- it "describes itself" do
35
- matcher = eq(1)
36
- matcher.matches?(1)
37
- expect(matcher.description).to eq "eq 1"
38
- end
39
-
40
- it "provides message, expected and actual on #failure_message" do
41
- matcher = eq("1")
42
- matcher.matches?(1)
43
- expect(matcher.failure_message_for_should).to eq "\nexpected: \"1\"\n got: 1\n\n(compared using ==)\n"
44
- end
45
-
46
- it "provides message, expected and actual on #negative_failure_message" do
47
- matcher = eq(1)
48
- matcher.matches?(1)
49
- expect(matcher.failure_message_for_should_not).to eq "\nexpected: value != 1\n got: 1\n\n(compared using ==)\n"
50
- end
51
-
52
- it 'fails properly when the actual is an array of multiline strings' do
53
- expect {
54
- expect(["a\nb", "c\nd"]).to eq([])
55
- }.to fail_matching("expected: []")
56
- end
57
- end
58
- end
59
- end
60
-
@@ -1,41 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module RSpec
4
- module Matchers
5
- describe "eql" do
6
- it_behaves_like "an RSpec matcher", :valid_value => 1, :invalid_value => 2 do
7
- let(:matcher) { eql(1) }
8
- end
9
-
10
- it "is diffable" do
11
- expect(eql(1)).to be_diffable
12
- end
13
-
14
- it "matches when actual.eql?(expected)" do
15
- expect(1).to eql(1)
16
- end
17
-
18
- it "does not match when !actual.eql?(expected)" do
19
- expect(1).not_to eql(2)
20
- end
21
-
22
- it "describes itself" do
23
- matcher = eql(1)
24
- matcher.matches?(1)
25
- expect(matcher.description).to eq "eql 1"
26
- end
27
-
28
- it "provides message, expected and actual on #failure_message" do
29
- matcher = eql("1")
30
- matcher.matches?(1)
31
- expect(matcher.failure_message_for_should).to eq "\nexpected: \"1\"\n got: 1\n\n(compared using eql?)\n"
32
- end
33
-
34
- it "provides message, expected and actual on #negative_failure_message" do
35
- matcher = eql(1)
36
- matcher.matches?(1)
37
- expect(matcher.failure_message_for_should_not).to eq "\nexpected: value != 1\n got: 1\n\n(compared using eql?)\n"
38
- end
39
- end
40
- end
41
- end