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,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
@@ -1,124 +0,0 @@
1
- require 'spec_helper'
2
- require 'ostruct'
3
-
4
- describe "exist matcher" do
5
- it_behaves_like "an RSpec matcher", :valid_value => OpenStruct.new(:exist? => true),
6
- :invalid_value => OpenStruct.new(:exist? => false) do
7
- let(:matcher) { exist }
8
- end
9
-
10
- context "when the object does not respond to #exist? or #exists?" do
11
- subject { mock }
12
-
13
- [:to, :not_to].each do |expect_method|
14
- describe "expect(...).#{expect_method} exist" do
15
- it "raises an error" do
16
- expect {
17
- expect(subject).send(expect_method, exist)
18
- }.to raise_error(NoMethodError)
19
- end
20
- end
21
- end
22
- end
23
-
24
- [:exist?, :exists?].each do |predicate|
25
- context "when the object responds to ##{predicate}" do
26
- describe "expect(...).to exist" do
27
- it "passes if #{predicate}" do
28
- expect(mock(predicate => true)).to exist
29
- end
30
-
31
- it "fails if not #{predicate}" do
32
- expect {
33
- expect(mock(predicate => false)).to exist
34
- }.to fail_with(/expected .* to exist/)
35
- end
36
-
37
- it 'works when the object overrides `send`' do
38
- klass = Struct.new(:message) do
39
- def send
40
- :message_sent
41
- end
42
-
43
- define_method predicate do
44
- true
45
- end
46
- end
47
-
48
- expect(klass.new("msg")).to exist
49
- end
50
- end
51
-
52
- describe "expect(...).not_to exist" do
53
- it "passes if not #{predicate}" do
54
- expect(mock(predicate => false)).not_to exist
55
- end
56
-
57
- it "fails if #{predicate}" do
58
- expect {
59
- expect(mock(predicate => true)).not_to exist
60
- }.to fail_with(/expected .* not to exist/)
61
- end
62
- end
63
- end
64
- end
65
-
66
- context "when the object responds to #exist? and #exists?" do
67
- context "when they both return falsey values" do
68
- subject { mock(:exist? => false, :exists? => nil) }
69
-
70
- describe "expect(...).not_to exist" do
71
- it "passes" do
72
- expect(subject).not_to exist
73
- end
74
- end
75
-
76
- describe "expect(...).to exist" do
77
- it "fails" do
78
- expect {
79
- expect(subject).to exist
80
- }.to fail_with(/expected .* to exist/)
81
- end
82
- end
83
- end
84
-
85
- context "when they both return truthy values" do
86
- subject { mock(:exist? => true, :exists? => "something true") }
87
-
88
- describe "expect(...).not_to exist" do
89
- it "fails" do
90
- expect {
91
- expect(subject).not_to exist
92
- }.to fail_with(/expected .* not to exist/)
93
- end
94
- end
95
-
96
- describe "expect(...).to exist" do
97
- it "passes" do
98
- expect(subject).to exist
99
- end
100
- end
101
- end
102
-
103
- context "when they return values with different truthiness" do
104
- subject { mock(:exist? => true, :exists? => false) }
105
-
106
- [:to, :not_to].each do |expect_method|
107
- describe "expect(...).#{expect_method} exist" do
108
- it "raises an error" do
109
- expect {
110
- expect(subject).send(expect_method, exist)
111
- }.to raise_error(/#exist\? and #exists\? returned different values/)
112
- end
113
- end
114
- end
115
- end
116
- end
117
-
118
- it 'passes any provided arguments to the call to #exist?' do
119
- object = mock
120
- object.should_receive(:exist?).with(:foo, :bar) { true }
121
-
122
- expect(object).to exist(:foo, :bar)
123
- end
124
- end
@@ -1,122 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "expect(...).to have_sym(*args)" do
4
- it_behaves_like "an RSpec matcher", :valid_value => { :a => 1 },
5
- :invalid_value => {} do
6
- let(:matcher) { have_key(:a) }
7
- end
8
-
9
- it "passes if #has_sym?(*args) returns true" do
10
- expect({:a => "A"}).to have_key(:a)
11
- end
12
-
13
- it "fails if #has_sym?(*args) returns false" do
14
- expect {
15
- expect({:b => "B"}).to have_key(:a)
16
- }.to fail_with("expected #has_key?(:a) to return true, got false")
17
- end
18
-
19
- it 'does not include any args in the failure message if no args were given to the matcher' do
20
- o = Object.new
21
- def o.has_some_stuff?; false; end
22
- expect {
23
- expect(o).to have_some_stuff
24
- }.to fail_with("expected #has_some_stuff? to return true, got false")
25
- end
26
-
27
- it 'includes multiple args in the failure message if multiple args were given to the matcher' do
28
- o = Object.new
29
- def o.has_some_stuff?(*_); false; end
30
- expect {
31
- expect(o).to have_some_stuff(:a, 7, "foo")
32
- }.to fail_with('expected #has_some_stuff?(:a, 7, "foo") to return true, got false')
33
- end
34
-
35
- it "fails if #has_sym?(*args) returns nil" do
36
- klass = Class.new do
37
- def has_foo?
38
- end
39
- end
40
- expect {
41
- expect(klass.new).to have_foo
42
- }.to fail_with(/expected #has_foo.* to return true, got false/)
43
- end
44
-
45
- it "fails if target does not respond to #has_sym?" do
46
- expect {
47
- expect(Object.new).to have_key(:a)
48
- }.to raise_error(NoMethodError)
49
- end
50
-
51
- it "reraises an exception thrown in #has_sym?(*args)" do
52
- o = Object.new
53
- def o.has_sym?(*args)
54
- raise "Funky exception"
55
- end
56
- expect {
57
- expect(o).to have_sym(:foo)
58
- }.to raise_error("Funky exception")
59
- end
60
- end
61
-
62
- describe "expect(...).not_to have_sym(*args)" do
63
- it "passes if #has_sym?(*args) returns false" do
64
- expect({:a => "A"}).not_to have_key(:b)
65
- end
66
-
67
- it "passes if #has_sym?(*args) returns nil" do
68
- klass = Class.new do
69
- def has_foo?
70
- end
71
- end
72
- expect(klass.new).not_to have_foo
73
- end
74
-
75
- it "fails if #has_sym?(*args) returns true" do
76
- expect {
77
- expect({:a => "A"}).not_to have_key(:a)
78
- }.to fail_with("expected #has_key?(:a) to return false, got true")
79
- end
80
-
81
- it "fails if target does not respond to #has_sym?" do
82
- expect {
83
- expect(Object.new).to have_key(:a)
84
- }.to raise_error(NoMethodError)
85
- end
86
-
87
- it "reraises an exception thrown in #has_sym?(*args)" do
88
- o = Object.new
89
- def o.has_sym?(*args)
90
- raise "Funky exception"
91
- end
92
- expect {
93
- expect(o).not_to have_sym(:foo)
94
- }.to raise_error("Funky exception")
95
- end
96
-
97
- it 'does not include any args in the failure message if no args were given to the matcher' do
98
- o = Object.new
99
- def o.has_some_stuff?; true; end
100
- expect {
101
- expect(o).not_to have_some_stuff
102
- }.to fail_with("expected #has_some_stuff? to return false, got true")
103
- end
104
-
105
- it 'includes multiple args in the failure message if multiple args were given to the matcher' do
106
- o = Object.new
107
- def o.has_some_stuff?(*_); true; end
108
- expect {
109
- expect(o).not_to have_some_stuff(:a, 7, "foo")
110
- }.to fail_with('expected #has_some_stuff?(:a, 7, "foo") to return false, got true')
111
- end
112
- end
113
-
114
- describe "has" do
115
- it "works when the target implements #send" do
116
- o = {:a => "A"}
117
- def o.send(*args); raise "DOH! Library developers shouldn't use #send!" end
118
- expect {
119
- expect(o).to have_key(:a)
120
- }.to_not raise_error
121
- end
122
- end