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,67 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Object, "#should" do
4
- before(:each) do
5
- @target = "target"
6
- @matcher = double("matcher")
7
- allow(@matcher).to receive(:matches?).and_return(true)
8
- allow(@matcher).to receive(:failure_message)
9
- end
10
-
11
- it "accepts and interacts with a matcher" do
12
- expect(@matcher).to receive(:matches?).with(@target).and_return(true)
13
- expect(@target).to @matcher
14
- end
15
-
16
- it "asks for a failure_message when matches? returns false" do
17
- expect(@matcher).to receive(:matches?).with(@target).and_return(false)
18
- expect(@matcher).to receive(:failure_message).and_return("the failure message")
19
- expect {
20
- expect(@target).to @matcher
21
- }.to fail_with("the failure message")
22
- end
23
-
24
- context "on interpretters that have BasicObject", :if => defined?(BasicObject) do
25
- let(:proxy_class) do
26
- Class.new(BasicObject) do
27
- def initialize(target)
28
- @target = target
29
- end
30
-
31
- def proxied?
32
- true
33
- end
34
-
35
- def method_missing(name, *args)
36
- @target.send(name, *args)
37
- end
38
- end
39
- end
40
-
41
- it 'works properly on BasicObject-subclassed proxy objects' do
42
- expect(proxy_class.new(Object.new)).to be_proxied
43
- end
44
- end
45
- end
46
-
47
- describe Object, "#should_not" do
48
- before(:each) do
49
- @target = "target"
50
- @matcher = double("matcher")
51
- end
52
-
53
- it "accepts and interacts with a matcher" do
54
- expect(@matcher).to receive(:matches?).with(@target).and_return(false)
55
- allow(@matcher).to receive(:failure_message_when_negated)
56
-
57
- expect(@target).not_to @matcher
58
- end
59
-
60
- it "asks for a failure_message_when_negated when matches? returns true" do
61
- expect(@matcher).to receive(:matches?).with(@target).and_return(true)
62
- expect(@matcher).to receive(:failure_message_when_negated).and_return("the failure message for should not")
63
- expect {
64
- expect(@target).not_to @matcher
65
- }.to fail_with("the failure message for should not")
66
- end
67
- end
@@ -1,114 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
-
5
- describe RSpec::Expectations, "#fail_with with diff of arrays" do
6
- before { allow(RSpec::Matchers.configuration).to receive_messages(:color? => false) }
7
-
8
- it "splits items with newlines" do
9
- expected_diff = "\nDiff:\n@@ -1 +1,3 @@\n+a\\nb\n+c\\nd\n"
10
- expect {
11
- RSpec::Expectations.fail_with("", [], ["a\nb", "c\nd"])
12
- }.to fail_with(expected_diff)
13
- end
14
-
15
- it "shows inner arrays on a single line" do
16
- expected_diff = "\nDiff:\n@@ -1 +1,3 @@\n+a\\nb\n+[\"c\\nd\"]\n"
17
- expect {
18
- RSpec::Expectations.fail_with("", [], ["a\nb", ["c\nd"]])
19
- }.to fail_with(expected_diff)
20
- end
21
- end
22
-
23
- describe RSpec::Expectations, "#fail_with with diff" do
24
- let(:differ) { double("differ") }
25
-
26
- before(:each) do
27
- allow(RSpec::Expectations).to receive(:differ) { differ }
28
- end
29
-
30
- it "calls differ if expected/actual are not strings (or numbers or procs)" do
31
- expect(differ).to receive(:diff_as_object).and_return("diff")
32
- expect {
33
- RSpec::Expectations.fail_with "the message", Object.new, Object.new
34
- }.to fail_with("the message\nDiff:diff")
35
- end
36
-
37
- context "with two strings" do
38
- context "and actual is multiline" do
39
- it "calls differ" do
40
- expect(differ).to receive(:diff_as_string).and_return("diff")
41
- expect {
42
- RSpec::Expectations.fail_with "the message", "expected\nthis", "actual"
43
- }.to fail_with("the message\nDiff:diff")
44
- end
45
- end
46
-
47
- context "and expected is multiline" do
48
- it "calls differ" do
49
- expect(differ).to receive(:diff_as_string).and_return("diff")
50
- expect {
51
- RSpec::Expectations.fail_with "the message", "expected", "actual\nthat"
52
- }.to fail_with("the message\nDiff:diff")
53
- end
54
- end
55
-
56
- context "and both are single line strings" do
57
- it "does not call differ" do
58
- expect(differ).not_to receive(:diff_as_string)
59
- expect {
60
- RSpec::Expectations.fail_with("the message", "expected", "actual")
61
- }.to fail_with("the message")
62
- end
63
- end
64
-
65
- context "and they are UTF-16LE encoded", :if => String.method_defined?(:encode) do
66
- it 'does not diff when they are not multiline' do
67
- expect(differ).not_to receive(:diff_as_string)
68
-
69
- str_1 = "This is a pile of poo: 💩".encode("UTF-16LE")
70
- str_2 = "This is a pile of poo: 💩".encode("UTF-16LE")
71
-
72
- expect {
73
- RSpec::Expectations.fail_with("the message", str_1, str_2)
74
- }.to fail_with("the message")
75
- end
76
-
77
- it 'diffs when they are multiline' do
78
- expect(differ).to receive(:diff_as_string).and_return("diff")
79
-
80
- str_1 = "This is a pile of poo:\n💩".encode("UTF-16LE")
81
- str_2 = "This is a pile of poo:\n💩".encode("UTF-16LE")
82
-
83
- expect {
84
- RSpec::Expectations.fail_with("the message", str_1, str_2)
85
- }.to fail_with("the message\nDiff:diff")
86
- end
87
- end
88
- end
89
-
90
- it "does not call differ if no expected/actual" do
91
- expect {
92
- RSpec::Expectations.fail_with "the message"
93
- }.to fail_with("the message")
94
- end
95
-
96
- it "does not call differ expected is Numeric" do
97
- expect {
98
- RSpec::Expectations.fail_with "the message", 1, "1"
99
- }.to fail_with("the message")
100
- end
101
-
102
- it "does not call differ when actual is Numeric" do
103
- expect {
104
- RSpec::Expectations.fail_with "the message", "1", 1
105
- }.to fail_with("the message")
106
- end
107
-
108
- it "does not call differ if expected or actual are procs" do
109
- expect {
110
- RSpec::Expectations.fail_with "the message", lambda {}, lambda {}
111
- }.to fail_with("the message")
112
- end
113
- end
114
-
@@ -1,205 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module ExampleExpectations
4
-
5
- class ArbitraryMatcher
6
- def initialize(*args, &block)
7
- if args.last.is_a? Hash
8
- @expected = args.last[:expected]
9
- end
10
- @expected = block.call if block
11
- @block = block
12
- end
13
-
14
- def matches?(target)
15
- @target = target
16
- return @expected == target
17
- end
18
-
19
- def with(new_value)
20
- @expected = new_value
21
- self
22
- end
23
-
24
- def failure_message
25
- "expected #{@expected}, got #{@target}"
26
- end
27
-
28
- def failure_message_when_negated
29
- "expected not #{@expected}, got #{@target}"
30
- end
31
- end
32
-
33
- class PositiveOnlyMatcher < ArbitraryMatcher
34
- undef failure_message_when_negated rescue nil
35
- end
36
-
37
- def arbitrary_matcher(*args, &block)
38
- ArbitraryMatcher.new(*args, &block)
39
- end
40
-
41
- def positive_only_matcher(*args, &block)
42
- PositiveOnlyMatcher.new(*args, &block)
43
- end
44
-
45
- end
46
-
47
- module RSpec
48
- module Expectations
49
- describe PositiveExpectationHandler do
50
- describe "#handle_matcher" do
51
- it "asks the matcher if it matches" do
52
- matcher = double("matcher")
53
- actual = Object.new
54
- expect(matcher).to receive(:matches?).with(actual).and_return(true)
55
- RSpec::Expectations::PositiveExpectationHandler.handle_matcher(actual, matcher)
56
- end
57
-
58
- it "returns the match value" do
59
- matcher = double("matcher")
60
- actual = Object.new
61
- expect(matcher).to receive(:matches?).with(actual).and_return(:this_value)
62
- expect(RSpec::Expectations::PositiveExpectationHandler.handle_matcher(actual, matcher)).to eq :this_value
63
- end
64
-
65
- it "calls failure_message if the matcher implements it" do
66
- matcher = double("matcher", :failure_message => "message", :matches? => false)
67
- actual = Object.new
68
-
69
- expect(::RSpec::Expectations).to receive(:fail_with).with("message")
70
-
71
- RSpec::Expectations::PositiveExpectationHandler.handle_matcher(actual, matcher)
72
- end
73
-
74
- it "calls fail if matcher.diffable?" do
75
- matcher = double("matcher",
76
- :diffable? => true,
77
- :failure_message => "message",
78
- :matches? => false,
79
- :expected => 1,
80
- :actual => 2
81
- )
82
- actual = Object.new
83
-
84
- expect(::RSpec::Expectations).to receive(:fail_with).with("message", 1, 2)
85
-
86
- RSpec::Expectations::PositiveExpectationHandler.handle_matcher(actual, matcher)
87
- end
88
-
89
- it "calls failure_message if the matcher does not implement failure_message" do
90
- matcher = double("matcher", :failure_message => "message", :matches? => false)
91
- actual = Object.new
92
-
93
- expect(::RSpec::Expectations).to receive(:fail_with).with("message")
94
-
95
- RSpec::Expectations::PositiveExpectationHandler.handle_matcher(actual, matcher)
96
-
97
- end
98
-
99
- it "uses the custom failure message when one is provided" do
100
- matcher = double("matcher", :failure_message => "message", :matches? => false)
101
- actual = Object.new
102
-
103
- expect(::RSpec::Expectations).to receive(:fail_with).with("custom")
104
-
105
- RSpec::Expectations::PositiveExpectationHandler.handle_matcher(actual, matcher, "custom")
106
- end
107
-
108
- it "uses the custom failure message when one is provided as a callable object" do
109
- matcher = double("matcher", :failure_message => "message", :matches? => false)
110
- actual = Object.new
111
-
112
- failure_message = double("failure message", :call => "custom")
113
-
114
- expect(::RSpec::Expectations).to receive(:fail_with).with("custom")
115
-
116
- RSpec::Expectations::PositiveExpectationHandler.handle_matcher(actual, matcher, failure_message)
117
- end
118
- end
119
- end
120
-
121
- describe NegativeExpectationHandler do
122
- describe "#handle_matcher" do
123
- it "asks the matcher if it doesn't match when the matcher responds to #does_not_match?" do
124
- matcher = double("matcher", :does_not_match? => true, :failure_message_when_negated => nil)
125
- actual = Object.new
126
- expect(matcher).to receive(:does_not_match?).with(actual).and_return(true)
127
- RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher)
128
- end
129
-
130
- it "asks the matcher if it matches when the matcher doesn't respond to #does_not_match?" do
131
- matcher = double("matcher")
132
- actual = Object.new
133
- allow(matcher).to receive(:failure_message_when_negated)
134
- expect(matcher).to receive(:matches?).with(actual).and_return(false)
135
- RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher)
136
- end
137
-
138
- it "returns the match value" do
139
- matcher = double("matcher")
140
- actual = Object.new
141
- expect(matcher).to receive(:matches?).with(actual).and_return(false)
142
- allow(matcher).to receive(:failure_message_when_negated).and_return("ignore")
143
- expect(RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher)).to be_falsey
144
- end
145
-
146
- it "calls fail if matcher.diffable?" do
147
- matcher = double("matcher",
148
- :diffable? => true,
149
- :failure_message_when_negated => "message",
150
- :matches? => true,
151
- :expected => 1,
152
- :actual => 2
153
- )
154
- actual = Object.new
155
-
156
- expect(::RSpec::Expectations).to receive(:fail_with).with("message", 1, 2)
157
-
158
- RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher)
159
- end
160
-
161
- it "uses the custom failure message when one is provided" do
162
- matcher = double("matcher", :failure_message_when_negated => "message", :matches? => true)
163
- actual = Object.new
164
-
165
- expect(::RSpec::Expectations).to receive(:fail_with).with("custom")
166
-
167
- RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher, "custom")
168
- end
169
-
170
- it "uses the custom failure message when one is provided as a callable object" do
171
- matcher = double("matcher", :failure_message_when_negated => "message", :matches? => true)
172
- actual = Object.new
173
-
174
- failure_message = double("failure message", :call => "custom")
175
-
176
- expect(::RSpec::Expectations).to receive(:fail_with).with("custom")
177
-
178
- RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher, failure_message)
179
- end
180
- end
181
- end
182
-
183
- describe PositiveExpectationHandler do
184
- include ExampleExpectations
185
-
186
- it "handles submitted args" do
187
- expect(5).to arbitrary_matcher(:expected => 5)
188
- expect(5).to arbitrary_matcher(:expected => "wrong").with(5)
189
- expect { expect(5).to arbitrary_matcher(:expected => 4) }.to fail_with("expected 4, got 5")
190
- expect { expect(5).to arbitrary_matcher(:expected => 5).with(4) }.to fail_with("expected 4, got 5")
191
- expect(5).not_to arbitrary_matcher(:expected => 4)
192
- expect(5).not_to arbitrary_matcher(:expected => 5).with(4)
193
- expect { expect(5).not_to arbitrary_matcher(:expected => 5) }.to fail_with("expected not 5, got 5")
194
- expect { expect(5).not_to arbitrary_matcher(:expected => 4).with(5) }.to fail_with("expected not 5, got 5")
195
- end
196
-
197
- it "handles the submitted block" do
198
- expect(5).to arbitrary_matcher { 5 }
199
- expect(5).to arbitrary_matcher(:expected => 4) { 5 }
200
- expect(5).to arbitrary_matcher(:expected => 4).with(5) { 3 }
201
- end
202
-
203
- end
204
- end
205
- end
@@ -1,27 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module RSpec
4
- describe Matchers do
5
-
6
- let(:sample_matchers) do
7
- [:be,
8
- :be_instance_of,
9
- :be_kind_of]
10
- end
11
-
12
- context "once required" do
13
- include MinitestIntegration
14
-
15
- it "includes itself in Minitest::Test" do
16
- with_minitest_loaded do
17
- minitest_case = MiniTest::Test.allocate
18
- sample_matchers.each do |sample_matcher|
19
- expect(minitest_case).to respond_to(sample_matcher)
20
- end
21
- end
22
- end
23
-
24
- end
25
-
26
- end
27
- end
@@ -1,89 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module RSpec
4
- module Expectations
5
- describe Syntax do
6
- context "when passing a message to an expectation" do
7
- let(:warner) { ::Kernel }
8
-
9
- let(:string_like_object) do
10
- Struct.new(:to_str, :to_s).new(*(["Ceci n'est pas une Chaine."]*2))
11
- end
12
-
13
- let(:insufficiently_string_like_object) do
14
- Struct.new(:to_s).new("Ceci n'est pas une Chaine.")
15
- end
16
-
17
- let(:callable_object) do
18
- Struct.new(:call).new("Ceci n'est pas une Chaine.")
19
- end
20
-
21
- describe "expect(...).to" do
22
- it "prints a warning when the message object isn't a String" do
23
- expect(warner).to receive(:warn).with(/ignoring.*message/)
24
- expect(3).to eq(3), :not_a_string
25
- end
26
-
27
- it "doesn't print a warning when message is a String" do
28
- expect(warner).not_to receive(:warn)
29
- expect(3).to eq(3), "a string"
30
- end
31
-
32
- it "doesn't print a warning when message responds to to_str" do
33
- expect(warner).not_to receive(:warn)
34
- expect(3).to eq(3), string_like_object
35
- end
36
-
37
- it "prints a warning when the message object handles to_s but not to_str" do
38
- expect(warner).to receive(:warn).with(/ignoring.*message/)
39
- expect(3).to eq(3), insufficiently_string_like_object
40
- end
41
-
42
- it "doesn't print a warning when message responds to call" do
43
- expect(warner).not_to receive(:warn)
44
- expect(3).to eq(3), callable_object
45
- end
46
- end
47
-
48
- describe "expect(...).not_to" do
49
- it "prints a warning when the message object isn't a String" do
50
- expect(warner).to receive(:warn).with(/ignoring.*message/)
51
- expect(3).not_to eq(4), :not_a_string
52
- end
53
-
54
- it "doesn't print a warning when message is a String" do
55
- expect(warner).not_to receive(:warn)
56
- expect(3).not_to eq(4), "a string"
57
- end
58
-
59
- it "doesn't print a warning when message responds to to_str" do
60
- expect(warner).not_to receive(:warn)
61
- expect(3).not_to eq(4), string_like_object
62
- end
63
-
64
- it "prints a warning when the message object handles to_s but not to_str" do
65
- expect(warner).to receive(:warn).with(/ignoring.*message/)
66
- expect(3).not_to eq(4), insufficiently_string_like_object
67
- end
68
-
69
- it "doesn't print a warning when message responds to call" do
70
- expect(warner).not_to receive(:warn)
71
- expect(3).not_to eq(4), callable_object
72
- end
73
- end
74
- end
75
-
76
- describe "enabling the should syntax on something other than the default syntax host" do
77
- include_context "with the default expectation syntax"
78
-
79
- it "continues to warn about the should syntax" do
80
- my_host = Class.new
81
- expect(RSpec).to receive(:deprecate)
82
- Syntax.enable_should(my_host)
83
-
84
- 3.should eq 3
85
- end
86
- end
87
- end
88
- end
89
- end