rspec-expectations 2.11.3 → 3.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (152) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data/.document +1 -1
  4. data/.yardopts +1 -1
  5. data/Changelog.md +1026 -21
  6. data/{License.txt → LICENSE.md} +5 -3
  7. data/README.md +174 -78
  8. data/lib/rspec/expectations/block_snippet_extractor.rb +253 -0
  9. data/lib/rspec/expectations/configuration.rb +230 -0
  10. data/lib/rspec/expectations/expectation_target.rb +130 -55
  11. data/lib/rspec/expectations/fail_with.rb +17 -33
  12. data/lib/rspec/expectations/failure_aggregator.rb +212 -0
  13. data/lib/rspec/expectations/handler.rb +163 -29
  14. data/lib/rspec/expectations/minitest_integration.rb +58 -0
  15. data/lib/rspec/expectations/syntax.rb +68 -54
  16. data/lib/rspec/expectations/version.rb +1 -1
  17. data/lib/rspec/expectations.rb +59 -24
  18. data/lib/rspec/matchers/aliased_matcher.rb +116 -0
  19. data/lib/rspec/matchers/built_in/all.rb +86 -0
  20. data/lib/rspec/matchers/built_in/base_matcher.rb +150 -20
  21. data/lib/rspec/matchers/built_in/be.rb +115 -109
  22. data/lib/rspec/matchers/built_in/be_between.rb +77 -0
  23. data/lib/rspec/matchers/built_in/be_instance_of.rb +16 -1
  24. data/lib/rspec/matchers/built_in/be_kind_of.rb +10 -1
  25. data/lib/rspec/matchers/built_in/be_within.rb +43 -17
  26. data/lib/rspec/matchers/built_in/change.rb +392 -75
  27. data/lib/rspec/matchers/built_in/compound.rb +290 -0
  28. data/lib/rspec/matchers/built_in/contain_exactly.rb +302 -0
  29. data/lib/rspec/matchers/built_in/count_expectation.rb +169 -0
  30. data/lib/rspec/matchers/built_in/cover.rb +3 -0
  31. data/lib/rspec/matchers/built_in/eq.rb +26 -8
  32. data/lib/rspec/matchers/built_in/eql.rb +19 -8
  33. data/lib/rspec/matchers/built_in/equal.rb +56 -19
  34. data/lib/rspec/matchers/built_in/exist.rb +74 -10
  35. data/lib/rspec/matchers/built_in/has.rb +141 -22
  36. data/lib/rspec/matchers/built_in/have_attributes.rb +114 -0
  37. data/lib/rspec/matchers/built_in/include.rb +175 -20
  38. data/lib/rspec/matchers/built_in/match.rb +95 -1
  39. data/lib/rspec/matchers/built_in/operators.rb +128 -0
  40. data/lib/rspec/matchers/built_in/output.rb +207 -0
  41. data/lib/rspec/matchers/built_in/raise_error.rb +212 -38
  42. data/lib/rspec/matchers/built_in/respond_to.rb +155 -29
  43. data/lib/rspec/matchers/built_in/satisfy.rb +39 -9
  44. data/lib/rspec/matchers/built_in/start_or_end_with.rb +94 -0
  45. data/lib/rspec/matchers/built_in/throw_symbol.rb +58 -14
  46. data/lib/rspec/matchers/built_in/yield.rb +252 -98
  47. data/lib/rspec/matchers/built_in.rb +47 -33
  48. data/lib/rspec/matchers/composable.rb +171 -0
  49. data/lib/rspec/matchers/dsl.rb +530 -10
  50. data/lib/rspec/matchers/english_phrasing.rb +58 -0
  51. data/lib/rspec/matchers/expecteds_for_multiple_diffs.rb +82 -0
  52. data/lib/rspec/matchers/fail_matchers.rb +42 -0
  53. data/lib/rspec/matchers/generated_descriptions.rb +15 -10
  54. data/lib/rspec/matchers/matcher_delegator.rb +35 -0
  55. data/lib/rspec/matchers/matcher_protocol.rb +105 -0
  56. data/lib/rspec/matchers.rb +604 -252
  57. data.tar.gz.sig +0 -0
  58. metadata +178 -278
  59. metadata.gz.sig +0 -0
  60. data/features/README.md +0 -49
  61. data/features/Upgrade.md +0 -53
  62. data/features/built_in_matchers/README.md +0 -90
  63. data/features/built_in_matchers/be.feature +0 -173
  64. data/features/built_in_matchers/be_within.feature +0 -46
  65. data/features/built_in_matchers/cover.feature +0 -45
  66. data/features/built_in_matchers/end_with.feature +0 -46
  67. data/features/built_in_matchers/equality.feature +0 -145
  68. data/features/built_in_matchers/exist.feature +0 -43
  69. data/features/built_in_matchers/expect_change.feature +0 -59
  70. data/features/built_in_matchers/expect_error.feature +0 -138
  71. data/features/built_in_matchers/have.feature +0 -103
  72. data/features/built_in_matchers/include.feature +0 -121
  73. data/features/built_in_matchers/match.feature +0 -50
  74. data/features/built_in_matchers/operators.feature +0 -221
  75. data/features/built_in_matchers/predicates.feature +0 -128
  76. data/features/built_in_matchers/respond_to.feature +0 -78
  77. data/features/built_in_matchers/satisfy.feature +0 -31
  78. data/features/built_in_matchers/start_with.feature +0 -46
  79. data/features/built_in_matchers/throw_symbol.feature +0 -85
  80. data/features/built_in_matchers/types.feature +0 -114
  81. data/features/built_in_matchers/yield.feature +0 -146
  82. data/features/custom_matchers/access_running_example.feature +0 -53
  83. data/features/custom_matchers/define_diffable_matcher.feature +0 -27
  84. data/features/custom_matchers/define_matcher.feature +0 -340
  85. data/features/custom_matchers/define_matcher_outside_rspec.feature +0 -38
  86. data/features/custom_matchers/define_matcher_with_fluent_interface.feature +0 -24
  87. data/features/customized_message.feature +0 -22
  88. data/features/diffing.feature +0 -85
  89. data/features/implicit_docstrings.feature +0 -52
  90. data/features/step_definitions/additional_cli_steps.rb +0 -22
  91. data/features/support/env.rb +0 -5
  92. data/features/syntax_configuration.feature +0 -68
  93. data/features/test_frameworks/test_unit.feature +0 -46
  94. data/lib/rspec/expectations/deprecation.rb +0 -38
  95. data/lib/rspec/expectations/differ.rb +0 -81
  96. data/lib/rspec/expectations/errors.rb +0 -9
  97. data/lib/rspec/expectations/extensions/array.rb +0 -9
  98. data/lib/rspec/expectations/extensions/object.rb +0 -39
  99. data/lib/rspec/expectations/extensions.rb +0 -2
  100. data/lib/rspec/matchers/be_close.rb +0 -9
  101. data/lib/rspec/matchers/built_in/have.rb +0 -108
  102. data/lib/rspec/matchers/built_in/match_array.rb +0 -45
  103. data/lib/rspec/matchers/built_in/start_and_end_with.rb +0 -48
  104. data/lib/rspec/matchers/compatibility.rb +0 -14
  105. data/lib/rspec/matchers/configuration.rb +0 -66
  106. data/lib/rspec/matchers/extensions/instance_eval_with_args.rb +0 -39
  107. data/lib/rspec/matchers/matcher.rb +0 -299
  108. data/lib/rspec/matchers/method_missing.rb +0 -12
  109. data/lib/rspec/matchers/operator_matcher.rb +0 -84
  110. data/lib/rspec/matchers/pretty.rb +0 -60
  111. data/lib/rspec-expectations.rb +0 -1
  112. data/spec/rspec/expectations/differ_spec.rb +0 -153
  113. data/spec/rspec/expectations/expectation_target_spec.rb +0 -65
  114. data/spec/rspec/expectations/extensions/kernel_spec.rb +0 -67
  115. data/spec/rspec/expectations/fail_with_spec.rb +0 -70
  116. data/spec/rspec/expectations/handler_spec.rb +0 -206
  117. data/spec/rspec/matchers/base_matcher_spec.rb +0 -60
  118. data/spec/rspec/matchers/be_close_spec.rb +0 -22
  119. data/spec/rspec/matchers/be_instance_of_spec.rb +0 -40
  120. data/spec/rspec/matchers/be_kind_of_spec.rb +0 -37
  121. data/spec/rspec/matchers/be_spec.rb +0 -452
  122. data/spec/rspec/matchers/be_within_spec.rb +0 -80
  123. data/spec/rspec/matchers/change_spec.rb +0 -528
  124. data/spec/rspec/matchers/configuration_spec.rb +0 -202
  125. data/spec/rspec/matchers/cover_spec.rb +0 -69
  126. data/spec/rspec/matchers/description_generation_spec.rb +0 -176
  127. data/spec/rspec/matchers/dsl_spec.rb +0 -57
  128. data/spec/rspec/matchers/eq_spec.rb +0 -54
  129. data/spec/rspec/matchers/eql_spec.rb +0 -41
  130. data/spec/rspec/matchers/equal_spec.rb +0 -60
  131. data/spec/rspec/matchers/exist_spec.rb +0 -110
  132. data/spec/rspec/matchers/has_spec.rb +0 -118
  133. data/spec/rspec/matchers/have_spec.rb +0 -461
  134. data/spec/rspec/matchers/include_spec.rb +0 -367
  135. data/spec/rspec/matchers/match_array_spec.rb +0 -124
  136. data/spec/rspec/matchers/match_spec.rb +0 -61
  137. data/spec/rspec/matchers/matcher_spec.rb +0 -434
  138. data/spec/rspec/matchers/matchers_spec.rb +0 -31
  139. data/spec/rspec/matchers/method_missing_spec.rb +0 -24
  140. data/spec/rspec/matchers/operator_matcher_spec.rb +0 -221
  141. data/spec/rspec/matchers/raise_error_spec.rb +0 -344
  142. data/spec/rspec/matchers/respond_to_spec.rb +0 -295
  143. data/spec/rspec/matchers/satisfy_spec.rb +0 -44
  144. data/spec/rspec/matchers/start_with_end_with_spec.rb +0 -182
  145. data/spec/rspec/matchers/throw_symbol_spec.rb +0 -116
  146. data/spec/rspec/matchers/yield_spec.rb +0 -402
  147. data/spec/spec_helper.rb +0 -27
  148. data/spec/support/classes.rb +0 -56
  149. data/spec/support/in_sub_process.rb +0 -31
  150. data/spec/support/matchers.rb +0 -22
  151. data/spec/support/ruby_version.rb +0 -10
  152. data/spec/support/shared_examples.rb +0 -13
@@ -1,90 +0,0 @@
1
- # Built-in Matchers
2
-
3
- Here is a list of matchers that ship with rspec-expectations. Each matcher
4
- can be used with `should` or `should_not` e.g.
5
-
6
- result.should eq(3)
7
- list.should_not be_empty
8
-
9
- ## Object identity
10
-
11
- actual.should be(expected) # passes if actual.equal?(expected)
12
-
13
- ## Object equivalence
14
-
15
- actual.should eq(expected) # passes if actual == expected
16
-
17
- ## Optional APIs for identity/equivalence
18
-
19
- actual.should == expected # passes if actual == expected
20
- actual.should eql(expected) # passes if actual.eql?(expected)
21
- actual.should equal(expected) # passes if actual.equal?(expected)
22
-
23
- # NOTE: this can't work in Ruby 1.8, so we don't support it at all:
24
- # actual.should != expected
25
- # The reason is that Ruby 1.8 parses it as:
26
- # !(actual.should.==(expected)),
27
- # so by the time RSpec sees it it has no way to know that it's
28
- # been negated. Use either of these instead:
29
- # actual.should_not eq(expected)
30
- # actual.should_not == expected
31
-
32
- ## Comparisons
33
-
34
- actual.should be > expected
35
- actual.should be >= expected
36
- actual.should be <= expected
37
- actual.should be < expected
38
- actual.should =~ /expression/
39
- actual.should match(/expression/)
40
- actual.should be_within(delta).of(expected)
41
-
42
- ## Types/classes
43
-
44
- actual.should be_instance_of(expected)
45
- actual.should be_kind_of(expected)
46
-
47
- ## Truthiness and existentialism
48
-
49
- actual.should be_true # passes if actual is truthy (not nil or false)
50
- actual.should be_false # passes if actual is falsy (nil or false)
51
- actual.should be_nil # passes if actual is nil
52
- actual.should be # passes if actual is truthy (not nil or false)
53
-
54
- ## Expecting errors
55
-
56
- expect { ... }.to raise_error
57
- expect { ... }.to raise_error(ErrorClass)
58
- expect { ... }.to raise_error("message")
59
- expect { ... }.to raise_error(ErrorClass, "message")
60
-
61
- ## Expecting throws
62
-
63
- expect { ... }.to throw_symbol
64
- expect { ... }.to throw_symbol(:symbol)
65
- expect { ... }.to throw_symbol(:symbol, 'value')
66
-
67
- ## Predicate matchers
68
-
69
- actual.should be_xxx # passes if actual.xxx?
70
- actual.should have_xxx(:arg) # passes if actual.has_xxx?(:arg)
71
-
72
- ### Examples
73
-
74
- [].should be_empty # passes because [].empty? returns true
75
- { :a => 1 }.should have_key(:a) # passes because the hash has the key :a
76
-
77
- ## Collection membership
78
-
79
- actual.should include(expected)
80
-
81
- ### Examples
82
-
83
- [1,2,3].should include(1)
84
- [1,2,3].should include(1, 2)
85
- {:a => 'b'}.should include(:a => 'b')
86
- "this string".should include("is str")
87
-
88
- ## Ranges (1.9 only)
89
-
90
- (1..10).should cover(3)
@@ -1,173 +0,0 @@
1
- Feature: "be" matchers
2
-
3
- There are several related "be" matchers:
4
-
5
- obj.should be_true # passes if obj is truthy (not nil or false)
6
- obj.should be_false # passes if obj is falsy (nil or false)
7
- obj.should be_nil # passes if obj is nil
8
- obj.should be # passes if obj is truthy (not nil or false)
9
-
10
- Scenario: be_true matcher
11
- Given a file named "be_true_spec.rb" with:
12
- """
13
- describe "be_true matcher" do
14
- specify { true.should be_true }
15
- specify { 7.should be_true }
16
- specify { "foo".should be_true }
17
- specify { nil.should_not be_true }
18
- specify { false.should_not be_true }
19
-
20
- # deliberate failures
21
- specify { true.should_not be_true }
22
- specify { 7.should_not be_true }
23
- specify { "foo".should_not be_true }
24
- specify { nil.should be_true }
25
- specify { false.should be_true }
26
- end
27
- """
28
- When I run `rspec be_true_spec.rb`
29
- Then the output should contain "10 examples, 5 failures"
30
- And the output should contain:
31
- """
32
- expected: non-true value
33
- got: true
34
- """
35
- And the output should contain:
36
- """
37
- expected: non-true value
38
- got: 7
39
- """
40
- And the output should contain:
41
- """
42
- expected: non-true value
43
- got: "foo"
44
- """
45
- And the output should contain:
46
- """
47
- expected: true value
48
- got: nil
49
- """
50
- And the output should contain:
51
- """
52
- expected: true value
53
- got: false
54
- """
55
-
56
- Scenario: be_false matcher
57
- Given a file named "be_false_spec.rb" with:
58
- """
59
- describe "be_false matcher" do
60
- specify { nil.should be_false }
61
- specify { false.should be_false }
62
- specify { true.should_not be_false }
63
- specify { 7.should_not be_false }
64
- specify { "foo".should_not be_false }
65
-
66
- # deliberate failures
67
- specify { nil.should_not be_false }
68
- specify { false.should_not be_false }
69
- specify { true.should be_false }
70
- specify { 7.should be_false }
71
- specify { "foo".should be_false }
72
- end
73
- """
74
- When I run `rspec be_false_spec.rb`
75
- Then the output should contain "10 examples, 5 failures"
76
- And the output should contain:
77
- """
78
- expected: non-false value
79
- got: nil
80
- """
81
- And the output should contain:
82
- """
83
- expected: non-false value
84
- got: false
85
- """
86
- And the output should contain:
87
- """
88
- expected: false value
89
- got: true
90
- """
91
- And the output should contain:
92
- """
93
- expected: false value
94
- got: 7
95
- """
96
- And the output should contain:
97
- """
98
- expected: false value
99
- got: "foo"
100
- """
101
-
102
- Scenario: be_nil matcher
103
- Given a file named "be_nil_spec.rb" with:
104
- """
105
- describe "be_nil matcher" do
106
- specify { nil.should be_nil }
107
- specify { false.should_not be_nil }
108
- specify { true.should_not be_nil }
109
- specify { 7.should_not be_nil }
110
- specify { "foo".should_not be_nil }
111
-
112
- # deliberate failures
113
- specify { nil.should_not be_nil }
114
- specify { false.should be_nil }
115
- specify { true.should be_nil }
116
- specify { 7.should be_nil }
117
- specify { "foo".should be_nil }
118
- end
119
- """
120
- When I run `rspec be_nil_spec.rb`
121
- Then the output should contain "10 examples, 5 failures"
122
- And the output should contain:
123
- """
124
- expected: not nil
125
- got: nil
126
- """
127
- And the output should contain:
128
- """
129
- expected: nil
130
- got: false
131
- """
132
- And the output should contain:
133
- """
134
- expected: nil
135
- got: true
136
- """
137
- And the output should contain:
138
- """
139
- expected: nil
140
- got: 7
141
- """
142
- And the output should contain:
143
- """
144
- expected: nil
145
- got: "foo"
146
- """
147
-
148
- Scenario: be matcher
149
- Given a file named "be_spec.rb" with:
150
- """
151
- describe "be_matcher" do
152
- specify { true.should be }
153
- specify { 7.should be }
154
- specify { "foo".should be }
155
- specify { nil.should_not be }
156
- specify { false.should_not be }
157
-
158
- # deliberate failures
159
- specify { true.should_not be }
160
- specify { 7.should_not be }
161
- specify { "foo".should_not be }
162
- specify { nil.should be }
163
- specify { false.should be }
164
- end
165
- """
166
- When I run `rspec be_spec.rb`
167
- Then the output should contain all of these:
168
- | 10 examples, 5 failures |
169
- | expected true to evaluate to false |
170
- | expected 7 to evaluate to false |
171
- | expected "foo" to evaluate to false |
172
- | expected nil to evaluate to true |
173
- | expected false to evaluate to true |
@@ -1,46 +0,0 @@
1
- Feature: be_within matcher
2
-
3
- Normal equality expectations do not work well for floating point values.
4
- Consider this irb session:
5
-
6
- > radius = 3
7
- => 3
8
- > area_of_circle = radius * radius * Math::PI
9
- => 28.2743338823081
10
- > area_of_circle == 28.2743338823081
11
- => false
12
-
13
- Instead, you should use the be_within matcher to check that the value
14
- is within a delta of your expected value:
15
-
16
- area_of_circle.should be_within(0.1).of(28.3)
17
-
18
- Note that the difference between the actual and expected values must be
19
- smaller than your delta; if it is equal, the matcher will fail.
20
-
21
- Scenario: basic usage
22
- Given a file named "be_within_matcher_spec.rb" with:
23
- """
24
- describe 27.5 do
25
- it { should be_within(0.5).of(27.9) }
26
- it { should be_within(0.5).of(28.0) }
27
- it { should be_within(0.5).of(27.1) }
28
- it { should be_within(0.5).of(27.0) }
29
-
30
- it { should_not be_within(0.5).of(28.1) }
31
- it { should_not be_within(0.5).of(26.9) }
32
-
33
- # deliberate failures
34
- it { should_not be_within(0.5).of(28) }
35
- it { should_not be_within(0.5).of(27) }
36
- it { should be_within(0.5).of(28.1) }
37
- it { should be_within(0.5).of(26.9) }
38
- end
39
- """
40
- When I run `rspec be_within_matcher_spec.rb`
41
- Then the output should contain all of these:
42
- | 10 examples, 4 failures |
43
- | expected 27.5 not to be within 0.5 of 28 |
44
- | expected 27.5 not to be within 0.5 of 27 |
45
- | expected 27.5 to be within 0.5 of 28.1 |
46
- | expected 27.5 to be within 0.5 of 26.9 |
@@ -1,45 +0,0 @@
1
- @ruby-1.9
2
- Feature: cover matcher
3
-
4
- Use the cover matcher to specify that a range covers one or more
5
- expected objects. This works on any object that responds to #cover? (such
6
- as a Range):
7
-
8
- (1..10).should cover(5)
9
- (1..10).should cover(4, 6)
10
- (1..10).should_not cover(11)
11
-
12
- Scenario: range usage
13
- Given a file named "range_cover_matcher_spec.rb" with:
14
- """
15
- describe (1..10) do
16
- it { should cover(4) }
17
- it { should cover(6) }
18
- it { should cover(8) }
19
- it { should cover(4, 6) }
20
- it { should cover(4, 6, 8) }
21
- it { should_not cover(11) }
22
- it { should_not cover(11, 12) }
23
-
24
- # deliberate failures
25
- it { should cover(11) }
26
- it { should_not cover(4) }
27
- it { should_not cover(6) }
28
- it { should_not cover(8) }
29
- it { should_not cover(4, 6, 8) }
30
-
31
- # both of these should fail since it covers 5 but not 11
32
- it { should cover(5, 11) }
33
- it { should_not cover(5, 11) }
34
- end
35
- """
36
- When I run `rspec range_cover_matcher_spec.rb`
37
- Then the output should contain all of these:
38
- | 14 examples, 7 failures |
39
- | expected 1..10 to cover 11 |
40
- | expected 1..10 not to cover 4 |
41
- | expected 1..10 not to cover 6 |
42
- | expected 1..10 not to cover 8 |
43
- | expected 1..10 not to cover 4, 6, and 8 |
44
- | expected 1..10 to cover 5 and 11 |
45
- | expected 1..10 not to cover 5 and 11 |
@@ -1,46 +0,0 @@
1
- Feature: end_with matcher
2
-
3
- Use the `end_with` matcher to specify that a string or array ends with the
4
- expected characters or elements.
5
-
6
- "this string".should end_with "string"
7
- "this string".should_not end_with "stringy"
8
- [0, 1, 2].should end_with 1, 2
9
-
10
- Scenario: string usage
11
- Given a file named "example_spec.rb" with:
12
- """
13
- describe "this string" do
14
- it { should end_with "string" }
15
- it { should_not end_with "stringy" }
16
-
17
- # deliberate failures
18
- it { should_not end_with "string" }
19
- it { should end_with "stringy" }
20
- end
21
- """
22
- When I run `rspec example_spec.rb`
23
- Then the output should contain all of these:
24
- | 4 examples, 2 failures |
25
- | expected "this string" not to end with "string" |
26
- | expected "this string" to end with "stringy" |
27
-
28
- Scenario: array usage
29
- Given a file named "example_spec.rb" with:
30
- """
31
- describe [0, 1, 2, 3, 4] do
32
- it { should end_with 4 }
33
- it { should end_with 3, 4 }
34
- it { should_not end_with 3 }
35
- it { should_not end_with 0, 1, 2, 3, 4, 5 }
36
-
37
- # deliberate failures
38
- it { should_not end_with 4 }
39
- it { should end_with 3 }
40
- end
41
- """
42
- When I run `rspec example_spec.rb`
43
- Then the output should contain all of these:
44
- | 6 examples, 2 failures |
45
- | expected [0, 1, 2, 3, 4] not to end with 4 |
46
- | expected [0, 1, 2, 3, 4] to end with 3 |
@@ -1,145 +0,0 @@
1
- Feature: equality matchers
2
-
3
- Ruby exposes several different methods for handling equality:
4
-
5
- a.equal?(b) # object identity - a and b refer to the same object
6
- a.eql?(b) # object equivalence - a and b have the same value
7
- a == b # object equivalence - a and b have the same value with type conversions
8
-
9
- Note that these descriptions are guidelines but are not forced by the
10
- language. Any object can implement any of these methods with its own
11
- semantics.
12
-
13
- rspec-expectations ships with matchers that align with each of these methods:
14
-
15
- a.should equal(b) # passes if a.equal?(b)
16
- a.should eql(b) # passes if a.eql?(b)
17
- a.should == b # passes if a == b
18
-
19
- It also ships with two matchers that have more of a DSL feel to them:
20
-
21
- a.should be(b) # passes if a.equal?(b)
22
- a.should eq(b) # passes if a == b
23
-
24
- These are a useful pair if you wish to avoid the warning that Ruby emits on
25
- `a.should == b`
26
-
27
- Scenario: compare using eq (==)
28
- Given a file named "compare_using_eq.rb" with:
29
- """
30
- require 'spec_helper'
31
-
32
- describe "a string" do
33
- it "is equal to another string of the same value" do
34
- "this string".should eq("this string")
35
- end
36
-
37
- it "is not equal to another string of a different value" do
38
- "this string".should_not eq("a different string")
39
- end
40
- end
41
-
42
- describe "an integer" do
43
- it "is equal to a float of the same value" do
44
- 5.should eq(5.0)
45
- end
46
- end
47
- """
48
- When I run `rspec compare_using_eq.rb`
49
- Then the output should contain "3 examples, 0 failures"
50
-
51
- Scenario: compare using ==
52
- Given a file named "compare_using_==.rb" with:
53
- """
54
- require 'spec_helper'
55
-
56
- describe "a string" do
57
- it "is equal to another string of the same value" do
58
- "this string".should == "this string"
59
- end
60
-
61
- it "is not equal to another string of a different value" do
62
- "this string".should_not == "a different string"
63
- end
64
- end
65
-
66
- describe "an integer" do
67
- it "is equal to a float of the same value" do
68
- 5.should == 5.0
69
- end
70
- end
71
- """
72
- When I run `rspec compare_using_==.rb`
73
- Then the output should contain "3 examples, 0 failures"
74
-
75
- Scenario: compare using eql (eql?)
76
- Given a file named "compare_using_eql.rb" with:
77
- """
78
- require 'spec_helper'
79
-
80
- describe "an integer" do
81
- it "is equal to another integer of the same value" do
82
- 5.should eql(5)
83
- end
84
-
85
- it "is not equal to another integer of a different value" do
86
- 5.should_not eql(6)
87
- end
88
-
89
- it "is not equal to a float of the same value" do
90
- 5.should_not eql(5.0)
91
- end
92
-
93
- end
94
- """
95
- When I run `rspec compare_using_eql.rb`
96
- Then the output should contain "3 examples, 0 failures"
97
-
98
- Scenario: compare using equal (equal?)
99
- Given a file named "compare_using_equal.rb" with:
100
- """
101
- require 'spec_helper'
102
-
103
- describe "a string" do
104
- it "is equal to itself" do
105
- string = "this string"
106
- string.should equal(string)
107
- end
108
-
109
- it "is not equal to another string of the same value" do
110
- "this string".should_not equal("this string")
111
- end
112
-
113
- it "is not equal to another string of a different value" do
114
- "this string".should_not equal("a different string")
115
- end
116
-
117
- end
118
- """
119
- When I run `rspec compare_using_equal.rb`
120
- Then the output should contain "3 examples, 0 failures"
121
-
122
- Scenario: compare using be (equal?)
123
- Given a file named "compare_using_be.rb" with:
124
- """
125
- require 'spec_helper'
126
-
127
- describe "a string" do
128
- it "is equal to itself" do
129
- string = "this string"
130
- string.should be(string)
131
- end
132
-
133
- it "is not equal to another string of the same value" do
134
- "this string".should_not be("this string")
135
- end
136
-
137
- it "is not equal to another string of a different value" do
138
- "this string".should_not be("a different string")
139
- end
140
-
141
- end
142
- """
143
- When I run `rspec compare_using_be.rb`
144
- Then the output should contain "3 examples, 0 failures"
145
-
@@ -1,43 +0,0 @@
1
- Feature: exist matcher
2
-
3
- The exist matcher is used to specify that something exists
4
- (as indicated by #exist? or #exists?):
5
-
6
- obj.should exist # passes if obj.exist? or obj.exists?
7
-
8
- Scenario: basic usage
9
- Given a file named "exist_matcher_spec.rb" with:
10
- """
11
- class Planet
12
- attr_reader :name
13
-
14
- def initialize(name)
15
- @name = name
16
- end
17
-
18
- def inspect
19
- "<Planet: #{name}>"
20
- end
21
-
22
- def exist? # also works with exists?
23
- %w[Mercury Venus Earth Mars Jupiter Saturn Uranus Neptune].include?(name)
24
- end
25
- end
26
-
27
- describe "Earth" do
28
- let(:earth) { Planet.new("Earth") }
29
- specify { earth.should exist }
30
- specify { earth.should_not exist } # deliberate failure
31
- end
32
-
33
- describe "Tatooine" do
34
- let(:tatooine) { Planet.new("Tatooine") }
35
- it { tatooine.should exist } # deliberate failure
36
- it { tatooine.should_not exist }
37
- end
38
- """
39
- When I run `rspec exist_matcher_spec.rb`
40
- Then the output should contain all of these:
41
- | 4 examples, 2 failures |
42
- | expected <Planet: Earth> not to exist |
43
- | expected <Planet: Tatooine> to exist |
@@ -1,59 +0,0 @@
1
- Feature: expect change
2
-
3
- Expect the execution of a block of code to change the state of an object.
4
-
5
- Background:
6
- Given a file named "lib/counter.rb" with:
7
- """
8
- class Counter
9
- class << self
10
- def increment
11
- @count ||= 0
12
- @count += 1
13
- end
14
-
15
- def count
16
- @count ||= 0
17
- end
18
- end
19
- end
20
- """
21
-
22
- Scenario: expect change
23
- Given a file named "spec/example_spec.rb" with:
24
- """
25
- require "counter"
26
-
27
- describe Counter, "#increment" do
28
- it "should increment the count" do
29
- expect { Counter.increment }.to change{Counter.count}.from(0).to(1)
30
- end
31
-
32
- # deliberate failure
33
- it "should increment the count by 2" do
34
- expect { Counter.increment }.to change{Counter.count}.by(2)
35
- end
36
- end
37
- """
38
- When I run `rspec spec/example_spec.rb`
39
- Then the output should contain "1 failure"
40
- Then the output should contain "should have been changed by 2, but was changed by 1"
41
-
42
- Scenario: expect no change
43
- Given a file named "spec/example_spec.rb" with:
44
- """
45
- require "counter"
46
-
47
- describe Counter, "#increment" do
48
- it "should not increment the count by 1 (using to_not)" do
49
- expect { Counter.increment }.to_not change{Counter.count}
50
- end
51
-
52
- it "should not increment the count by 1 (using not_to)" do
53
- expect { Counter.increment }.not_to change{Counter.count}
54
- end
55
- end
56
- """
57
- When I run `rspec spec/example_spec.rb`
58
- Then the output should contain "2 failures"
59
- Then the output should contain "should not have changed, but did change from 1 to 2"