rspec-expectations 2.13.0 → 3.0.0

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 (142) hide show
  1. checksums.yaml +15 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data/Changelog.md +413 -23
  4. data/License.txt +1 -0
  5. data/README.md +109 -80
  6. data/lib/rspec/{matchers → expectations}/configuration.rb +44 -14
  7. data/lib/rspec/expectations/expectation_target.rb +71 -38
  8. data/lib/rspec/expectations/fail_with.rb +12 -44
  9. data/lib/rspec/expectations/handler.rb +135 -35
  10. data/lib/rspec/expectations/minitest_integration.rb +16 -0
  11. data/lib/rspec/expectations/syntax.rb +60 -94
  12. data/lib/rspec/expectations/version.rb +1 -1
  13. data/lib/rspec/expectations.rb +46 -24
  14. data/lib/rspec/matchers/aliased_matcher.rb +41 -0
  15. data/lib/rspec/matchers/built_in/all.rb +78 -0
  16. data/lib/rspec/matchers/built_in/base_matcher.rb +63 -15
  17. data/lib/rspec/matchers/built_in/be.rb +170 -79
  18. data/lib/rspec/matchers/built_in/be_between.rb +77 -0
  19. data/lib/rspec/matchers/built_in/be_instance_of.rb +11 -3
  20. data/lib/rspec/matchers/built_in/be_kind_of.rb +5 -0
  21. data/lib/rspec/matchers/built_in/be_within.rb +40 -16
  22. data/lib/rspec/matchers/built_in/change.rb +275 -74
  23. data/lib/rspec/matchers/built_in/compound.rb +122 -0
  24. data/lib/rspec/matchers/built_in/contain_exactly.rb +256 -0
  25. data/lib/rspec/matchers/built_in/cover.rb +3 -0
  26. data/lib/rspec/matchers/built_in/eq.rb +60 -6
  27. data/lib/rspec/matchers/built_in/eql.rb +17 -5
  28. data/lib/rspec/matchers/built_in/equal.rb +55 -21
  29. data/lib/rspec/matchers/built_in/exist.rb +74 -10
  30. data/lib/rspec/matchers/built_in/has.rb +71 -15
  31. data/lib/rspec/matchers/built_in/include.rb +58 -29
  32. data/lib/rspec/matchers/built_in/match.rb +19 -1
  33. data/lib/rspec/matchers/built_in/operators.rb +119 -0
  34. data/lib/rspec/matchers/built_in/output.rb +150 -0
  35. data/lib/rspec/matchers/built_in/raise_error.rb +91 -33
  36. data/lib/rspec/matchers/built_in/respond_to.rb +42 -20
  37. data/lib/rspec/matchers/built_in/satisfy.rb +19 -3
  38. data/lib/rspec/matchers/built_in/start_and_end_with.rb +54 -18
  39. data/lib/rspec/matchers/built_in/throw_symbol.rb +38 -8
  40. data/lib/rspec/matchers/built_in/yield.rb +237 -55
  41. data/lib/rspec/matchers/built_in.rb +45 -33
  42. data/lib/rspec/matchers/composable.rb +179 -0
  43. data/lib/rspec/matchers/dsl.rb +362 -5
  44. data/lib/rspec/matchers/generated_descriptions.rb +13 -6
  45. data/lib/rspec/matchers/matcher_delegator.rb +37 -0
  46. data/lib/rspec/matchers/pretty.rb +33 -20
  47. data/lib/rspec/matchers.rb +450 -227
  48. data.tar.gz.sig +1 -0
  49. metadata +100 -215
  50. metadata.gz.sig +0 -0
  51. data/features/README.md +0 -49
  52. data/features/Upgrade.md +0 -53
  53. data/features/built_in_matchers/README.md +0 -90
  54. data/features/built_in_matchers/be.feature +0 -175
  55. data/features/built_in_matchers/be_within.feature +0 -48
  56. data/features/built_in_matchers/cover.feature +0 -47
  57. data/features/built_in_matchers/end_with.feature +0 -48
  58. data/features/built_in_matchers/equality.feature +0 -139
  59. data/features/built_in_matchers/exist.feature +0 -45
  60. data/features/built_in_matchers/expect_change.feature +0 -59
  61. data/features/built_in_matchers/expect_error.feature +0 -144
  62. data/features/built_in_matchers/have.feature +0 -109
  63. data/features/built_in_matchers/include.feature +0 -174
  64. data/features/built_in_matchers/match.feature +0 -52
  65. data/features/built_in_matchers/operators.feature +0 -227
  66. data/features/built_in_matchers/predicates.feature +0 -137
  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 -146
  73. data/features/custom_matchers/access_running_example.feature +0 -53
  74. data/features/custom_matchers/define_diffable_matcher.feature +0 -27
  75. data/features/custom_matchers/define_matcher.feature +0 -368
  76. data/features/custom_matchers/define_matcher_outside_rspec.feature +0 -38
  77. data/features/custom_matchers/define_matcher_with_fluent_interface.feature +0 -24
  78. data/features/customized_message.feature +0 -22
  79. data/features/diffing.feature +0 -85
  80. data/features/implicit_docstrings.feature +0 -52
  81. data/features/step_definitions/additional_cli_steps.rb +0 -22
  82. data/features/support/env.rb +0 -5
  83. data/features/syntax_configuration.feature +0 -68
  84. data/features/test_frameworks/test_unit.feature +0 -46
  85. data/lib/rspec/expectations/deprecation.rb +0 -38
  86. data/lib/rspec/expectations/differ.rb +0 -115
  87. data/lib/rspec/expectations/errors.rb +0 -9
  88. data/lib/rspec/expectations/extensions/array.rb +0 -9
  89. data/lib/rspec/expectations/extensions/object.rb +0 -39
  90. data/lib/rspec/expectations/extensions.rb +0 -2
  91. data/lib/rspec/matchers/be_close.rb +0 -9
  92. data/lib/rspec/matchers/built_in/have.rb +0 -108
  93. data/lib/rspec/matchers/built_in/match_array.rb +0 -51
  94. data/lib/rspec/matchers/compatibility.rb +0 -14
  95. data/lib/rspec/matchers/extensions/instance_eval_with_args.rb +0 -39
  96. data/lib/rspec/matchers/matcher.rb +0 -300
  97. data/lib/rspec/matchers/method_missing.rb +0 -12
  98. data/lib/rspec/matchers/operator_matcher.rb +0 -109
  99. data/lib/rspec-expectations.rb +0 -1
  100. data/spec/rspec/expectations/differ_spec.rb +0 -170
  101. data/spec/rspec/expectations/expectation_target_spec.rb +0 -75
  102. data/spec/rspec/expectations/extensions/kernel_spec.rb +0 -67
  103. data/spec/rspec/expectations/fail_with_spec.rb +0 -95
  104. data/spec/rspec/expectations/handler_spec.rb +0 -206
  105. data/spec/rspec/expectations/syntax_spec.rb +0 -97
  106. data/spec/rspec/matchers/base_matcher_spec.rb +0 -62
  107. data/spec/rspec/matchers/be_close_spec.rb +0 -22
  108. data/spec/rspec/matchers/be_instance_of_spec.rb +0 -63
  109. data/spec/rspec/matchers/be_kind_of_spec.rb +0 -41
  110. data/spec/rspec/matchers/be_spec.rb +0 -516
  111. data/spec/rspec/matchers/be_within_spec.rb +0 -129
  112. data/spec/rspec/matchers/change_spec.rb +0 -542
  113. data/spec/rspec/matchers/configuration_spec.rb +0 -238
  114. data/spec/rspec/matchers/cover_spec.rb +0 -69
  115. data/spec/rspec/matchers/description_generation_spec.rb +0 -176
  116. data/spec/rspec/matchers/dsl_spec.rb +0 -57
  117. data/spec/rspec/matchers/eq_spec.rb +0 -60
  118. data/spec/rspec/matchers/eql_spec.rb +0 -41
  119. data/spec/rspec/matchers/equal_spec.rb +0 -78
  120. data/spec/rspec/matchers/exist_spec.rb +0 -124
  121. data/spec/rspec/matchers/has_spec.rb +0 -122
  122. data/spec/rspec/matchers/have_spec.rb +0 -445
  123. data/spec/rspec/matchers/include_matcher_integration_spec.rb +0 -30
  124. data/spec/rspec/matchers/include_spec.rb +0 -531
  125. data/spec/rspec/matchers/match_array_spec.rb +0 -194
  126. data/spec/rspec/matchers/match_spec.rb +0 -61
  127. data/spec/rspec/matchers/matcher_spec.rb +0 -471
  128. data/spec/rspec/matchers/matchers_spec.rb +0 -37
  129. data/spec/rspec/matchers/method_missing_spec.rb +0 -28
  130. data/spec/rspec/matchers/operator_matcher_spec.rb +0 -223
  131. data/spec/rspec/matchers/raise_error_spec.rb +0 -395
  132. data/spec/rspec/matchers/respond_to_spec.rb +0 -292
  133. data/spec/rspec/matchers/satisfy_spec.rb +0 -44
  134. data/spec/rspec/matchers/start_with_end_with_spec.rb +0 -186
  135. data/spec/rspec/matchers/throw_symbol_spec.rb +0 -116
  136. data/spec/rspec/matchers/yield_spec.rb +0 -437
  137. data/spec/spec_helper.rb +0 -54
  138. data/spec/support/classes.rb +0 -56
  139. data/spec/support/in_sub_process.rb +0 -38
  140. data/spec/support/matchers.rb +0 -22
  141. data/spec/support/ruby_version.rb +0 -10
  142. data/spec/support/shared_examples.rb +0 -13
@@ -1,116 +0,0 @@
1
- Feature: specify types of objects
2
-
3
- rspec-expectations includes two matchers to specify types of objects:
4
-
5
- * `obj.should be_kind_of(type)`: calls `obj.kind_of?(type)`, which returns
6
- true if type is in obj's class hierarchy or is a module and is
7
- included in a class in obj's class hierarchy.
8
- * `obj.should be_instance_of(type)`: calls `obj.instance_of?(type)`, which
9
- returns true if and only if type if obj's class.
10
-
11
- Both of these matchers have aliases:
12
-
13
- ```ruby
14
- obj.should be_a_kind_of(type) # same as obj.should be_kind_of(type)
15
- obj.should be_a(type) # same as obj.should be_kind_of(type)
16
- obj.should be_an(type) # same as obj.should be_kind_of(type)
17
- obj.should be_an_instance_of(type) # same as obj.should be_instance_of(type)
18
- ```
19
-
20
- Scenario: be_(a_)kind_of matcher
21
- Given a file named "be_kind_of_matcher_spec.rb" with:
22
- """ruby
23
- module MyModule; end
24
-
25
- class Fixnum
26
- include MyModule
27
- end
28
-
29
- describe 17 do
30
- # the actual class
31
- it { should be_kind_of(Fixnum) }
32
- it { should be_a_kind_of(Fixnum) }
33
- it { should be_a(Fixnum) }
34
-
35
- # the superclass
36
- it { should be_kind_of(Integer) }
37
- it { should be_a_kind_of(Integer) }
38
- it { should be_an(Integer) }
39
-
40
- # an included module
41
- it { should be_kind_of(MyModule) }
42
- it { should be_a_kind_of(MyModule) }
43
- it { should be_a(MyModule) }
44
-
45
- # negative passing case
46
- it { should_not be_kind_of(String) }
47
- it { should_not be_a_kind_of(String) }
48
- it { should_not be_a(String) }
49
-
50
- # deliberate failures
51
- it { should_not be_kind_of(Fixnum) }
52
- it { should_not be_a_kind_of(Fixnum) }
53
- it { should_not be_a(Fixnum) }
54
- it { should_not be_kind_of(Integer) }
55
- it { should_not be_a_kind_of(Integer) }
56
- it { should_not be_an(Integer) }
57
- it { should_not be_kind_of(MyModule) }
58
- it { should_not be_a_kind_of(MyModule) }
59
- it { should_not be_a(MyModule) }
60
- it { should be_kind_of(String) }
61
- it { should be_a_kind_of(String) }
62
- it { should be_a(String) }
63
- end
64
- """
65
- When I run `rspec be_kind_of_matcher_spec.rb`
66
- Then the output should contain all of these:
67
- | 24 examples, 12 failures |
68
- | expected 17 not to be a kind of Fixnum |
69
- | expected 17 not to be a kind of Integer |
70
- | expected 17 not to be a kind of MyModule |
71
- | expected 17 to be a kind of String |
72
-
73
- Scenario: be_(an_)instance_of matcher
74
- Given a file named "be_instance_of_matcher_spec.rb" with:
75
- """ruby
76
- module MyModule; end
77
-
78
- class Fixnum
79
- include MyModule
80
- end
81
-
82
- describe 17 do
83
- # the actual class
84
- it { should be_instance_of(Fixnum) }
85
- it { should be_an_instance_of(Fixnum) }
86
-
87
- # the superclass
88
- it { should_not be_instance_of(Integer) }
89
- it { should_not be_an_instance_of(Integer) }
90
-
91
- # an included module
92
- it { should_not be_instance_of(MyModule) }
93
- it { should_not be_an_instance_of(MyModule) }
94
-
95
- # another class with no relation to the subject's hierarchy
96
- it { should_not be_instance_of(String) }
97
- it { should_not be_an_instance_of(String) }
98
-
99
- # deliberate failures
100
- it { should_not be_instance_of(Fixnum) }
101
- it { should_not be_an_instance_of(Fixnum) }
102
- it { should be_instance_of(Integer) }
103
- it { should be_an_instance_of(Integer) }
104
- it { should be_instance_of(MyModule) }
105
- it { should be_an_instance_of(MyModule) }
106
- it { should be_instance_of(String) }
107
- it { should be_an_instance_of(String) }
108
- end
109
- """
110
- When I run `rspec be_instance_of_matcher_spec.rb`
111
- Then the output should contain all of these:
112
- | 16 examples, 8 failures |
113
- | expected 17 not to be an instance of Fixnum |
114
- | expected 17 to be an instance of Integer |
115
- | expected 17 to be an instance of MyModule |
116
- | expected 17 to be an instance of String |
@@ -1,146 +0,0 @@
1
- Feature: yield matchers
2
-
3
- There are four related matchers that allow you to specify whether
4
- or not a method yields, how many times it yields, whether or not
5
- it yields with arguments, and what those arguments are.
6
-
7
- * `yield_control` matches if the method-under-test yields, regardless
8
- of whether or not arguments are yielded.
9
- * `yield_with_args` matches if the method-under-test yields with
10
- arguments. If arguments are provided to this matcher, it will
11
- only pass if the actual yielded arguments match the expected ones
12
- using `===` or `==`.
13
- * `yield_with_no_args` matches if the method-under-test yields with
14
- no arguments.
15
- * `yield_successive_args` is designed for iterators, and will match
16
- if the method-under-test yields the same number of times as arguments
17
- passed to this matcher, and all actual yielded arguments match the
18
- expected ones using `===` or `==`.
19
-
20
- Note: your expect block _must_ accept an argument that is then passed on to
21
- the method-under-test as a block. This acts as a "probe" that allows the matcher
22
- to detect whether or not your method yields, and, if so, how many times and what
23
- the yielded arguments are.
24
-
25
- Background:
26
- Given a file named "my_class.rb" with:
27
- """ruby
28
- class MyClass
29
- def self.yield_once_with(*args)
30
- yield *args
31
- end
32
-
33
- def self.raw_yield
34
- yield
35
- end
36
-
37
- def self.dont_yield
38
- end
39
- end
40
- """
41
-
42
- Scenario: yield_control matcher
43
- Given a file named "yield_control_spec.rb" with:
44
- """ruby
45
- require './my_class'
46
-
47
- describe "yield_control matcher" do
48
- specify { expect { |b| MyClass.yield_once_with(1, &b) }.to yield_control }
49
- specify { expect { |b| MyClass.dont_yield(&b) }.not_to yield_control }
50
-
51
- # deliberate failures
52
- specify { expect { |b| MyClass.yield_once_with(1, &b) }.not_to yield_control }
53
- specify { expect { |b| MyClass.dont_yield(&b) }.to yield_control }
54
- end
55
- """
56
- When I run `rspec yield_control_spec.rb`
57
- Then the output should contain all of these:
58
- | 4 examples, 2 failures |
59
- | expected given block to yield control |
60
- | expected given block not to yield control |
61
-
62
- Scenario: yield_with_args matcher
63
- Given a file named "yield_with_args_spec.rb" with:
64
- """ruby
65
- require './my_class'
66
-
67
- describe "yield_with_args matcher" do
68
- specify { expect { |b| MyClass.yield_once_with("foo", &b) }.to yield_with_args }
69
- specify { expect { |b| MyClass.yield_once_with("foo", &b) }.to yield_with_args("foo") }
70
- specify { expect { |b| MyClass.yield_once_with("foo", &b) }.to yield_with_args(String) }
71
- specify { expect { |b| MyClass.yield_once_with("foo", &b) }.to yield_with_args(/oo/) }
72
-
73
- specify { expect { |b| MyClass.yield_once_with("foo", "bar", &b) }.to yield_with_args("foo", "bar") }
74
- specify { expect { |b| MyClass.yield_once_with("foo", "bar", &b) }.to yield_with_args(String, String) }
75
- specify { expect { |b| MyClass.yield_once_with("foo", "bar", &b) }.to yield_with_args(/fo/, /ar/) }
76
-
77
- specify { expect { |b| MyClass.yield_once_with("foo", "bar", &b) }.not_to yield_with_args(17, "baz") }
78
-
79
- # deliberate failures
80
- specify { expect { |b| MyClass.yield_once_with("foo", &b) }.not_to yield_with_args }
81
- specify { expect { |b| MyClass.yield_once_with("foo", &b) }.not_to yield_with_args("foo") }
82
- specify { expect { |b| MyClass.yield_once_with("foo", &b) }.not_to yield_with_args(String) }
83
- specify { expect { |b| MyClass.yield_once_with("foo", &b) }.not_to yield_with_args(/oo/) }
84
- specify { expect { |b| MyClass.yield_once_with("foo", "bar", &b) }.not_to yield_with_args("foo", "bar") }
85
- specify { expect { |b| MyClass.yield_once_with("foo", "bar", &b) }.to yield_with_args(17, "baz") }
86
- end
87
- """
88
- When I run `rspec yield_with_args_spec.rb`
89
- Then the output should contain all of these:
90
- | 14 examples, 6 failures |
91
- | expected given block not to yield with arguments, but did |
92
- | expected given block not to yield with arguments, but yielded with expected arguments |
93
- | expected given block to yield with arguments, but yielded with unexpected arguments |
94
-
95
- Scenario: yield_with_no_args matcher
96
- Given a file named "yield_with_no_args_spec.rb" with:
97
- """ruby
98
- require './my_class'
99
-
100
- describe "yield_with_no_args matcher" do
101
- specify { expect { |b| MyClass.raw_yield(&b) }.to yield_with_no_args }
102
- specify { expect { |b| MyClass.dont_yield(&b) }.not_to yield_with_no_args }
103
- specify { expect { |b| MyClass.yield_once_with("a", &b) }.not_to yield_with_no_args }
104
-
105
- # deliberate failures
106
- specify { expect { |b| MyClass.raw_yield(&b) }.not_to yield_with_no_args }
107
- specify { expect { |b| MyClass.dont_yield(&b) }.to yield_with_no_args }
108
- specify { expect { |b| MyClass.yield_once_with("a", &b) }.to yield_with_no_args }
109
- end
110
- """
111
- When I run `rspec yield_with_no_args_spec.rb`
112
- Then the output should contain all of these:
113
- | 6 examples, 3 failures |
114
- | expected given block not to yield with no arguments, but did |
115
- | expected given block to yield with no arguments, but did not yield |
116
- | expected given block to yield with no arguments, but yielded with arguments: ["a"] |
117
-
118
- Scenario: yield_successive_args matcher
119
- Given a file named "yield_successive_args_spec.rb" with:
120
- """ruby
121
- def array
122
- [1, 2, 3]
123
- end
124
-
125
- def array_of_tuples
126
- [[:a, :b], [:c, :d]]
127
- end
128
-
129
- describe "yield_successive_args matcher" do
130
- specify { expect { |b| array.each(&b) }.to yield_successive_args(1, 2, 3) }
131
- specify { expect { |b| array_of_tuples.each(&b) }.to yield_successive_args([:a, :b], [:c, :d]) }
132
- specify { expect { |b| array.each(&b) }.to yield_successive_args(Fixnum, Fixnum, Fixnum) }
133
- specify { expect { |b| array.each(&b) }.not_to yield_successive_args(1, 2) }
134
-
135
- # deliberate failures
136
- specify { expect { |b| array.each(&b) }.not_to yield_successive_args(1, 2, 3) }
137
- specify { expect { |b| array_of_tuples.each(&b) }.not_to yield_successive_args([:a, :b], [:c, :d]) }
138
- specify { expect { |b| array.each(&b) }.not_to yield_successive_args(Fixnum, Fixnum, Fixnum) }
139
- specify { expect { |b| array.each(&b) }.to yield_successive_args(1, 2) }
140
- end
141
- """
142
- When I run `rspec yield_successive_args_spec.rb`
143
- Then the output should contain all of these:
144
- | 8 examples, 4 failures |
145
- | expected given block not to yield successively with arguments, but yielded with expected arguments |
146
- | expected given block to yield successively with arguments, but yielded with unexpected arguments |
@@ -1,53 +0,0 @@
1
- Feature: access running example
2
-
3
- In order to take advantage of services that are available
4
- in my examples when I'm writing matchers
5
- As a spec author
6
- I want to call methods on the running example
7
-
8
- If the method exists in the context of the example, it gets
9
- called. If not, a NoMethodError is raised on the Matcher itself
10
- (not the example).
11
-
12
- Scenario: call method defined on example from matcher
13
- Given a file named "example_spec.rb" with:
14
- """ruby
15
- RSpec::Matchers.define :bar do
16
- match do |_|
17
- foo == "foo"
18
- end
19
- end
20
-
21
- describe "something" do
22
- def foo
23
- "foo"
24
- end
25
-
26
- it "does something" do
27
- "foo".should bar
28
- end
29
- end
30
- """
31
- When I run `rspec ./example_spec.rb`
32
- Then the output should contain "1 example, 0 failures"
33
-
34
- Scenario: call method _not_ defined on example from matcher
35
- Given a file named "example_spec.rb" with:
36
- """ruby
37
- RSpec::Matchers.define :bar do
38
- match do |_|
39
- foo == "foo"
40
- end
41
- end
42
-
43
- describe "something" do
44
- it "does something" do
45
- "foo".should bar
46
- end
47
- end
48
- """
49
- When I run `rspec ./example_spec.rb`
50
- Then the output should contain "1 example, 1 failure"
51
- And the output should match /undefined.*method/
52
- And the output should contain "RSpec::Matchers::DSL::Matcher"
53
- And the output should not contain "ExampleGroup"
@@ -1,27 +0,0 @@
1
- Feature: define diffable matcher
2
-
3
- When a matcher is defined as diffable, and the --diff
4
- flag is set, the output will include a diff of the submitted
5
- objects.
6
-
7
- @wip
8
- Scenario: define a diffable matcher
9
- Given a file named "diffable_matcher_spec.rb" with:
10
- """ruby
11
- RSpec::Matchers.define :be_just_like do |expected|
12
- match do |actual|
13
- actual == expected
14
- end
15
-
16
- diffable
17
- end
18
-
19
- describe "this" do
20
- it {should be_just_like("that")}
21
- end
22
- """
23
- When I run `rspec ./diffable_matcher_spec.rb --diff`
24
- Then the exit status should not be 0
25
-
26
- And the output should contain "should be just like that"
27
- And the output should contain "Diff:\n@@ -1,2 +1,2 @@\n-that\n+this"