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,206 +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
- @old_patterns = RSpec.configuration.backtrace_exclusion_patterns
26
- RSpec.configuration.backtrace_exclusion_patterns = [/clean-me/]
27
- end
28
-
29
- after do
30
- RSpec.configuration.backtrace_exclusion_patterns = @old_patterns
31
- end
32
-
33
- it "defaults to rspec-core's backtrace formatter when rspec-core is loaded" do
34
- expect(config.backtrace_formatter).to be(RSpec::Core::BacktraceFormatter)
35
- expect(formatted_backtrace).to eq(cleaned_backtrace)
36
- end
37
-
38
- it "defaults to a null formatter when rspec-core is not loaded" do
39
- hide_const("RSpec::Core::BacktraceFormatter")
40
- expect(formatted_backtrace).to eq(original_backtrace)
41
- end
42
-
43
- it "can be set to another backtrace formatter" do
44
- config.backtrace_formatter = double(:format_backtrace => ['a'])
45
- expect(formatted_backtrace).to eq(['a'])
46
- end
47
- end
48
-
49
- context 'on an interpreter that does not provide BasicObject', :uses_should, :unless => defined?(::BasicObject) do
50
- before { RSpec::Expectations::Syntax.disable_should(Delegator) }
51
-
52
- let(:klass) do
53
- Class.new(SimpleDelegator) do
54
- def delegated?; true; end
55
- end
56
- end
57
-
58
- let(:instance) { klass.new(Object.new) }
59
-
60
- it 'provides a means to manually add it Delegator' do
61
- instance.should_not respond_to(:delegated?) # because #should is being delegated...
62
- config.add_should_and_should_not_to Delegator
63
- instance.should respond_to(:delegated?) # now it should work!
64
- end
65
- end
66
-
67
- shared_examples_for "configuring the expectation syntax" do
68
- before do
69
- @orig_syntax = RSpec::Matchers.configuration.syntax
70
- end
71
-
72
- after do
73
- configure_syntax(@orig_syntax)
74
- end
75
-
76
- it 'can limit the syntax to :should' do
77
- configure_syntax :should
78
- configured_syntax.should eq([:should])
79
-
80
- 3.should eq(3)
81
- 3.should_not eq(4)
82
- lambda { expect(6).to eq(6) }.should raise_error(NameError)
83
- end
84
-
85
- it 'is a no-op when configured to :should twice' do
86
- configure_syntax :should
87
- Expectations::Syntax.default_should_host.should_not_receive(:method_added)
88
- configure_syntax :should
89
- RSpec::Mocks.verify # because configure_syntax is called again in an after hook
90
- end
91
-
92
- it 'can limit the syntax to :expect' do
93
- configure_syntax :expect
94
- expect(configured_syntax).to eq([:expect])
95
-
96
- expect(3).to eq(3)
97
- expect { 3.should eq(3) }.to raise_error(NameError)
98
- expect { 3.should_not eq(3) }.to raise_error(NameError)
99
- end
100
-
101
- it 'is a no-op when configured to :expect twice' do
102
- RSpec::Matchers.stub(:method_added).and_raise("no methods should be added here")
103
-
104
- configure_syntax :expect
105
- configure_syntax :expect
106
- end
107
-
108
- it 'can re-enable the :should syntax' do
109
- configure_syntax :expect
110
- configure_syntax [:should, :expect]
111
- configured_syntax.should eq([:should, :expect])
112
-
113
- 3.should eq(3)
114
- 3.should_not eq(4)
115
- expect(3).to eq(3)
116
- end
117
-
118
- it 'can re-enable the :expect syntax' do
119
- configure_syntax :should
120
- configure_syntax [:should, :expect]
121
- configured_syntax.should eq([:should, :expect])
122
-
123
- 3.should eq(3)
124
- 3.should_not eq(4)
125
- expect(3).to eq(3)
126
- end
127
-
128
- it 'does not add the deprecated #should to ExpectationTarget when only :should is enabled' do
129
- et = Expectations::ExpectationTarget
130
-
131
- configure_syntax :should
132
- et.new(Proc.new {}).should be_an(et)
133
- et.new(Proc.new {}).should_not be_a(Proc)
134
- end
135
-
136
- it 'does not add the deprecated #should to ExpectationTarget when only :expect is enabled' do
137
- configure_syntax :expect
138
- expect(expect(3)).not_to respond_to(:should)
139
- expect(expect(3)).not_to respond_to(:should_not)
140
- end
141
-
142
- context 'when both :expect and :should are enabled' do
143
- before { allow(RSpec).to receive(:deprecate) }
144
-
145
- it 'allows `expect {}.should` to be used' do
146
- configure_syntax [:should, :expect]
147
- expect { raise "boom" }.should raise_error("boom")
148
- expect { }.should_not raise_error
149
- end
150
-
151
- it 'prints a deprecation notice when `expect {}.should` is used' do
152
- configure_syntax [:should, :expect]
153
-
154
- expect(RSpec).to receive(:deprecate)
155
- expect { raise "boom" }.should raise_error("boom")
156
-
157
- expect(RSpec).to receive(:deprecate)
158
- expect { }.should_not raise_error
159
- end
160
- end
161
- end
162
-
163
- describe "configuring rspec-expectations directly" do
164
- it_behaves_like "configuring the expectation syntax" do
165
- def configure_syntax(syntax)
166
- RSpec::Matchers.configuration.syntax = syntax
167
- end
168
-
169
- def configured_syntax
170
- RSpec::Matchers.configuration.syntax
171
- end
172
- end
173
- end
174
-
175
- describe "configuring using the rspec-core config API" do
176
- it_behaves_like "configuring the expectation syntax" do
177
- def configure_syntax(syntax)
178
- RSpec.configure do |rspec|
179
- rspec.expect_with :rspec do |c|
180
- c.syntax = syntax
181
- end
182
- end
183
- end
184
-
185
- def configured_syntax
186
- RSpec.configure do |rspec|
187
- rspec.expect_with :rspec do |c|
188
- return c.syntax
189
- end
190
- end
191
- end
192
- end
193
- end
194
-
195
- it 'enables both syntaxes by default' do
196
- # This is kinda a hack, but since we want to enforce use of
197
- # the expect syntax within our specs here, we have modified the
198
- # config setting, which makes it hard to get at the original
199
- # default value. in spec_helper.rb we store the default value
200
- # in $default_expectation_syntax so we can use it here.
201
- expect($default_expectation_syntax).to match_array([:expect, :should])
202
- end
203
- end
204
- end
205
- end
206
-
@@ -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,190 +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(x)" 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(...).to include(x) when x responds to description but is not a matcher" do
116
- obj = double(:description => "description", :inspect => "inspect")
117
- expect([obj]).to include(obj)
118
- expect(RSpec::Matchers.generated_description).to eq "should include inspect"
119
- end
120
-
121
- it "expect(...).to include(x) when x responds to description and is a matcher" do
122
- matcher = double(:description => "description",
123
- :matches? => true,
124
- :failure_message_for_should => "")
125
- expect([matcher]).to include(matcher)
126
- expect(RSpec::Matchers.generated_description).to eq "should include description"
127
- end
128
-
129
- it "expect(array).not_to match_array [1,2,3]" do
130
- expect([1,2,3]).to match_array [1,2,3]
131
- expect(RSpec::Matchers.generated_description).to eq "should contain exactly 1, 2 and 3"
132
- end
133
-
134
- it "expect(...).to match" do
135
- expect("this string").to match(/this string/)
136
- expect(RSpec::Matchers.generated_description).to eq "should match /this string/"
137
- end
138
-
139
- it "expect(...).to raise_error" do
140
- expect { raise }.to raise_error
141
- expect(RSpec::Matchers.generated_description).to eq "should raise Exception"
142
- end
143
-
144
- it "expect(...).to raise_error with type" do
145
- expect { raise }.to raise_error(RuntimeError)
146
- expect(RSpec::Matchers.generated_description).to eq "should raise RuntimeError"
147
- end
148
-
149
- it "expect(...).to raise_error with type and message" do
150
- expect { raise "there was an error" }.to raise_error(RuntimeError, "there was an error")
151
- expect(RSpec::Matchers.generated_description).to eq "should raise RuntimeError with \"there was an error\""
152
- end
153
-
154
- it "expect(...).to respond_to" do
155
- expect([]).to respond_to(:insert)
156
- expect(RSpec::Matchers.generated_description).to eq "should respond to #insert"
157
- end
158
-
159
- it "expect(...).to throw symbol" do
160
- expect { throw :what_a_mess }.to throw_symbol
161
- expect(RSpec::Matchers.generated_description).to eq "should throw a Symbol"
162
- end
163
-
164
- it "expect(...).to throw symbol (with named symbol)" do
165
- expect { throw :what_a_mess }.to throw_symbol(:what_a_mess)
166
- expect(RSpec::Matchers.generated_description).to eq "should throw :what_a_mess"
167
- end
168
-
169
- def team
170
- Class.new do
171
- def players
172
- [1,2,3]
173
- end
174
- end.new
175
- end
176
- end
177
-
178
- describe "a Matcher with no description" do
179
- def matcher
180
- Class.new do
181
- def matches?(ignore); true; end
182
- def failure_message; ""; end
183
- end.new
184
- end
185
-
186
- it "provides a helpful message when used in a string-less example block" do
187
- expect(5).to matcher
188
- expect(RSpec::Matchers.generated_description).to match(/When you call.*description method/m)
189
- end
190
- 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
@@ -1,78 +0,0 @@
1
- require 'spec_helper'
2
- module RSpec
3
- module Matchers
4
- describe "equal" do
5
- it_behaves_like "an RSpec matcher", :valid_value => :a, :invalid_value => :b do
6
- let(:matcher) { equal(:a) }
7
- end
8
-
9
- def inspect_object(o)
10
- "#<#{o.class}:#{o.object_id}> => #{o.inspect}"
11
- end
12
-
13
- it "matches when actual.equal?(expected)" do
14
- expect(1).to equal(1)
15
- end
16
-
17
- it "does not match when !actual.equal?(expected)" do
18
- expect("1").not_to equal("1")
19
- end
20
-
21
- it "describes itself" do
22
- matcher = equal(1)
23
- matcher.matches?(1)
24
- expect(matcher.description).to eq "equal 1"
25
- end
26
-
27
- it "suggests the `eq` matcher on failure" do
28
- expected, actual = "1", "1"
29
- expect {
30
- expect(actual).to equal(expected)
31
- }.to fail_with <<-MESSAGE
32
-
33
- expected #{inspect_object(expected)}
34
- got #{inspect_object(actual)}
35
-
36
- Compared using equal?, which compares object identity,
37
- but expected and actual are not the same object. Use
38
- `expect(actual).to eq(expected)` if you don't care about
39
- object identity in this example.
40
-
41
- MESSAGE
42
- end
43
-
44
- context "when using only `should`", :uses_only_should do
45
- it "suggests the `eq` matcher on failure" do
46
- expected, actual = "1", "1"
47
- lambda {
48
- actual.should equal(expected)
49
- }.should fail_with <<-MESSAGE
50
-
51
- expected #{inspect_object(expected)}
52
- got #{inspect_object(actual)}
53
-
54
- Compared using equal?, which compares object identity,
55
- but expected and actual are not the same object. Use
56
- `actual.should eq(expected)` if you don't care about
57
- object identity in this example.
58
-
59
- MESSAGE
60
- end
61
- end
62
-
63
- it "provides message on #negative_failure_message" do
64
- expected = actual = "1"
65
- matcher = equal(expected)
66
- matcher.matches?(actual)
67
- expect(matcher.failure_message_for_should_not).to eq <<-MESSAGE
68
-
69
- expected not #{inspect_object(expected)}
70
- got #{inspect_object(actual)}
71
-
72
- Compared using equal?, which compares object identity.
73
-
74
- MESSAGE
75
- end
76
- end
77
- end
78
- end