rspec-expectations 2.13.0 → 2.14.0.rc1

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 (60) hide show
  1. data/Changelog.md +34 -0
  2. data/README.md +43 -87
  3. data/features/README.md +8 -9
  4. data/features/built_in_matchers/README.md +41 -41
  5. data/features/built_in_matchers/be_within.feature +3 -3
  6. data/features/built_in_matchers/expect_change.feature +6 -6
  7. data/features/built_in_matchers/expect_error.feature +2 -2
  8. data/features/built_in_matchers/start_with.feature +1 -1
  9. data/features/built_in_matchers/throw_symbol.feature +11 -11
  10. data/features/built_in_matchers/yield.feature +18 -3
  11. data/features/custom_matchers/define_diffable_matcher.feature +1 -1
  12. data/features/custom_matchers/define_matcher_outside_rspec.feature +6 -6
  13. data/features/custom_matchers/define_matcher_with_fluent_interface.feature +1 -1
  14. data/features/customized_message.feature +1 -1
  15. data/features/support/env.rb +10 -1
  16. data/features/syntax_configuration.feature +3 -0
  17. data/features/test_frameworks/test_unit.feature +15 -17
  18. data/lib/rspec/expectations.rb +1 -1
  19. data/lib/rspec/expectations/deprecation.rb +12 -33
  20. data/lib/rspec/expectations/differ.rb +25 -7
  21. data/lib/rspec/expectations/expectation_target.rb +7 -8
  22. data/lib/rspec/expectations/extensions/object.rb +2 -12
  23. data/lib/rspec/expectations/fail_with.rb +11 -1
  24. data/lib/rspec/expectations/handler.rb +11 -6
  25. data/lib/rspec/expectations/syntax.rb +2 -2
  26. data/lib/rspec/expectations/version.rb +1 -1
  27. data/lib/rspec/matchers.rb +134 -144
  28. data/lib/rspec/matchers/be_close.rb +1 -1
  29. data/lib/rspec/matchers/built_in/be_within.rb +1 -1
  30. data/lib/rspec/matchers/built_in/have.rb +20 -4
  31. data/lib/rspec/matchers/built_in/raise_error.rb +23 -7
  32. data/lib/rspec/matchers/built_in/yield.rb +78 -3
  33. data/lib/rspec/matchers/operator_matcher.rb +1 -1
  34. data/lib/rspec/matchers/test_unit_integration.rb +11 -0
  35. data/spec/rspec/expectations/differ_spec.rb +27 -5
  36. data/spec/rspec/expectations/expectation_target_spec.rb +10 -3
  37. data/spec/rspec/expectations/extensions/kernel_spec.rb +5 -5
  38. data/spec/rspec/expectations/fail_with_spec.rb +19 -0
  39. data/spec/rspec/expectations/handler_spec.rb +42 -21
  40. data/spec/rspec/expectations/syntax_spec.rb +45 -3
  41. data/spec/rspec/matchers/be_close_spec.rb +6 -6
  42. data/spec/rspec/matchers/be_spec.rb +36 -36
  43. data/spec/rspec/matchers/be_within_spec.rb +4 -0
  44. data/spec/rspec/matchers/change_spec.rb +6 -6
  45. data/spec/rspec/matchers/configuration_spec.rb +57 -89
  46. data/spec/rspec/matchers/description_generation_spec.rb +1 -1
  47. data/spec/rspec/matchers/exist_spec.rb +9 -9
  48. data/spec/rspec/matchers/has_spec.rb +1 -1
  49. data/spec/rspec/matchers/have_spec.rb +12 -2
  50. data/spec/rspec/matchers/include_matcher_integration_spec.rb +2 -2
  51. data/spec/rspec/matchers/include_spec.rb +4 -4
  52. data/spec/rspec/matchers/match_array_spec.rb +1 -1
  53. data/spec/rspec/matchers/match_spec.rb +1 -1
  54. data/spec/rspec/matchers/raise_error_spec.rb +189 -99
  55. data/spec/rspec/matchers/respond_to_spec.rb +4 -4
  56. data/spec/rspec/matchers/satisfy_spec.rb +1 -1
  57. data/spec/rspec/matchers/start_with_end_with_spec.rb +2 -2
  58. data/spec/rspec/matchers/yield_spec.rb +81 -4
  59. data/spec/spec_helper.rb +1 -1
  60. metadata +10 -12
@@ -6,9 +6,21 @@ module RSpec
6
6
  context "when passing a message to an expectation" do
7
7
  let(:warner) { ::Kernel }
8
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
+
9
21
  describe "expect(...).to" do
10
22
  it "prints a warning when the message object isn't a String" do
11
- warner.should_receive(:warn).with /ignoring.*message/
23
+ warner.should_receive(:warn).with(/ignoring.*message/)
12
24
  expect(3).to eq(3), :not_a_string
13
25
  end
14
26
 
@@ -16,11 +28,26 @@ module RSpec
16
28
  warner.should_not_receive(:warn)
17
29
  expect(3).to eq(3), "a string"
18
30
  end
31
+
32
+ it "doesn't print a warning when message responds to to_str" do
33
+ warner.should_not_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
+ warner.should_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
+ warner.should_not_receive(:warn)
44
+ expect(3).to eq(3), callable_object
45
+ end
19
46
  end
20
47
 
21
- describe "expect(...).to_not" do
48
+ describe "expect(...).not_to" do
22
49
  it "prints a warning when the message object isn't a String" do
23
- warner.should_receive(:warn).with /ignoring.*message/
50
+ warner.should_receive(:warn).with(/ignoring.*message/)
24
51
  expect(3).not_to eq(4), :not_a_string
25
52
  end
26
53
 
@@ -28,6 +55,21 @@ module RSpec
28
55
  warner.should_not_receive(:warn)
29
56
  expect(3).not_to eq(4), "a string"
30
57
  end
58
+
59
+ it "doesn't print a warning when message responds to to_str" do
60
+ warner.should_not_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
+ warner.should_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
+ warner.should_not_receive(:warn)
71
+ expect(3).not_to eq(4), callable_object
72
+ end
31
73
  end
32
74
  end
33
75
 
@@ -4,17 +4,17 @@ module RSpec
4
4
  module Matchers
5
5
  describe "expect(actual).to be_close(expected, delta)" do
6
6
  before(:each) do
7
- RSpec.stub(:warn)
7
+ allow(RSpec).to receive(:deprecate)
8
8
  end
9
9
 
10
- it "delegates to be_within(delta).of(expected)" do
11
- should_receive(:be_within).with(0.5).and_return( be_within_matcher = stub )
12
- be_within_matcher.should_receive(:of).with(3.0)
10
+ it "is deprecated" do
11
+ expect(RSpec).to receive(:deprecate).with(/be_close.*/, :replacement => "be_within(0.5).of(3.0)")
13
12
  be_close(3.0, 0.5)
14
13
  end
15
14
 
16
- it "prints a deprecation warning" do
17
- RSpec.should_receive(:warn).with(/please use be_within.*instead/)
15
+ it "delegates to be_within(delta).of(expected)" do
16
+ should_receive(:be_within).with(0.5).and_return( be_within_matcher = double )
17
+ be_within_matcher.should_receive(:of).with(3.0)
18
18
  be_close(3.0, 0.5)
19
19
  end
20
20
  end
@@ -2,24 +2,24 @@ require 'spec_helper'
2
2
 
3
3
  describe "expect(...).to be_predicate" do
4
4
  it "passes when actual returns true for :predicate?" do
5
- actual = stub("actual", :happy? => true)
5
+ actual = double("actual", :happy? => true)
6
6
  expect(actual).to be_happy
7
7
  end
8
8
 
9
9
  it "passes when actual returns true for :predicates? (present tense)" do
10
- actual = stub("actual", :exists? => true, :exist? => true)
10
+ actual = double("actual", :exists? => true, :exist? => true)
11
11
  expect(actual).to be_exist
12
12
  end
13
13
 
14
14
  it "fails when actual returns false for :predicate?" do
15
- actual = stub("actual", :happy? => false)
15
+ actual = double("actual", :happy? => false)
16
16
  expect {
17
17
  expect(actual).to be_happy
18
18
  }.to fail_with("expected happy? to return true, got false")
19
19
  end
20
20
 
21
21
  it "fails when actual returns false for :predicate?" do
22
- actual = stub("actual", :happy? => nil)
22
+ actual = double("actual", :happy? => nil)
23
23
  expect {
24
24
  expect(actual).to be_happy
25
25
  }.to fail_with("expected happy? to return true, got nil")
@@ -32,7 +32,7 @@ describe "expect(...).to be_predicate" do
32
32
  end
33
33
 
34
34
  it "fails on error other than NameError" do
35
- actual = stub("actual")
35
+ actual = double("actual")
36
36
  actual.should_receive(:foo?).and_raise("aaaah")
37
37
  expect {
38
38
  expect(actual).to be_foo
@@ -50,17 +50,17 @@ end
50
50
 
51
51
  describe "expect(...).not_to be_predicate" do
52
52
  it "passes when actual returns false for :sym?" do
53
- actual = stub("actual", :happy? => false)
53
+ actual = double("actual", :happy? => false)
54
54
  expect(actual).not_to be_happy
55
55
  end
56
56
 
57
57
  it "passes when actual returns nil for :sym?" do
58
- actual = stub("actual", :happy? => nil)
58
+ actual = double("actual", :happy? => nil)
59
59
  expect(actual).not_to be_happy
60
60
  end
61
61
 
62
62
  it "fails when actual returns true for :sym?" do
63
- actual = stub("actual", :happy? => true)
63
+ actual = double("actual", :happy? => true)
64
64
  expect {
65
65
  expect(actual).not_to be_happy
66
66
  }.to fail_with("expected happy? to return false, got true")
@@ -75,13 +75,13 @@ end
75
75
 
76
76
  describe "expect(...).to be_predicate(*args)" do
77
77
  it "passes when actual returns true for :predicate?(*args)" do
78
- actual = mock("actual")
78
+ actual = double("actual")
79
79
  actual.should_receive(:older_than?).with(3).and_return(true)
80
80
  expect(actual).to be_older_than(3)
81
81
  end
82
82
 
83
83
  it "fails when actual returns false for :predicate?(*args)" do
84
- actual = mock("actual")
84
+ actual = double("actual")
85
85
  actual.should_receive(:older_than?).with(3).and_return(false)
86
86
  expect {
87
87
  expect(actual).to be_older_than(3)
@@ -97,13 +97,13 @@ end
97
97
 
98
98
  describe "expect(...).not_to be_predicate(*args)" do
99
99
  it "passes when actual returns false for :predicate?(*args)" do
100
- actual = mock("actual")
100
+ actual = double("actual")
101
101
  actual.should_receive(:older_than?).with(3).and_return(false)
102
102
  expect(actual).not_to be_older_than(3)
103
103
  end
104
104
 
105
105
  it "fails when actual returns true for :predicate?(*args)" do
106
- actual = mock("actual")
106
+ actual = double("actual")
107
107
  actual.should_receive(:older_than?).with(3).and_return(true)
108
108
  expect {
109
109
  expect(actual).not_to be_older_than(3)
@@ -119,16 +119,16 @@ end
119
119
 
120
120
  describe "expect(...).to be_predicate(&block)" do
121
121
  it "passes when actual returns true for :predicate?(&block)" do
122
- actual = mock("actual")
123
- delegate = mock("delegate")
122
+ actual = double("actual")
123
+ delegate = double("delegate")
124
124
  actual.should_receive(:happy?).and_yield
125
125
  delegate.should_receive(:check_happy).and_return(true)
126
126
  expect(actual).to be_happy { delegate.check_happy }
127
127
  end
128
128
 
129
129
  it "fails when actual returns false for :predicate?(&block)" do
130
- actual = mock("actual")
131
- delegate = mock("delegate")
130
+ actual = double("actual")
131
+ delegate = double("delegate")
132
132
  actual.should_receive(:happy?).and_yield
133
133
  delegate.should_receive(:check_happy).and_return(false)
134
134
  expect {
@@ -137,7 +137,7 @@ describe "expect(...).to be_predicate(&block)" do
137
137
  end
138
138
 
139
139
  it "fails when actual does not respond to :predicate?" do
140
- delegate = mock("delegate", :check_happy => true)
140
+ delegate = double("delegate", :check_happy => true)
141
141
  expect {
142
142
  expect(Object.new).to be_happy { delegate.check_happy }
143
143
  }.to raise_error(NameError)
@@ -146,16 +146,16 @@ end
146
146
 
147
147
  describe "expect(...).not_to be_predicate(&block)" do
148
148
  it "passes when actual returns false for :predicate?(&block)" do
149
- actual = mock("actual")
150
- delegate = mock("delegate")
149
+ actual = double("actual")
150
+ delegate = double("delegate")
151
151
  actual.should_receive(:happy?).and_yield
152
152
  delegate.should_receive(:check_happy).and_return(false)
153
153
  expect(actual).not_to be_happy { delegate.check_happy }
154
154
  end
155
155
 
156
156
  it "fails when actual returns true for :predicate?(&block)" do
157
- actual = mock("actual")
158
- delegate = mock("delegate")
157
+ actual = double("actual")
158
+ delegate = double("delegate")
159
159
  actual.should_receive(:happy?).and_yield
160
160
  delegate.should_receive(:check_happy).and_return(true)
161
161
  expect {
@@ -164,7 +164,7 @@ describe "expect(...).not_to be_predicate(&block)" do
164
164
  end
165
165
 
166
166
  it "fails when actual does not respond to :predicate?" do
167
- delegate = mock("delegate", :check_happy => true)
167
+ delegate = double("delegate", :check_happy => true)
168
168
  expect {
169
169
  expect(Object.new).not_to be_happy { delegate.check_happy }
170
170
  }.to raise_error(NameError)
@@ -173,16 +173,16 @@ end
173
173
 
174
174
  describe "expect(...).to be_predicate(*args, &block)" do
175
175
  it "passes when actual returns true for :predicate?(*args, &block)" do
176
- actual = mock("actual")
177
- delegate = mock("delegate")
176
+ actual = double("actual")
177
+ delegate = double("delegate")
178
178
  actual.should_receive(:older_than?).with(3).and_yield(3)
179
179
  delegate.should_receive(:check_older_than).with(3).and_return(true)
180
180
  expect(actual).to be_older_than(3) { |age| delegate.check_older_than(age) }
181
181
  end
182
182
 
183
183
  it "fails when actual returns false for :predicate?(*args, &block)" do
184
- actual = mock("actual")
185
- delegate = mock("delegate")
184
+ actual = double("actual")
185
+ delegate = double("delegate")
186
186
  actual.should_receive(:older_than?).with(3).and_yield(3)
187
187
  delegate.should_receive(:check_older_than).with(3).and_return(false)
188
188
  expect {
@@ -191,7 +191,7 @@ describe "expect(...).to be_predicate(*args, &block)" do
191
191
  end
192
192
 
193
193
  it "fails when actual does not respond to :predicate?" do
194
- delegate = mock("delegate", :check_older_than => true)
194
+ delegate = double("delegate", :check_older_than => true)
195
195
  expect {
196
196
  expect(Object.new).to be_older_than(3) { |age| delegate.check_older_than(age) }
197
197
  }.to raise_error(NameError)
@@ -200,16 +200,16 @@ end
200
200
 
201
201
  describe "expect(...).not_to be_predicate(*args, &block)" do
202
202
  it "passes when actual returns false for :predicate?(*args, &block)" do
203
- actual = mock("actual")
204
- delegate = mock("delegate")
203
+ actual = double("actual")
204
+ delegate = double("delegate")
205
205
  actual.should_receive(:older_than?).with(3).and_yield(3)
206
206
  delegate.should_receive(:check_older_than).with(3).and_return(false)
207
207
  expect(actual).not_to be_older_than(3) { |age| delegate.check_older_than(age) }
208
208
  end
209
209
 
210
210
  it "fails when actual returns true for :predicate?(*args, &block)" do
211
- actual = mock("actual")
212
- delegate = mock("delegate")
211
+ actual = double("actual")
212
+ delegate = double("delegate")
213
213
  actual.should_receive(:older_than?).with(3).and_yield(3)
214
214
  delegate.should_receive(:check_older_than).with(3).and_return(true)
215
215
  expect {
@@ -218,7 +218,7 @@ describe "expect(...).not_to be_predicate(*args, &block)" do
218
218
  end
219
219
 
220
220
  it "fails when actual does not respond to :predicate?" do
221
- delegate = mock("delegate", :check_older_than => true)
221
+ delegate = double("delegate", :check_older_than => true)
222
222
  expect {
223
223
  expect(Object.new).not_to be_older_than(3) { |age| delegate.check_older_than(age) }
224
224
  }.to raise_error(NameError)
@@ -465,10 +465,10 @@ end
465
465
 
466
466
  describe "'expect(...).to be' with operator" do
467
467
  it "includes 'be' in the description" do
468
- expect((be > 6).description).to match /be > 6/
469
- expect((be >= 6).description).to match /be >= 6/
470
- expect((be <= 6).description).to match /be <= 6/
471
- expect((be < 6).description).to match /be < 6/
468
+ expect((be > 6).description).to match(/be > 6/)
469
+ expect((be >= 6).description).to match(/be >= 6/)
470
+ expect((be <= 6).description).to match(/be <= 6/)
471
+ expect((be < 6).description).to match(/be < 6/)
472
472
  end
473
473
  end
474
474
 
@@ -27,6 +27,10 @@ module RSpec
27
27
  expect(5.5).to be_within(0.5).of(5.0)
28
28
  end
29
29
 
30
+ it "passes with integer arguments that are near each other" do
31
+ expect(1.0001).to be_within(5).percent_of(1)
32
+ end
33
+
30
34
  it "fails when actual < (expected - delta)" do
31
35
  expect {
32
36
  expect(4.49).to be_within(0.5).of(5.0)
@@ -156,12 +156,12 @@ describe "expect { ... }.not_to change(actual, message)" do
156
156
  end
157
157
 
158
158
  it "passes when actual is not modified by the block" do
159
- expect { }.to_not change(@instance, :some_value)
159
+ expect { }.not_to change(@instance, :some_value)
160
160
  end
161
161
 
162
162
  it "fails when actual is not modified by the block" do
163
163
  expect do
164
- expect {@instance.some_value = 6}.to_not change(@instance, :some_value)
164
+ expect {@instance.some_value = 6}.not_to change(@instance, :some_value)
165
165
  end.to fail_with("some_value should not have changed, but did change from 5 to 6")
166
166
  end
167
167
  end
@@ -206,18 +206,18 @@ describe "expect { ... }.not_to change { block }" do
206
206
  end
207
207
 
208
208
  it "passes when actual is modified by the block" do
209
- expect {}.to_not change{ @instance.some_value }
209
+ expect {}.not_to change{ @instance.some_value }
210
210
  end
211
211
 
212
212
  it "fails when actual is not modified by the block" do
213
213
  expect do
214
- expect {@instance.some_value = 6}.to_not change { @instance.some_value }
214
+ expect {@instance.some_value = 6}.not_to change { @instance.some_value }
215
215
  end.to fail_with("result should not have changed, but did change from 5 to 6")
216
216
  end
217
217
 
218
218
  it "warns if passed a block using do/end instead of {}" do
219
219
  expect do
220
- expect {}.to_not change do; end
220
+ expect {}.not_to change do; end
221
221
  end.to raise_error(SyntaxError, /block passed to should or should_not/)
222
222
  end
223
223
  end
@@ -537,6 +537,6 @@ describe RSpec::Matchers::BuiltIn::Change do
537
537
 
538
538
  expect {
539
539
  expect { @instance.some_value = "cat" }.to change(@instance, :some_value)
540
- }.to_not raise_error
540
+ }.not_to raise_error
541
541
  end
542
542
  end
@@ -22,7 +22,12 @@ module RSpec
22
22
  end
23
23
 
24
24
  before do
25
- RSpec.configuration.stub(:backtrace_clean_patterns) { [/clean-me/] }
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
26
31
  end
27
32
 
28
33
  it "defaults to rspec-core's backtrace formatter when rspec-core is loaded" do
@@ -36,7 +41,7 @@ module RSpec
36
41
  end
37
42
 
38
43
  it "can be set to another backtrace formatter" do
39
- config.backtrace_formatter = stub(:format_backtrace => ['a'])
44
+ config.backtrace_formatter = double(:format_backtrace => ['a'])
40
45
  expect(formatted_backtrace).to eq(['a'])
41
46
  end
42
47
  end
@@ -60,134 +65,97 @@ module RSpec
60
65
  end
61
66
 
62
67
  shared_examples_for "configuring the expectation syntax" do
63
- # We want a sandboxed method that ensures that we wind up with
64
- # both syntaxes properly enabled when the example ends.
65
- #
66
- # On platforms that fork, using a sub process is the easiest,
67
- # most robust way to achieve that.
68
- #
69
- # On jRuby we just re-enable both syntaxes at the end of the example;
70
- # however, this is a generally inferior approach because it depends on
71
- # the code-under-test working properly; if it doesn't work properly,
72
- # it could leave things in a "broken" state where tons of other examples fail.
73
- if RUBY_PLATFORM == "java"
74
- def sandboxed
75
- orig_syntax = RSpec::Matchers.configuration.syntax
76
- yield
77
- ensure
78
- configure_syntax(orig_syntax)
79
- end
80
- else
81
- include InSubProcess
82
- alias sandboxed in_sub_process
68
+ before do
69
+ @orig_syntax = RSpec::Matchers.configuration.syntax
70
+ end
71
+
72
+ after do
73
+ configure_syntax(@orig_syntax)
83
74
  end
84
75
 
85
76
  it 'can limit the syntax to :should' do
86
- sandboxed do
87
- configure_syntax :should
88
- configured_syntax.should eq([:should])
77
+ configure_syntax :should
78
+ configured_syntax.should eq([:should])
89
79
 
90
- 3.should eq(3)
91
- 3.should_not eq(4)
92
- lambda { expect(6).to eq(6) }.should raise_error(NameError)
93
- end
80
+ 3.should eq(3)
81
+ 3.should_not eq(4)
82
+ lambda { expect(6).to eq(6) }.should raise_error(NameError)
94
83
  end
95
84
 
96
85
  it 'is a no-op when configured to :should twice' do
97
- sandboxed do
98
- configure_syntax :should
99
-
100
- Expectations::Syntax.default_should_host.
101
- stub(:method_added).
102
- and_raise("no methods should be added here")
103
-
104
- configure_syntax :should
105
- end
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
106
90
  end
107
91
 
108
92
  it 'can limit the syntax to :expect' do
109
- sandboxed do
110
- configure_syntax :expect
111
- expect(configured_syntax).to eq([:expect])
93
+ configure_syntax :expect
94
+ expect(configured_syntax).to eq([:expect])
112
95
 
113
- expect(3).to eq(3)
114
- expect { 3.should eq(3) }.to raise_error(NameError)
115
- expect { 3.should_not eq(3) }.to raise_error(NameError)
116
- end
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)
117
99
  end
118
100
 
119
101
  it 'is a no-op when configured to :expect twice' do
120
- sandboxed do
121
- RSpec::Matchers.stub(:method_added).and_raise("no methods should be added here")
102
+ RSpec::Matchers.stub(:method_added).and_raise("no methods should be added here")
122
103
 
123
- configure_syntax :expect
124
- configure_syntax :expect
125
- end
104
+ configure_syntax :expect
105
+ configure_syntax :expect
126
106
  end
127
107
 
128
108
  it 'can re-enable the :should syntax' do
129
- sandboxed do
130
- configure_syntax :expect
131
- configure_syntax [:should, :expect]
132
- configured_syntax.should eq([:should, :expect])
109
+ configure_syntax :expect
110
+ configure_syntax [:should, :expect]
111
+ configured_syntax.should eq([:should, :expect])
133
112
 
134
- 3.should eq(3)
135
- 3.should_not eq(4)
136
- expect(3).to eq(3)
137
- end
113
+ 3.should eq(3)
114
+ 3.should_not eq(4)
115
+ expect(3).to eq(3)
138
116
  end
139
117
 
140
118
  it 'can re-enable the :expect syntax' do
141
- sandboxed do
142
- configure_syntax :should
143
- configure_syntax [:should, :expect]
144
- configured_syntax.should eq([:should, :expect])
119
+ configure_syntax :should
120
+ configure_syntax [:should, :expect]
121
+ configured_syntax.should eq([:should, :expect])
145
122
 
146
- 3.should eq(3)
147
- 3.should_not eq(4)
148
- expect(3).to eq(3)
149
- end
123
+ 3.should eq(3)
124
+ 3.should_not eq(4)
125
+ expect(3).to eq(3)
150
126
  end
151
127
 
152
128
  it 'does not add the deprecated #should to ExpectationTarget when only :should is enabled' do
153
129
  et = Expectations::ExpectationTarget
154
130
 
155
- sandboxed do
156
- configure_syntax :should
157
- et.new(Proc.new {}).should be_an(et)
158
- et.new(Proc.new {}).should_not be_a(Proc)
159
- end
131
+ configure_syntax :should
132
+ et.new(Proc.new {}).should be_an(et)
133
+ et.new(Proc.new {}).should_not be_a(Proc)
160
134
  end
161
135
 
162
136
  it 'does not add the deprecated #should to ExpectationTarget when only :expect is enabled' do
163
- sandboxed do
164
- configure_syntax :expect
165
- expect(expect(3)).not_to respond_to(:should)
166
- expect(expect(3)).not_to respond_to(:should_not)
167
- end
137
+ configure_syntax :expect
138
+ expect(expect(3)).not_to respond_to(:should)
139
+ expect(expect(3)).not_to respond_to(:should_not)
168
140
  end
169
141
 
170
142
  context 'when both :expect and :should are enabled' do
171
- before { RSpec.stub(:warn) }
143
+ before { allow(RSpec).to receive(:deprecate) }
172
144
 
173
145
  it 'allows `expect {}.should` to be used' do
174
- sandboxed do
175
- configure_syntax [:should, :expect]
176
- expect { raise "boom" }.should raise_error("boom")
177
- expect { }.should_not raise_error
178
- end
146
+ configure_syntax [:should, :expect]
147
+ expect { raise "boom" }.should raise_error("boom")
148
+ expect { }.should_not raise_error
179
149
  end
180
150
 
181
151
  it 'prints a deprecation notice when `expect {}.should` is used' do
182
- sandboxed do
183
- configure_syntax [:should, :expect]
152
+ configure_syntax [:should, :expect]
184
153
 
185
- RSpec.should_receive(:warn).with(/please use `expect \{ \}.to.*instead/)
186
- expect { raise "boom" }.should raise_error("boom")
154
+ expect(RSpec).to receive(:deprecate)
155
+ expect { raise "boom" }.should raise_error("boom")
187
156
 
188
- RSpec.should_receive(:warn).with(/please use `expect \{ \}.to_not.*instead/)
189
- expect { }.should_not raise_error
190
- end
157
+ expect(RSpec).to receive(:deprecate)
158
+ expect { }.should_not raise_error
191
159
  end
192
160
  end
193
161
  end