rspec-expectations 2.12.1 → 2.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. data/Changelog.md +31 -0
  2. data/README.md +1 -1
  3. data/features/built_in_matchers/be.feature +6 -4
  4. data/features/built_in_matchers/be_within.feature +3 -1
  5. data/features/built_in_matchers/cover.feature +2 -0
  6. data/features/built_in_matchers/end_with.feature +2 -0
  7. data/features/built_in_matchers/equality.feature +9 -15
  8. data/features/built_in_matchers/exist.feature +2 -0
  9. data/features/built_in_matchers/expect_error.feature +14 -8
  10. data/features/built_in_matchers/have.feature +11 -5
  11. data/features/built_in_matchers/include.feature +53 -0
  12. data/features/built_in_matchers/match.feature +2 -0
  13. data/features/built_in_matchers/operators.feature +17 -11
  14. data/features/built_in_matchers/predicates.feature +21 -13
  15. data/features/built_in_matchers/respond_to.feature +7 -1
  16. data/features/built_in_matchers/satisfy.feature +2 -0
  17. data/features/built_in_matchers/start_with.feature +2 -0
  18. data/features/built_in_matchers/throw_symbol.feature +6 -0
  19. data/features/built_in_matchers/types.feature +8 -6
  20. data/lib/rspec/expectations/deprecation.rb +1 -1
  21. data/lib/rspec/expectations/differ.rb +8 -8
  22. data/lib/rspec/expectations/fail_with.rb +17 -3
  23. data/lib/rspec/expectations/syntax.rb +46 -0
  24. data/lib/rspec/expectations/version.rb +1 -1
  25. data/lib/rspec/matchers/built_in/be.rb +7 -3
  26. data/lib/rspec/matchers/built_in/be_within.rb +13 -4
  27. data/lib/rspec/matchers/built_in/change.rb +2 -2
  28. data/lib/rspec/matchers/built_in/equal.rb +5 -1
  29. data/lib/rspec/matchers/built_in/exist.rb +1 -1
  30. data/lib/rspec/matchers/built_in/have.rb +8 -8
  31. data/lib/rspec/matchers/built_in/include.rb +19 -3
  32. data/lib/rspec/matchers/built_in/respond_to.rb +1 -1
  33. data/lib/rspec/matchers/extensions/instance_eval_with_args.rb +1 -1
  34. data/lib/rspec/matchers/matcher.rb +4 -3
  35. data/lib/rspec/matchers/operator_matcher.rb +1 -1
  36. data/lib/rspec/matchers/pretty.rb +5 -1
  37. data/spec/rspec/expectations/differ_spec.rb +8 -15
  38. data/spec/rspec/expectations/expectation_target_spec.rb +18 -8
  39. data/spec/rspec/expectations/extensions/kernel_spec.rb +15 -15
  40. data/spec/rspec/expectations/fail_with_spec.rb +41 -16
  41. data/spec/rspec/expectations/handler_spec.rb +13 -13
  42. data/spec/rspec/expectations/syntax_spec.rb +70 -8
  43. data/spec/rspec/matchers/base_matcher_spec.rb +14 -12
  44. data/spec/rspec/matchers/be_close_spec.rb +1 -1
  45. data/spec/rspec/matchers/be_instance_of_spec.rb +14 -8
  46. data/spec/rspec/matchers/be_kind_of_spec.rb +12 -8
  47. data/spec/rspec/matchers/be_spec.rb +212 -148
  48. data/spec/rspec/matchers/be_within_spec.rb +91 -42
  49. data/spec/rspec/matchers/change_spec.rb +52 -38
  50. data/spec/rspec/matchers/configuration_spec.rb +19 -15
  51. data/spec/rspec/matchers/cover_spec.rb +19 -19
  52. data/spec/rspec/matchers/description_generation_spec.rb +86 -86
  53. data/spec/rspec/matchers/dsl_spec.rb +7 -7
  54. data/spec/rspec/matchers/eq_spec.rb +17 -11
  55. data/spec/rspec/matchers/eql_spec.rb +10 -10
  56. data/spec/rspec/matchers/equal_spec.rb +27 -9
  57. data/spec/rspec/matchers/exist_spec.rb +35 -21
  58. data/spec/rspec/matchers/has_spec.rb +33 -29
  59. data/spec/rspec/matchers/have_spec.rb +165 -151
  60. data/spec/rspec/matchers/include_matcher_integration_spec.rb +30 -0
  61. data/spec/rspec/matchers/include_spec.rb +282 -124
  62. data/spec/rspec/matchers/match_array_spec.rb +90 -49
  63. data/spec/rspec/matchers/match_spec.rb +21 -21
  64. data/spec/rspec/matchers/matcher_spec.rb +85 -48
  65. data/spec/rspec/matchers/matchers_spec.rb +12 -6
  66. data/spec/rspec/matchers/method_missing_spec.rb +5 -1
  67. data/spec/rspec/matchers/operator_matcher_spec.rb +216 -237
  68. data/spec/rspec/matchers/raise_error_spec.rb +132 -132
  69. data/spec/rspec/matchers/respond_to_spec.rb +109 -112
  70. data/spec/rspec/matchers/satisfy_spec.rb +16 -16
  71. data/spec/rspec/matchers/start_with_end_with_spec.rb +36 -32
  72. data/spec/rspec/matchers/throw_symbol_spec.rb +24 -24
  73. data/spec/rspec/matchers/yield_spec.rb +7 -7
  74. data/spec/spec_helper.rb +46 -19
  75. data/spec/support/in_sub_process.rb +27 -20
  76. metadata +81 -83
@@ -1,3 +1,5 @@
1
+ require 'spec_helper'
2
+
1
3
  module RSpec::Matchers::BuiltIn
2
4
  describe BaseMatcher do
3
5
  describe "#match_unless_raises" do
@@ -6,21 +8,21 @@ module RSpec::Matchers::BuiltIn
6
8
  end
7
9
 
8
10
  it "returns true if there are no errors" do
9
- matcher.match_unless_raises {}.should be_true
11
+ expect(matcher.match_unless_raises {}).to be_true
10
12
  end
11
13
 
12
14
  it "returns false if there is an error" do
13
- matcher.match_unless_raises { raise }.should be_false
15
+ expect(matcher.match_unless_raises { raise }).to be_false
14
16
  end
15
17
 
16
18
  it "returns false if the only submitted error is raised" do
17
- matcher.match_unless_raises(RuntimeError){ raise "foo" }.should be_false
19
+ expect(matcher.match_unless_raises(RuntimeError){ raise "foo" }).to be_false
18
20
  end
19
21
 
20
22
  it "returns false if any of several errors submitted is raised" do
21
- matcher.match_unless_raises(RuntimeError, ArgumentError, NameError) { raise "foo" }.should be_false
22
- matcher.match_unless_raises(RuntimeError, ArgumentError, NameError) { raise ArgumentError.new('') }.should be_false
23
- matcher.match_unless_raises(RuntimeError, ArgumentError, NameError) { raise NameError.new('') }.should be_false
23
+ expect(matcher.match_unless_raises(RuntimeError, ArgumentError, NameError) { raise "foo" }).to be_false
24
+ expect(matcher.match_unless_raises(RuntimeError, ArgumentError, NameError) { raise ArgumentError.new('') }).to be_false
25
+ expect(matcher.match_unless_raises(RuntimeError, ArgumentError, NameError) { raise NameError.new('') }).to be_false
24
26
  end
25
27
 
26
28
  it "re-raises any error other than one of those specified" do
@@ -31,8 +33,8 @@ module RSpec::Matchers::BuiltIn
31
33
 
32
34
  it "stores the rescued exception for use in messages" do
33
35
  matcher.match_unless_raises(RuntimeError){ raise "foo" }
34
- matcher.rescued_exception.should be_a(RuntimeError)
35
- matcher.rescued_exception.message.should eq("foo")
36
+ expect(matcher.rescued_exception).to be_a(RuntimeError)
37
+ expect(matcher.rescued_exception.message).to eq("foo")
36
38
  end
37
39
 
38
40
  end
@@ -49,11 +51,11 @@ module RSpec::Matchers::BuiltIn
49
51
  end
50
52
  end
51
53
 
52
- matcher.new(3).matches?(3).should be_true
53
- matcher.new(3).should eq(3)
54
+ expect(matcher.new(3).matches?(3)).to be_true
55
+ expect(matcher.new(3)).to eq(3)
54
56
 
55
- matcher.new(3).matches?(4).should be_false
56
- matcher.new(3).should_not eq(4)
57
+ expect(matcher.new(3).matches?(4)).to be_false
58
+ expect(matcher.new(3)).not_to eq(4)
57
59
  end
58
60
  end
59
61
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  module RSpec
4
4
  module Matchers
5
- describe "[actual.should] be_close(expected, delta)" do
5
+ describe "expect(actual).to be_close(expected, delta)" do
6
6
  before(:each) do
7
7
  RSpec.stub(:warn)
8
8
  end
@@ -3,27 +3,31 @@ require 'spec_helper'
3
3
  module RSpec
4
4
  module Matchers
5
5
  [:be_an_instance_of, :be_instance_of].each do |method|
6
- describe "actual.should #{method}(expected)" do
6
+ describe "expect(actual).to #{method}(expected)" do
7
7
  it_behaves_like "an RSpec matcher", :valid_value => 5, :invalid_value => "a" do
8
8
  let(:matcher) { send(method, Fixnum) }
9
9
  end
10
10
 
11
11
  it "passes if actual is instance of expected class" do
12
- 5.should send(method, Fixnum)
12
+ expect(5).to send(method, Fixnum)
13
13
  end
14
14
 
15
15
  it "fails if actual is instance of subclass of expected class" do
16
- lambda { 5.should send(method, Numeric) }.should fail_with(%Q{expected 5 to be an instance of Numeric})
16
+ expect {
17
+ expect(5).to send(method, Numeric)
18
+ }.to fail_with(%Q{expected 5 to be an instance of Numeric})
17
19
  end
18
20
 
19
21
  it "fails with failure message for should unless actual is instance of expected class" do
20
- lambda { "foo".should send(method, Array) }.should fail_with(%Q{expected "foo" to be an instance of Array})
22
+ expect {
23
+ expect("foo").to send(method, Array)
24
+ }.to fail_with(%Q{expected "foo" to be an instance of Array})
21
25
  end
22
26
 
23
27
  it "provides a description" do
24
28
  matcher = be_an_instance_of(Fixnum)
25
29
  matcher.matches?(Numeric)
26
- matcher.description.should == "be an instance of Fixnum"
30
+ expect(matcher.description).to eq "be an instance of Fixnum"
27
31
  end
28
32
 
29
33
  context "when expected provides an expanded inspect, e.g. AR::Base" do
@@ -39,15 +43,17 @@ module RSpec
39
43
 
40
44
  it "provides a description including only the class name" do
41
45
  matcher = be_an_instance_of(User)
42
- matcher.description.should == "be an instance of User"
46
+ expect(matcher.description).to eq "be an instance of User"
43
47
  end
44
48
  end
45
49
  end
46
50
 
47
- describe "actual.should_not #{method}(expected)" do
51
+ describe "expect(actual).not_to #{method}(expected)" do
48
52
 
49
53
  it "fails with failure message for should_not if actual is instance of expected class" do
50
- lambda { "foo".should_not send(method, String) }.should fail_with(%Q{expected "foo" not to be an instance of String})
54
+ expect {
55
+ expect("foo").not_to send(method, String)
56
+ }.to fail_with(%Q{expected "foo" not to be an instance of String})
51
57
  end
52
58
 
53
59
  end
@@ -3,33 +3,37 @@ require 'spec_helper'
3
3
  module RSpec
4
4
  module Matchers
5
5
  [:be_a_kind_of, :be_kind_of].each do |method|
6
- describe "actual.should #{method}(expected)" do
6
+ describe "expect(actual).to #{method}(expected)" do
7
7
  it_behaves_like "an RSpec matcher", :valid_value => 5, :invalid_value => "a" do
8
8
  let(:matcher) { send(method, Fixnum) }
9
9
  end
10
10
 
11
11
  it "passes if actual is instance of expected class" do
12
- 5.should send(method, Fixnum)
12
+ expect(5).to send(method, Fixnum)
13
13
  end
14
14
 
15
15
  it "passes if actual is instance of subclass of expected class" do
16
- 5.should send(method, Numeric)
16
+ expect(5).to send(method, Numeric)
17
17
  end
18
18
 
19
19
  it "fails with failure message for should unless actual is kind of expected class" do
20
- lambda { "foo".should send(method, Array) }.should fail_with(%Q{expected "foo" to be a kind of Array})
20
+ expect {
21
+ expect("foo").to send(method, Array)
22
+ }.to fail_with(%Q{expected "foo" to be a kind of Array})
21
23
  end
22
24
 
23
25
  it "provides a description" do
24
26
  matcher = be_a_kind_of(String)
25
27
  matcher.matches?("this")
26
- matcher.description.should == "be a kind of String"
28
+ expect(matcher.description).to eq "be a kind of String"
27
29
  end
28
30
  end
29
-
30
- describe "actual.should_not #{method}(expected)" do
31
+
32
+ describe "expect(actual).not_to #{method}(expected)" do
31
33
  it "fails with failure message for should_not if actual is kind of expected class" do
32
- lambda { "foo".should_not send(method, String) }.should fail_with(%Q{expected "foo" not to be a kind of String})
34
+ expect {
35
+ expect("foo").not_to send(method, String)
36
+ }.to fail_with(%Q{expected "foo" not to be a kind of String})
33
37
  end
34
38
  end
35
39
  end
@@ -1,129 +1,129 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "should be_predicate" do
3
+ describe "expect(...).to be_predicate" do
4
4
  it "passes when actual returns true for :predicate?" do
5
5
  actual = stub("actual", :happy? => true)
6
- actual.should be_happy
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
10
  actual = stub("actual", :exists? => true, :exist? => true)
11
- actual.should be_exist
11
+ expect(actual).to be_exist
12
12
  end
13
13
 
14
14
  it "fails when actual returns false for :predicate?" do
15
15
  actual = stub("actual", :happy? => false)
16
- lambda {
17
- actual.should be_happy
18
- }.should fail_with("expected happy? to return true, got false")
16
+ expect {
17
+ expect(actual).to be_happy
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
22
  actual = stub("actual", :happy? => nil)
23
- lambda {
24
- actual.should be_happy
25
- }.should fail_with("expected happy? to return true, got nil")
23
+ expect {
24
+ expect(actual).to be_happy
25
+ }.to fail_with("expected happy? to return true, got nil")
26
26
  end
27
27
 
28
28
  it "fails when actual does not respond to :predicate?" do
29
- lambda {
30
- Object.new.should be_happy
31
- }.should raise_error(NameError, /happy\?/)
29
+ expect {
30
+ expect(Object.new).to be_happy
31
+ }.to raise_error(NameError, /happy\?/)
32
32
  end
33
33
 
34
34
  it "fails on error other than NameError" do
35
35
  actual = stub("actual")
36
36
  actual.should_receive(:foo?).and_raise("aaaah")
37
- lambda {
38
- actual.should be_foo
39
- }.should raise_error(/aaaah/)
37
+ expect {
38
+ expect(actual).to be_foo
39
+ }.to raise_error(/aaaah/)
40
40
  end
41
41
 
42
42
  it "fails on error other than NameError (with the present tense predicate)" do
43
43
  actual = Object.new
44
44
  actual.should_receive(:foos?).and_raise("aaaah")
45
- lambda {
46
- actual.should be_foo
47
- }.should raise_error(/aaaah/)
45
+ expect {
46
+ expect(actual).to be_foo
47
+ }.to raise_error(/aaaah/)
48
48
  end
49
49
  end
50
50
 
51
- describe "should_not be_predicate" do
51
+ describe "expect(...).not_to be_predicate" do
52
52
  it "passes when actual returns false for :sym?" do
53
53
  actual = stub("actual", :happy? => false)
54
- actual.should_not be_happy
54
+ expect(actual).not_to be_happy
55
55
  end
56
56
 
57
57
  it "passes when actual returns nil for :sym?" do
58
58
  actual = stub("actual", :happy? => nil)
59
- actual.should_not be_happy
59
+ expect(actual).not_to be_happy
60
60
  end
61
61
 
62
62
  it "fails when actual returns true for :sym?" do
63
63
  actual = stub("actual", :happy? => true)
64
- lambda {
65
- actual.should_not be_happy
66
- }.should fail_with("expected happy? to return false, got true")
64
+ expect {
65
+ expect(actual).not_to be_happy
66
+ }.to fail_with("expected happy? to return false, got true")
67
67
  end
68
68
 
69
69
  it "fails when actual does not respond to :sym?" do
70
- lambda {
71
- Object.new.should_not be_happy
72
- }.should raise_error(NameError)
70
+ expect {
71
+ expect(Object.new).not_to be_happy
72
+ }.to raise_error(NameError)
73
73
  end
74
74
  end
75
75
 
76
- describe "should be_predicate(*args)" do
76
+ describe "expect(...).to be_predicate(*args)" do
77
77
  it "passes when actual returns true for :predicate?(*args)" do
78
78
  actual = mock("actual")
79
79
  actual.should_receive(:older_than?).with(3).and_return(true)
80
- actual.should be_older_than(3)
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
84
  actual = mock("actual")
85
85
  actual.should_receive(:older_than?).with(3).and_return(false)
86
- lambda {
87
- actual.should be_older_than(3)
88
- }.should fail_with("expected older_than?(3) to return true, got false")
86
+ expect {
87
+ expect(actual).to be_older_than(3)
88
+ }.to fail_with("expected older_than?(3) to return true, got false")
89
89
  end
90
90
 
91
91
  it "fails when actual does not respond to :predicate?" do
92
- lambda {
93
- Object.new.should be_older_than(3)
94
- }.should raise_error(NameError)
92
+ expect {
93
+ expect(Object.new).to be_older_than(3)
94
+ }.to raise_error(NameError)
95
95
  end
96
96
  end
97
97
 
98
- describe "should_not be_predicate(*args)" do
98
+ describe "expect(...).not_to be_predicate(*args)" do
99
99
  it "passes when actual returns false for :predicate?(*args)" do
100
100
  actual = mock("actual")
101
101
  actual.should_receive(:older_than?).with(3).and_return(false)
102
- actual.should_not be_older_than(3)
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
106
  actual = mock("actual")
107
107
  actual.should_receive(:older_than?).with(3).and_return(true)
108
- lambda {
109
- actual.should_not be_older_than(3)
110
- }.should fail_with("expected older_than?(3) to return false, got true")
108
+ expect {
109
+ expect(actual).not_to be_older_than(3)
110
+ }.to fail_with("expected older_than?(3) to return false, got true")
111
111
  end
112
112
 
113
113
  it "fails when actual does not respond to :predicate?" do
114
- lambda {
115
- Object.new.should_not be_older_than(3)
116
- }.should raise_error(NameError)
114
+ expect {
115
+ expect(Object.new).not_to be_older_than(3)
116
+ }.to raise_error(NameError)
117
117
  end
118
118
  end
119
119
 
120
- describe "should be_predicate(&block)" do
120
+ describe "expect(...).to be_predicate(&block)" do
121
121
  it "passes when actual returns true for :predicate?(&block)" do
122
122
  actual = mock("actual")
123
123
  delegate = mock("delegate")
124
124
  actual.should_receive(:happy?).and_yield
125
125
  delegate.should_receive(:check_happy).and_return(true)
126
- actual.should be_happy { delegate.check_happy }
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
@@ -131,26 +131,26 @@ describe "should be_predicate(&block)" do
131
131
  delegate = mock("delegate")
132
132
  actual.should_receive(:happy?).and_yield
133
133
  delegate.should_receive(:check_happy).and_return(false)
134
- lambda {
135
- actual.should be_happy { delegate.check_happy }
136
- }.should fail_with("expected happy? to return true, got false")
134
+ expect {
135
+ expect(actual).to be_happy { delegate.check_happy }
136
+ }.to fail_with("expected happy? to return true, got false")
137
137
  end
138
138
 
139
139
  it "fails when actual does not respond to :predicate?" do
140
140
  delegate = mock("delegate", :check_happy => true)
141
- lambda {
142
- Object.new.should be_happy { delegate.check_happy }
143
- }.should raise_error(NameError)
141
+ expect {
142
+ expect(Object.new).to be_happy { delegate.check_happy }
143
+ }.to raise_error(NameError)
144
144
  end
145
145
  end
146
146
 
147
- describe "should_not be_predicate(&block)" do
147
+ describe "expect(...).not_to be_predicate(&block)" do
148
148
  it "passes when actual returns false for :predicate?(&block)" do
149
149
  actual = mock("actual")
150
150
  delegate = mock("delegate")
151
151
  actual.should_receive(:happy?).and_yield
152
152
  delegate.should_receive(:check_happy).and_return(false)
153
- actual.should_not be_happy { delegate.check_happy }
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
@@ -158,26 +158,26 @@ describe "should_not be_predicate(&block)" do
158
158
  delegate = mock("delegate")
159
159
  actual.should_receive(:happy?).and_yield
160
160
  delegate.should_receive(:check_happy).and_return(true)
161
- lambda {
162
- actual.should_not be_happy { delegate.check_happy }
163
- }.should fail_with("expected happy? to return false, got true")
161
+ expect {
162
+ expect(actual).not_to be_happy { delegate.check_happy }
163
+ }.to fail_with("expected happy? to return false, got true")
164
164
  end
165
165
 
166
166
  it "fails when actual does not respond to :predicate?" do
167
167
  delegate = mock("delegate", :check_happy => true)
168
- lambda {
169
- Object.new.should_not be_happy { delegate.check_happy }
170
- }.should raise_error(NameError)
168
+ expect {
169
+ expect(Object.new).not_to be_happy { delegate.check_happy }
170
+ }.to raise_error(NameError)
171
171
  end
172
172
  end
173
173
 
174
- describe "should be_predicate(*args, &block)" do
174
+ describe "expect(...).to be_predicate(*args, &block)" do
175
175
  it "passes when actual returns true for :predicate?(*args, &block)" do
176
176
  actual = mock("actual")
177
177
  delegate = mock("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
- actual.should be_older_than(3) { |age| delegate.check_older_than(age) }
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
@@ -185,26 +185,26 @@ describe "should be_predicate(*args, &block)" do
185
185
  delegate = mock("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
- lambda {
189
- actual.should be_older_than(3) { |age| delegate.check_older_than(age) }
190
- }.should fail_with("expected older_than?(3) to return true, got false")
188
+ expect {
189
+ expect(actual).to be_older_than(3) { |age| delegate.check_older_than(age) }
190
+ }.to fail_with("expected older_than?(3) to return true, got false")
191
191
  end
192
192
 
193
193
  it "fails when actual does not respond to :predicate?" do
194
194
  delegate = mock("delegate", :check_older_than => true)
195
- lambda {
196
- Object.new.should be_older_than(3) { |age| delegate.check_older_than(age) }
197
- }.should raise_error(NameError)
195
+ expect {
196
+ expect(Object.new).to be_older_than(3) { |age| delegate.check_older_than(age) }
197
+ }.to raise_error(NameError)
198
198
  end
199
199
  end
200
200
 
201
- describe "should_not be_predicate(*args, &block)" do
201
+ describe "expect(...).not_to be_predicate(*args, &block)" do
202
202
  it "passes when actual returns false for :predicate?(*args, &block)" do
203
203
  actual = mock("actual")
204
204
  delegate = mock("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
- actual.should_not be_older_than(3) { |age| delegate.check_older_than(age) }
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
@@ -212,199 +212,263 @@ describe "should_not be_predicate(*args, &block)" do
212
212
  delegate = mock("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
- lambda {
216
- actual.should_not be_older_than(3) { |age| delegate.check_older_than(age) }
217
- }.should fail_with("expected older_than?(3) to return false, got true")
215
+ expect {
216
+ expect(actual).not_to be_older_than(3) { |age| delegate.check_older_than(age) }
217
+ }.to fail_with("expected older_than?(3) to return false, got true")
218
218
  end
219
219
 
220
220
  it "fails when actual does not respond to :predicate?" do
221
221
  delegate = mock("delegate", :check_older_than => true)
222
- lambda {
223
- Object.new.should_not be_older_than(3) { |age| delegate.check_older_than(age) }
224
- }.should raise_error(NameError)
222
+ expect {
223
+ expect(Object.new).not_to be_older_than(3) { |age| delegate.check_older_than(age) }
224
+ }.to raise_error(NameError)
225
225
  end
226
226
  end
227
227
 
228
- describe "should be_true" do
228
+ describe "expect(...).to be_true" do
229
229
  it "passes when actual equal?(true)" do
230
- true.should be_true
230
+ expect(true).to be_true
231
231
  end
232
232
 
233
233
  it "passes when actual is 1" do
234
- 1.should be_true
234
+ expect(1).to be_true
235
235
  end
236
236
 
237
237
  it "fails when actual equal?(false)" do
238
- lambda {
239
- false.should be_true
240
- }.should fail_with("expected: true value\n got: false")
238
+ expect {
239
+ expect(false).to be_true
240
+ }.to fail_with("expected: true value\n got: false")
241
241
  end
242
242
  end
243
243
 
244
- describe "should be_false" do
244
+ describe "expect(...).to be_false" do
245
245
  it "passes when actual equal?(false)" do
246
- false.should be_false
246
+ expect(false).to be_false
247
247
  end
248
248
 
249
249
  it "passes when actual equal?(nil)" do
250
- nil.should be_false
250
+ expect(nil).to be_false
251
251
  end
252
252
 
253
253
  it "fails when actual equal?(true)" do
254
- lambda {
255
- true.should be_false
256
- }.should fail_with("expected: false value\n got: true")
254
+ expect {
255
+ expect(true).to be_false
256
+ }.to fail_with("expected: false value\n got: true")
257
257
  end
258
258
  end
259
259
 
260
- describe "should be_nil" do
260
+ describe "expect(...).to be_nil" do
261
261
  it "passes when actual is nil" do
262
- nil.should be_nil
262
+ expect(nil).to be_nil
263
263
  end
264
264
 
265
265
  it "fails when actual is not nil" do
266
- lambda {
267
- :not_nil.should be_nil
268
- }.should fail_with(/^expected: nil/)
266
+ expect {
267
+ expect(:not_nil).to be_nil
268
+ }.to fail_with(/^expected: nil/)
269
269
  end
270
270
  end
271
271
 
272
- describe "should_not be_nil" do
272
+ describe "expect(...).not_to be_nil" do
273
273
  it "passes when actual is not nil" do
274
- :not_nil.should_not be_nil
274
+ expect(:not_nil).not_to be_nil
275
275
  end
276
276
 
277
277
  it "fails when actual is nil" do
278
- lambda {
279
- nil.should_not be_nil
280
- }.should fail_with(/^expected: not nil/)
278
+ expect {
279
+ expect(nil).not_to be_nil
280
+ }.to fail_with(/^expected: not nil/)
281
281
  end
282
282
  end
283
283
 
284
- describe "should be <" do
284
+ describe "expect(...).to be <" do
285
285
  it "passes when < operator returns true" do
286
- 3.should be < 4
286
+ expect(3).to be < 4
287
287
  end
288
288
 
289
289
  it "fails when < operator returns false" do
290
- lambda { 3.should be < 3 }.should fail_with("expected: < 3\n got: 3")
290
+ expect {
291
+ expect(3).to be < 3
292
+ }.to fail_with("expected: < 3\n got: 3")
291
293
  end
292
294
 
293
295
  it "describes itself" do
294
- be.<(4).description.should == "be < 4"
296
+ expect(be.<(4).description).to eq "be < 4"
295
297
  end
296
298
  end
297
299
 
298
- describe "should be <=" do
300
+ describe "expect(...).to be <=" do
299
301
  it "passes when <= operator returns true" do
300
- 3.should be <= 4
301
- 4.should be <= 4
302
+ expect(3).to be <= 4
303
+ expect(4).to be <= 4
302
304
  end
303
305
 
304
306
  it "fails when <= operator returns false" do
305
- lambda { 3.should be <= 2 }.should fail_with("expected: <= 2\n got: 3")
307
+ expect {
308
+ expect(3).to be <= 2
309
+ }.to fail_with("expected: <= 2\n got: 3")
306
310
  end
307
311
  end
308
312
 
309
- describe "should be >=" do
313
+ describe "expect(...).to be >=" do
310
314
  it "passes when >= operator returns true" do
311
- 4.should be >= 4
312
- 5.should be >= 4
315
+ expect(4).to be >= 4
316
+ expect(5).to be >= 4
313
317
  end
314
318
 
315
319
  it "fails when >= operator returns false" do
316
- lambda { 3.should be >= 4 }.should fail_with("expected: >= 4\n got: 3")
320
+ expect {
321
+ expect(3).to be >= 4
322
+ }.to fail_with("expected: >= 4\n got: 3")
317
323
  end
318
324
  end
319
325
 
320
- describe "should be >" do
326
+ describe "expect(...).to be >" do
321
327
  it "passes when > operator returns true" do
322
- 5.should be > 4
328
+ expect(5).to be > 4
323
329
  end
324
330
 
325
331
  it "fails when > operator returns false" do
326
- lambda { 3.should be > 4 }.should fail_with("expected: > 4\n got: 3")
332
+ expect {
333
+ expect(3).to be > 4
334
+ }.to fail_with("expected: > 4\n got: 3")
327
335
  end
328
336
  end
329
337
 
330
- describe "should be ==" do
338
+ describe "expect(...).to be ==" do
331
339
  it "passes when == operator returns true" do
332
- 5.should be == 5
340
+ expect(5).to be == 5
333
341
  end
334
342
 
335
343
  it "fails when == operator returns false" do
336
- lambda { 3.should be == 4 }.should fail_with("expected: == 4\n got: 3")
344
+ expect {
345
+ expect(3).to be == 4
346
+ }.to fail_with("expected: == 4\n got: 3")
347
+ end
348
+
349
+ it 'works when the target overrides `#send`' do
350
+ klass = Struct.new(:message) do
351
+ def send
352
+ :message_sent
353
+ end
354
+ end
355
+
356
+ msg_1 = klass.new("hello")
357
+ msg_2 = klass.new("hello")
358
+ expect(msg_1).to be == msg_2
359
+ end
360
+ end
361
+
362
+ describe "expect(...).to be =~" do
363
+ it "passes when =~ operator returns true" do
364
+ expect("a string").to be =~ /str/
365
+ end
366
+
367
+ it "fails when =~ operator returns false" do
368
+ expect {
369
+ expect("a string").to be =~ /blah/
370
+ }.to fail_with(%Q|expected: =~ /blah/\n got: "a string"|)
371
+ end
372
+ end
373
+
374
+ describe "should be =~", :uses_should do
375
+ it "passes when =~ operator returns true" do
376
+ "a string".should be =~ /str/
377
+ end
378
+
379
+ it "fails when =~ operator returns false" do
380
+ expect {
381
+ "a string".should be =~ /blah/
382
+ }.to fail_with(%Q|expected: =~ /blah/\n got: "a string"|)
337
383
  end
338
384
  end
339
385
 
340
- describe "should be ===" do
386
+ describe "expect(...).to be ===" do
341
387
  it "passes when === operator returns true" do
342
- Hash.should be === Hash.new
388
+ expect(Hash).to be === Hash.new
343
389
  end
344
390
 
345
391
  it "fails when === operator returns false" do
346
- lambda { Hash.should be === "not a hash" }.should fail_with(%[expected: === "not a hash"\n got: Hash])
392
+ expect {
393
+ expect(Hash).to be === "not a hash"
394
+ }.to fail_with(%[expected: === "not a hash"\n got: Hash])
395
+ end
396
+ end
397
+
398
+ describe "expect(...).not_to with operators" do
399
+ it "coaches user to stop using operators with expect().not_to" do
400
+ expect {
401
+ expect(5).not_to be < 6
402
+ }.to raise_error(/`expect\(actual\).not_to be < 6` not only FAILED,\nit is a bit confusing./m)
347
403
  end
348
404
  end
349
405
 
350
- describe "should_not with operators" do
406
+ describe "should_not with operators", :uses_only_should do
351
407
  it "coaches user to stop using operators with should_not" do
352
408
  lambda {
353
409
  5.should_not be < 6
354
- }.should raise_error(/not only FAILED,\nit is a bit confusing./m)
410
+ }.should raise_error(/`actual.should_not be < 6` not only FAILED,\nit is a bit confusing./m)
355
411
  end
356
412
  end
357
413
 
358
- describe "should be" do
414
+ describe "expect(...).to be" do
359
415
  it "passes if actual is truthy" do
360
- true.should be
361
- 1.should be
416
+ expect(true).to be
417
+ expect(1).to be
362
418
  end
363
419
 
364
420
  it "fails if actual is false" do
365
- lambda {false.should be}.should fail_with("expected false to evaluate to true")
421
+ expect {
422
+ expect(false).to be
423
+ }.to fail_with("expected false to evaluate to true")
366
424
  end
367
425
 
368
426
  it "fails if actual is nil" do
369
- lambda {nil.should be}.should fail_with("expected nil to evaluate to true")
427
+ expect {
428
+ expect(nil).to be
429
+ }.to fail_with("expected nil to evaluate to true")
370
430
  end
371
431
 
372
432
  it "describes itself" do
373
- be.description.should == "be"
433
+ expect(be.description).to eq "be"
374
434
  end
375
435
  end
376
436
 
377
- describe "should_not be" do
437
+ describe "expect(...).not_to be" do
378
438
  it "passes if actual is falsy" do
379
- false.should_not be
380
- nil.should_not be
439
+ expect(false).not_to be
440
+ expect(nil).not_to be
381
441
  end
382
442
 
383
443
  it "fails on true" do
384
- lambda {true.should_not be}.should fail_with("expected true to evaluate to false")
444
+ expect {
445
+ expect(true).not_to be
446
+ }.to fail_with("expected true to evaluate to false")
385
447
  end
386
448
  end
387
449
 
388
- describe "should be(value)" do
450
+ describe "expect(...).to be(value)" do
389
451
  it "delegates to equal" do
390
- self.should_receive(:equal).with(5)
391
- 5.should be(5)
452
+ matcher = equal(5)
453
+ self.should_receive(:equal).with(5).and_return(matcher)
454
+ expect(5).to be(5)
392
455
  end
393
456
  end
394
457
 
395
- describe "should_not be(value)" do
458
+ describe "expect(...).not_to be(value)" do
396
459
  it "delegates to equal" do
397
- self.should_receive(:equal).with(4)
398
- 5.should_not be(4)
460
+ matcher = equal(4)
461
+ self.should_receive(:equal).with(4).and_return(matcher)
462
+ expect(5).not_to be(4)
399
463
  end
400
464
  end
401
465
 
402
- describe "'should be' with operator" do
466
+ describe "'expect(...).to be' with operator" do
403
467
  it "includes 'be' in the description" do
404
- (be > 6).description.should =~ /be > 6/
405
- (be >= 6).description.should =~ /be >= 6/
406
- (be <= 6).description.should =~ /be <= 6/
407
- (be < 6).description.should =~ /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/
408
472
  end
409
473
  end
410
474
 
@@ -424,29 +488,29 @@ describe "arbitrary predicate with DelegateClass" do
424
488
  end
425
489
 
426
490
  delegate = ArrayDelegate.new([1,2,3,4,5,6])
427
- delegate.should be_large
491
+ expect(delegate).to be_large
428
492
  end
429
493
  end
430
494
 
431
495
  describe "be_a, be_an" do
432
496
  it "passes when class matches" do
433
- "foobar".should be_a(String)
434
- [1,2,3].should be_an(Array)
497
+ expect("foobar").to be_a(String)
498
+ expect([1,2,3]).to be_an(Array)
435
499
  end
436
500
 
437
501
  it "fails when class does not match" do
438
- "foobar".should_not be_a(Hash)
439
- [1,2,3].should_not be_an(Integer)
502
+ expect("foobar").not_to be_a(Hash)
503
+ expect([1,2,3]).not_to be_an(Integer)
440
504
  end
441
505
  end
442
506
 
443
507
  describe "be_an_instance_of" do
444
508
  it "passes when direct class matches" do
445
- 5.should be_an_instance_of(Fixnum)
509
+ expect(5).to be_an_instance_of(Fixnum)
446
510
  end
447
511
 
448
512
  it "fails when class is higher up hierarchy" do
449
- 5.should_not be_an_instance_of(Numeric)
513
+ expect(5).not_to be_an_instance_of(Numeric)
450
514
  end
451
515
  end
452
516