rspec-expectations 3.0.0.beta2 → 3.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +2 -2
  4. data/.yardopts +0 -1
  5. data/Changelog.md +115 -35
  6. data/README.md +2 -2
  7. data/lib/rspec/expectations.rb +13 -8
  8. data/lib/rspec/{matchers → expectations}/configuration.rb +38 -13
  9. data/lib/rspec/expectations/expectation_target.rb +72 -8
  10. data/lib/rspec/expectations/fail_with.rb +10 -52
  11. data/lib/rspec/expectations/handler.rb +9 -11
  12. data/lib/rspec/expectations/syntax.rb +37 -35
  13. data/lib/rspec/expectations/version.rb +1 -1
  14. data/lib/rspec/matchers.rb +60 -9
  15. data/lib/rspec/matchers/aliased_matcher.rb +6 -0
  16. data/lib/rspec/matchers/built_in.rb +9 -1
  17. data/lib/rspec/matchers/built_in/all.rb +78 -0
  18. data/lib/rspec/matchers/built_in/base_matcher.rb +39 -1
  19. data/lib/rspec/matchers/built_in/be.rb +117 -42
  20. data/lib/rspec/matchers/built_in/be_between.rb +22 -0
  21. data/lib/rspec/matchers/built_in/be_instance_of.rb +11 -3
  22. data/lib/rspec/matchers/built_in/be_kind_of.rb +5 -0
  23. data/lib/rspec/matchers/built_in/be_within.rb +26 -6
  24. data/lib/rspec/matchers/built_in/change.rb +89 -13
  25. data/lib/rspec/matchers/built_in/compound.rb +19 -3
  26. data/lib/rspec/matchers/built_in/contain_exactly.rb +17 -6
  27. data/lib/rspec/matchers/built_in/cover.rb +3 -0
  28. data/lib/rspec/matchers/built_in/eq.rb +20 -5
  29. data/lib/rspec/matchers/built_in/eql.rb +15 -3
  30. data/lib/rspec/matchers/built_in/equal.rb +23 -6
  31. data/lib/rspec/matchers/built_in/exist.rb +74 -10
  32. data/lib/rspec/matchers/built_in/has.rb +58 -3
  33. data/lib/rspec/matchers/built_in/include.rb +16 -1
  34. data/lib/rspec/matchers/built_in/match.rb +14 -4
  35. data/lib/rspec/matchers/built_in/operators.rb +16 -0
  36. data/lib/rspec/matchers/built_in/output.rb +47 -5
  37. data/lib/rspec/matchers/built_in/raise_error.rb +40 -23
  38. data/lib/rspec/matchers/built_in/respond_to.rb +37 -16
  39. data/lib/rspec/matchers/built_in/satisfy.rb +15 -0
  40. data/lib/rspec/matchers/built_in/start_and_end_with.rb +29 -14
  41. data/lib/rspec/matchers/built_in/throw_symbol.rb +32 -3
  42. data/lib/rspec/matchers/built_in/yield.rb +148 -44
  43. data/lib/rspec/matchers/composable.rb +48 -7
  44. data/lib/rspec/matchers/dsl.rb +45 -17
  45. data/lib/rspec/matchers/generated_descriptions.rb +7 -0
  46. data/lib/rspec/matchers/matcher_delegator.rb +6 -2
  47. data/lib/rspec/matchers/pretty.rb +15 -19
  48. metadata +33 -236
  49. metadata.gz.sig +0 -0
  50. data/features/README.md +0 -48
  51. data/features/Upgrade.md +0 -53
  52. data/features/built_in_matchers/README.md +0 -96
  53. data/features/built_in_matchers/be.feature +0 -175
  54. data/features/built_in_matchers/be_within.feature +0 -48
  55. data/features/built_in_matchers/comparisons.feature +0 -97
  56. data/features/built_in_matchers/contain_exactly.feature +0 -46
  57. data/features/built_in_matchers/cover.feature +0 -47
  58. data/features/built_in_matchers/end_with.feature +0 -48
  59. data/features/built_in_matchers/equality.feature +0 -136
  60. data/features/built_in_matchers/exist.feature +0 -45
  61. data/features/built_in_matchers/expect_change.feature +0 -59
  62. data/features/built_in_matchers/expect_error.feature +0 -144
  63. data/features/built_in_matchers/include.feature +0 -126
  64. data/features/built_in_matchers/match.feature +0 -51
  65. data/features/built_in_matchers/output.feature +0 -70
  66. data/features/built_in_matchers/predicates.feature +0 -161
  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 -161
  73. data/features/composing_matchers.feature +0 -250
  74. data/features/compound_expectations.feature +0 -45
  75. data/features/custom_matchers/access_running_example.feature +0 -53
  76. data/features/custom_matchers/define_diffable_matcher.feature +0 -27
  77. data/features/custom_matchers/define_matcher.feature +0 -340
  78. data/features/custom_matchers/define_matcher_outside_rspec.feature +0 -34
  79. data/features/custom_matchers/define_matcher_with_fluent_interface.feature +0 -24
  80. data/features/customized_message.feature +0 -39
  81. data/features/diffing.feature +0 -85
  82. data/features/implicit_docstrings.feature +0 -52
  83. data/features/step_definitions/additional_cli_steps.rb +0 -22
  84. data/features/support/env.rb +0 -21
  85. data/features/support/rubinius.rb +0 -6
  86. data/features/syntax_configuration.feature +0 -71
  87. data/features/test_frameworks/minitest.feature +0 -44
  88. data/lib/rspec-expectations.rb +0 -1
  89. data/lib/rspec/expectations/diff_presenter.rb +0 -141
  90. data/lib/rspec/expectations/differ.rb +0 -44
  91. data/lib/rspec/expectations/encoded_string.rb +0 -56
  92. data/spec/rspec/expectations/diff_presenter_spec.rb +0 -249
  93. data/spec/rspec/expectations/encoded_string_spec.rb +0 -74
  94. data/spec/rspec/expectations/expectation_target_spec.rb +0 -82
  95. data/spec/rspec/expectations/extensions/kernel_spec.rb +0 -67
  96. data/spec/rspec/expectations/fail_with_spec.rb +0 -114
  97. data/spec/rspec/expectations/handler_spec.rb +0 -205
  98. data/spec/rspec/expectations/minitest_integration_spec.rb +0 -27
  99. data/spec/rspec/expectations/syntax_spec.rb +0 -89
  100. data/spec/rspec/expectations_spec.rb +0 -12
  101. data/spec/rspec/matchers/aliased_matcher_spec.rb +0 -48
  102. data/spec/rspec/matchers/aliases_spec.rb +0 -449
  103. data/spec/rspec/matchers/built_in/base_matcher_spec.rb +0 -83
  104. data/spec/rspec/matchers/built_in/be_between_spec.rb +0 -159
  105. data/spec/rspec/matchers/built_in/be_instance_of_spec.rb +0 -63
  106. data/spec/rspec/matchers/built_in/be_kind_of_spec.rb +0 -41
  107. data/spec/rspec/matchers/built_in/be_spec.rb +0 -592
  108. data/spec/rspec/matchers/built_in/be_within_spec.rb +0 -141
  109. data/spec/rspec/matchers/built_in/change_spec.rb +0 -808
  110. data/spec/rspec/matchers/built_in/compound_spec.rb +0 -292
  111. data/spec/rspec/matchers/built_in/contain_exactly_spec.rb +0 -441
  112. data/spec/rspec/matchers/built_in/cover_spec.rb +0 -69
  113. data/spec/rspec/matchers/built_in/eq_spec.rb +0 -156
  114. data/spec/rspec/matchers/built_in/eql_spec.rb +0 -41
  115. data/spec/rspec/matchers/built_in/equal_spec.rb +0 -106
  116. data/spec/rspec/matchers/built_in/exist_spec.rb +0 -124
  117. data/spec/rspec/matchers/built_in/has_spec.rb +0 -161
  118. data/spec/rspec/matchers/built_in/include_spec.rb +0 -540
  119. data/spec/rspec/matchers/built_in/match_spec.rb +0 -102
  120. data/spec/rspec/matchers/built_in/operators_spec.rb +0 -252
  121. data/spec/rspec/matchers/built_in/output_spec.rb +0 -165
  122. data/spec/rspec/matchers/built_in/raise_error_spec.rb +0 -461
  123. data/spec/rspec/matchers/built_in/respond_to_spec.rb +0 -292
  124. data/spec/rspec/matchers/built_in/satisfy_spec.rb +0 -44
  125. data/spec/rspec/matchers/built_in/start_and_end_with_spec.rb +0 -253
  126. data/spec/rspec/matchers/built_in/throw_symbol_spec.rb +0 -135
  127. data/spec/rspec/matchers/built_in/yield_spec.rb +0 -627
  128. data/spec/rspec/matchers/configuration_spec.rb +0 -213
  129. data/spec/rspec/matchers/description_generation_spec.rb +0 -191
  130. data/spec/rspec/matchers/dsl_spec.rb +0 -895
  131. data/spec/rspec/matchers/legacy_spec.rb +0 -101
  132. data/spec/rspec/matchers_spec.rb +0 -74
  133. data/spec/spec_helper.rb +0 -85
  134. data/spec/support/matchers.rb +0 -22
  135. data/spec/support/shared_examples.rb +0 -35
@@ -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,156 +0,0 @@
1
- require 'spec_helper'
2
- require 'date'
3
- require 'complex'
4
-
5
- module RSpec
6
- module Matchers
7
- describe "eq" do
8
- it_behaves_like "an RSpec matcher", :valid_value => 1, :invalid_value => 2 do
9
- let(:matcher) { eq(1) }
10
- end
11
-
12
- it "is diffable" do
13
- expect(eq(1)).to be_diffable
14
- end
15
-
16
- it "matches when actual == expected" do
17
- expect(1).to eq(1)
18
- end
19
-
20
- it "does not match when actual != expected" do
21
- expect(1).not_to eq(2)
22
- end
23
-
24
- it "compares by sending == to actual (not expected)" do
25
- called = false
26
- actual = Class.new do
27
- define_method :== do |other|
28
- called = true
29
- end
30
- end.new
31
-
32
- expect(actual).to eq :anything # to trigger the matches? method
33
- expect(called).to be_truthy
34
- end
35
-
36
- it "describes itself" do
37
- matcher = eq(1)
38
- matcher.matches?(1)
39
- expect(matcher.description).to eq "eq 1"
40
- end
41
-
42
- it "provides message, expected and actual on #failure_message" do
43
- matcher = eq("1")
44
- matcher.matches?(1)
45
- expect(matcher.failure_message).to eq "\nexpected: \"1\"\n got: 1\n\n(compared using ==)\n"
46
- end
47
-
48
- it "provides message, expected and actual on #negative_failure_message" do
49
- matcher = eq(1)
50
- matcher.matches?(1)
51
- expect(matcher.failure_message_when_negated).to eq "\nexpected: value != 1\n got: 1\n\n(compared using ==)\n"
52
- end
53
-
54
- it 'fails properly when the actual is an array of multiline strings' do
55
- expect {
56
- expect(["a\nb", "c\nd"]).to eq([])
57
- }.to fail_matching("expected: []")
58
- end
59
-
60
- describe '#description' do
61
- [
62
- [nil, 'eq nil'],
63
- [true, 'eq true'],
64
- [false, 'eq false'],
65
- [:symbol, 'eq :symbol'],
66
- [1, 'eq 1'],
67
- [1.2, 'eq 1.2'],
68
- [Complex(1, 2), "eq #{Complex(1, 2).inspect}"],
69
- ['foo', 'eq "foo"'],
70
- [/regex/, 'eq /regex/'],
71
- [['foo'], 'eq ["foo"]'],
72
- [{:foo => :bar}, 'eq {:foo=>:bar}'],
73
- [Class, 'eq Class'],
74
- [RSpec, 'eq RSpec'],
75
- [Date.new(2014, 1, 1), "eq #{Date.new(2014, 1, 1).inspect}"],
76
- [Time.utc(2014, 1, 1), "eq #{Time.utc(2014, 1, 1).inspect}"],
77
- ].each do |expected, expected_description|
78
- context "with #{expected.inspect}" do
79
- it "is \"#{expected_description}\"" do
80
- expect(eq(expected).description).to eq expected_description
81
- end
82
- end
83
- end
84
-
85
- context 'with object' do
86
- it 'matches with "^eq #<Object:0x[0-9a-f]*>$"' do
87
- expect(eq(Object.new).description).to match(/^eq #<Object:0x[0-9a-f]*>$/)
88
- end
89
- end
90
- end
91
-
92
- context "Time Equality" do
93
- RSpec::Matchers.define :a_string_with_differing_output do
94
- match do |string|
95
- time_strings = /expected: (.+)\n.*got: (.+)$/.match(string).captures
96
- time_strings.uniq.count == 2
97
- end
98
- end
99
-
100
- RSpec::Matchers.define :a_string_with_identical_output do
101
- match do |string|
102
- time_strings = /expected: value != (.+)\n.*got: (.+)$/.match(string).captures
103
- time_strings.uniq.count == 1
104
- end
105
- end
106
-
107
- context 'with Time objects' do
108
- let(:time1) { Time.utc(1969, 12, 31, 19, 01, 40, 101) }
109
- let(:time2) { Time.utc(1969, 12, 31, 19, 01, 40, 102) }
110
-
111
- it 'produces different output for Times differing by milliseconds' do
112
- expect {
113
- expect(time1).to eq(time2)
114
- }.to fail_with(a_string_with_differing_output)
115
- end
116
- end
117
-
118
- context 'with DateTime objects' do
119
- let(:date1) { DateTime.new(2000, 1, 1, 1, 1, Rational(1, 10)) }
120
- let(:date2) { DateTime.new(2000, 1, 1, 1, 1, Rational(2, 10)) }
121
-
122
- it 'produces different output for DateTimes differing by milliseconds' do
123
- expect {
124
- expect(date1).to eq(date2)
125
- }.to fail_with(a_string_with_differing_output)
126
- end
127
-
128
- it 'does not not assume DateTime is defined since you need to require `date` to make it available' do
129
- hide_const('DateTime')
130
- expect {
131
- expect(5).to eq(4)
132
- }.to raise_error(RSpec::Expectations::ExpectationNotMetError)
133
- end
134
-
135
- it 'fails with identical output when the DateTimes are exactly the same' do
136
- expect {
137
- expect(date1).to_not eq(date1)
138
- }.to fail_with(a_string_with_identical_output)
139
- end
140
-
141
- context 'when ActiveSupport is loaded' do
142
- it "uses a custom format to ensure the output is different when DateTimes differ" do
143
- stub_const("ActiveSupport", Module.new)
144
- allow(date1).to receive(:inspect).and_return("Timestamp")
145
- allow(date2).to receive(:inspect).and_return("Timestamp")
146
-
147
- expect {
148
- expect(date1).to eq(date2)
149
- }.to fail_with(a_string_with_differing_output)
150
- end
151
- end
152
- end
153
- end
154
- end
155
- end
156
- end
@@ -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).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_when_negated).to eq "\nexpected: value != 1\n got: 1\n\n(compared using eql?)\n"
38
- end
39
- end
40
- end
41
- end
@@ -1,106 +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
- context "when the expected object is falsey in conditinal semantics" do
28
- it "describes itself with the expected object" do
29
- matcher = equal(nil)
30
- matcher.matches?(nil)
31
- expect(matcher.description).to eq "equal nil"
32
- end
33
- end
34
-
35
- context "when the expected object's #equal? always returns true" do
36
- let(:strange_string) do
37
- string = "foo"
38
-
39
- def string.equal?(other)
40
- true
41
- end
42
-
43
- string
44
- end
45
-
46
- it "describes itself with the expected object" do
47
- matcher = equal(strange_string)
48
- matcher.matches?(strange_string)
49
- expect(matcher.description).to eq 'equal "foo"'
50
- end
51
- end
52
-
53
- it "prints a special message for `false`" do
54
- expected, actual = false, "1"
55
- expect {
56
- expect(actual).to equal(expected)
57
- }.to fail_with "\nexpected false\n got #{inspect_object(actual)}\n"
58
- end
59
-
60
- it "prints a special message for `true`" do
61
- expected, actual = true, "1"
62
- expect {
63
- expect(actual).to equal(expected)
64
- }.to fail_with "\nexpected true\n got #{inspect_object(actual)}\n"
65
- end
66
-
67
- it "prints a special message for `nil`" do
68
- expected, actual = nil, "1"
69
- expect {
70
- expect(actual).to equal(expected)
71
- }.to fail_with "\nexpected nil\n got #{inspect_object(actual)}\n"
72
- end
73
-
74
- it "suggests the `eq` matcher on failure" do
75
- expected, actual = "1", "1"
76
- expect {
77
- expect(actual).to equal(expected)
78
- }.to fail_with <<-MESSAGE
79
-
80
- expected #{inspect_object(expected)}
81
- got #{inspect_object(actual)}
82
-
83
- Compared using equal?, which compares object identity,
84
- but expected and actual are not the same object. Use
85
- `expect(actual).to eq(expected)` if you don't care about
86
- object identity in this example.
87
-
88
- MESSAGE
89
- end
90
-
91
- it "provides message on #negative_failure_message" do
92
- expected = actual = "1"
93
- matcher = equal(expected)
94
- matcher.matches?(actual)
95
- expect(matcher.failure_message_when_negated).to eq <<-MESSAGE
96
-
97
- expected not #{inspect_object(expected)}
98
- got #{inspect_object(actual)}
99
-
100
- Compared using equal?, which compares object identity.
101
-
102
- MESSAGE
103
- end
104
- end
105
- end
106
- 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 { double }
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(double(predicate => true)).to exist
29
- end
30
-
31
- it "fails if not #{predicate}" do
32
- expect {
33
- expect(double(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(double(predicate => false)).not_to exist
55
- end
56
-
57
- it "fails if #{predicate}" do
58
- expect {
59
- expect(double(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 { double(: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 { double(: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 { double(: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 = double
120
- expect(object).to receive(:exist?).with(:foo, :bar) { true }
121
-
122
- expect(object).to exist(:foo, :bar)
123
- end
124
- end