rspec-expectations 3.0.0.beta2 → 3.0.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 (135) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +2 -2
  4. data/.yardopts +0 -1
  5. data/Changelog.md +115 -35
  6. data/README.md +2 -2
  7. data/lib/rspec/expectations.rb +13 -8
  8. data/lib/rspec/{matchers → expectations}/configuration.rb +38 -13
  9. data/lib/rspec/expectations/expectation_target.rb +72 -8
  10. data/lib/rspec/expectations/fail_with.rb +10 -52
  11. data/lib/rspec/expectations/handler.rb +9 -11
  12. data/lib/rspec/expectations/syntax.rb +37 -35
  13. data/lib/rspec/expectations/version.rb +1 -1
  14. data/lib/rspec/matchers.rb +60 -9
  15. data/lib/rspec/matchers/aliased_matcher.rb +6 -0
  16. data/lib/rspec/matchers/built_in.rb +9 -1
  17. data/lib/rspec/matchers/built_in/all.rb +78 -0
  18. data/lib/rspec/matchers/built_in/base_matcher.rb +39 -1
  19. data/lib/rspec/matchers/built_in/be.rb +117 -42
  20. data/lib/rspec/matchers/built_in/be_between.rb +22 -0
  21. data/lib/rspec/matchers/built_in/be_instance_of.rb +11 -3
  22. data/lib/rspec/matchers/built_in/be_kind_of.rb +5 -0
  23. data/lib/rspec/matchers/built_in/be_within.rb +26 -6
  24. data/lib/rspec/matchers/built_in/change.rb +89 -13
  25. data/lib/rspec/matchers/built_in/compound.rb +19 -3
  26. data/lib/rspec/matchers/built_in/contain_exactly.rb +17 -6
  27. data/lib/rspec/matchers/built_in/cover.rb +3 -0
  28. data/lib/rspec/matchers/built_in/eq.rb +20 -5
  29. data/lib/rspec/matchers/built_in/eql.rb +15 -3
  30. data/lib/rspec/matchers/built_in/equal.rb +23 -6
  31. data/lib/rspec/matchers/built_in/exist.rb +74 -10
  32. data/lib/rspec/matchers/built_in/has.rb +58 -3
  33. data/lib/rspec/matchers/built_in/include.rb +16 -1
  34. data/lib/rspec/matchers/built_in/match.rb +14 -4
  35. data/lib/rspec/matchers/built_in/operators.rb +16 -0
  36. data/lib/rspec/matchers/built_in/output.rb +47 -5
  37. data/lib/rspec/matchers/built_in/raise_error.rb +40 -23
  38. data/lib/rspec/matchers/built_in/respond_to.rb +37 -16
  39. data/lib/rspec/matchers/built_in/satisfy.rb +15 -0
  40. data/lib/rspec/matchers/built_in/start_and_end_with.rb +29 -14
  41. data/lib/rspec/matchers/built_in/throw_symbol.rb +32 -3
  42. data/lib/rspec/matchers/built_in/yield.rb +148 -44
  43. data/lib/rspec/matchers/composable.rb +48 -7
  44. data/lib/rspec/matchers/dsl.rb +45 -17
  45. data/lib/rspec/matchers/generated_descriptions.rb +7 -0
  46. data/lib/rspec/matchers/matcher_delegator.rb +6 -2
  47. data/lib/rspec/matchers/pretty.rb +15 -19
  48. metadata +33 -236
  49. metadata.gz.sig +0 -0
  50. data/features/README.md +0 -48
  51. data/features/Upgrade.md +0 -53
  52. data/features/built_in_matchers/README.md +0 -96
  53. data/features/built_in_matchers/be.feature +0 -175
  54. data/features/built_in_matchers/be_within.feature +0 -48
  55. data/features/built_in_matchers/comparisons.feature +0 -97
  56. data/features/built_in_matchers/contain_exactly.feature +0 -46
  57. data/features/built_in_matchers/cover.feature +0 -47
  58. data/features/built_in_matchers/end_with.feature +0 -48
  59. data/features/built_in_matchers/equality.feature +0 -136
  60. data/features/built_in_matchers/exist.feature +0 -45
  61. data/features/built_in_matchers/expect_change.feature +0 -59
  62. data/features/built_in_matchers/expect_error.feature +0 -144
  63. data/features/built_in_matchers/include.feature +0 -126
  64. data/features/built_in_matchers/match.feature +0 -51
  65. data/features/built_in_matchers/output.feature +0 -70
  66. data/features/built_in_matchers/predicates.feature +0 -161
  67. data/features/built_in_matchers/respond_to.feature +0 -84
  68. data/features/built_in_matchers/satisfy.feature +0 -33
  69. data/features/built_in_matchers/start_with.feature +0 -48
  70. data/features/built_in_matchers/throw_symbol.feature +0 -91
  71. data/features/built_in_matchers/types.feature +0 -116
  72. data/features/built_in_matchers/yield.feature +0 -161
  73. data/features/composing_matchers.feature +0 -250
  74. data/features/compound_expectations.feature +0 -45
  75. data/features/custom_matchers/access_running_example.feature +0 -53
  76. data/features/custom_matchers/define_diffable_matcher.feature +0 -27
  77. data/features/custom_matchers/define_matcher.feature +0 -340
  78. data/features/custom_matchers/define_matcher_outside_rspec.feature +0 -34
  79. data/features/custom_matchers/define_matcher_with_fluent_interface.feature +0 -24
  80. data/features/customized_message.feature +0 -39
  81. data/features/diffing.feature +0 -85
  82. data/features/implicit_docstrings.feature +0 -52
  83. data/features/step_definitions/additional_cli_steps.rb +0 -22
  84. data/features/support/env.rb +0 -21
  85. data/features/support/rubinius.rb +0 -6
  86. data/features/syntax_configuration.feature +0 -71
  87. data/features/test_frameworks/minitest.feature +0 -44
  88. data/lib/rspec-expectations.rb +0 -1
  89. data/lib/rspec/expectations/diff_presenter.rb +0 -141
  90. data/lib/rspec/expectations/differ.rb +0 -44
  91. data/lib/rspec/expectations/encoded_string.rb +0 -56
  92. data/spec/rspec/expectations/diff_presenter_spec.rb +0 -249
  93. data/spec/rspec/expectations/encoded_string_spec.rb +0 -74
  94. data/spec/rspec/expectations/expectation_target_spec.rb +0 -82
  95. data/spec/rspec/expectations/extensions/kernel_spec.rb +0 -67
  96. data/spec/rspec/expectations/fail_with_spec.rb +0 -114
  97. data/spec/rspec/expectations/handler_spec.rb +0 -205
  98. data/spec/rspec/expectations/minitest_integration_spec.rb +0 -27
  99. data/spec/rspec/expectations/syntax_spec.rb +0 -89
  100. data/spec/rspec/expectations_spec.rb +0 -12
  101. data/spec/rspec/matchers/aliased_matcher_spec.rb +0 -48
  102. data/spec/rspec/matchers/aliases_spec.rb +0 -449
  103. data/spec/rspec/matchers/built_in/base_matcher_spec.rb +0 -83
  104. data/spec/rspec/matchers/built_in/be_between_spec.rb +0 -159
  105. data/spec/rspec/matchers/built_in/be_instance_of_spec.rb +0 -63
  106. data/spec/rspec/matchers/built_in/be_kind_of_spec.rb +0 -41
  107. data/spec/rspec/matchers/built_in/be_spec.rb +0 -592
  108. data/spec/rspec/matchers/built_in/be_within_spec.rb +0 -141
  109. data/spec/rspec/matchers/built_in/change_spec.rb +0 -808
  110. data/spec/rspec/matchers/built_in/compound_spec.rb +0 -292
  111. data/spec/rspec/matchers/built_in/contain_exactly_spec.rb +0 -441
  112. data/spec/rspec/matchers/built_in/cover_spec.rb +0 -69
  113. data/spec/rspec/matchers/built_in/eq_spec.rb +0 -156
  114. data/spec/rspec/matchers/built_in/eql_spec.rb +0 -41
  115. data/spec/rspec/matchers/built_in/equal_spec.rb +0 -106
  116. data/spec/rspec/matchers/built_in/exist_spec.rb +0 -124
  117. data/spec/rspec/matchers/built_in/has_spec.rb +0 -161
  118. data/spec/rspec/matchers/built_in/include_spec.rb +0 -540
  119. data/spec/rspec/matchers/built_in/match_spec.rb +0 -102
  120. data/spec/rspec/matchers/built_in/operators_spec.rb +0 -252
  121. data/spec/rspec/matchers/built_in/output_spec.rb +0 -165
  122. data/spec/rspec/matchers/built_in/raise_error_spec.rb +0 -461
  123. data/spec/rspec/matchers/built_in/respond_to_spec.rb +0 -292
  124. data/spec/rspec/matchers/built_in/satisfy_spec.rb +0 -44
  125. data/spec/rspec/matchers/built_in/start_and_end_with_spec.rb +0 -253
  126. data/spec/rspec/matchers/built_in/throw_symbol_spec.rb +0 -135
  127. data/spec/rspec/matchers/built_in/yield_spec.rb +0 -627
  128. data/spec/rspec/matchers/configuration_spec.rb +0 -213
  129. data/spec/rspec/matchers/description_generation_spec.rb +0 -191
  130. data/spec/rspec/matchers/dsl_spec.rb +0 -895
  131. data/spec/rspec/matchers/legacy_spec.rb +0 -101
  132. data/spec/rspec/matchers_spec.rb +0 -74
  133. data/spec/spec_helper.rb +0 -85
  134. data/spec/support/matchers.rb +0 -22
  135. data/spec/support/shared_examples.rb +0 -35
@@ -1,44 +0,0 @@
1
- module RSpec
2
- module Expectations
3
- class Differ
4
- def initialize(actual, expected)
5
- @actual = actual
6
- @expected = expected
7
- end
8
-
9
- def hunks
10
- @file_length_difference = 0
11
- @hunks ||= diffs.map do |piece|
12
- build_hunk(piece)
13
- end
14
- end
15
-
16
- private
17
-
18
- def diffs
19
- Diff::LCS.diff(expected_lines, actual_lines)
20
- end
21
-
22
- def expected_lines
23
- @expected.split("\n").map! { |e| e.chomp }
24
- end
25
-
26
- def actual_lines
27
- @actual.split("\n").map! { |e| e.chomp }
28
- end
29
-
30
- def build_hunk(piece)
31
- Diff::LCS::Hunk.new(
32
- expected_lines, actual_lines, piece, context_lines, @file_length_difference
33
- ).tap do |h|
34
- @file_length_difference = h.file_length_difference
35
- end
36
- end
37
-
38
- def context_lines
39
- 3
40
- end
41
-
42
- end
43
- end
44
- end
@@ -1,56 +0,0 @@
1
- require "delegate"
2
-
3
- module RSpec
4
- module Expectations
5
- class EncodedString < SimpleDelegator
6
-
7
- def initialize(string, encoding = nil)
8
- @encoding = encoding
9
- @source_encoding = detect_source_encoding(string)
10
- @string = matching_encoding(string)
11
- super(@string)
12
- end
13
- attr_reader :source_encoding
14
-
15
- def <<(string)
16
- @string << matching_encoding(string)
17
- end
18
-
19
- def split(regex_or_string)
20
- @string.split(matching_encoding(regex_or_string))
21
- end
22
-
23
- private
24
-
25
- if String.method_defined?(:encoding)
26
- def matching_encoding(string)
27
- string.encode(@encoding)
28
- rescue Encoding::UndefinedConversionError, Encoding::InvalidByteSequenceError
29
- normalize_missing(string.encode(@encoding, :invalid => :replace, :undef => :replace))
30
- rescue Encoding::ConverterNotFoundError
31
- normalize_missing(string.force_encoding(@encoding).encode(:invalid => :replace))
32
- end
33
-
34
- def normalize_missing(string)
35
- if @encoding.to_s == "UTF-8"
36
- string.gsub("\xEF\xBF\xBD".force_encoding(@encoding), "?")
37
- else
38
- string
39
- end
40
- end
41
-
42
- def detect_source_encoding(string)
43
- string.encoding
44
- end
45
- else
46
- def matching_encoding(string)
47
- string
48
- end
49
-
50
- def detect_source_encoding(string)
51
- 'US-ASCII'
52
- end
53
- end
54
- end
55
- end
56
- end
@@ -1,249 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
- require 'ostruct'
4
-
5
- module RSpec
6
- module Expectations
7
- describe DiffPresenter do
8
- let(:differ) { RSpec::Expectations::DiffPresenter.new }
9
- context "without --color" do
10
-
11
- before { allow(RSpec::Matchers.configuration).to receive_messages(:color? => false) }
12
-
13
- describe '#diff_as_string' do
14
- subject { differ.diff_as_string(@actual, @expected) }
15
-
16
- it "outputs unified diff of two strings" do
17
- @expected = "foo\nzap\nbar\nthis\nis\nsoo\nvery\nvery\nequal\ninsert\na\nanother\nline\n"
18
- @actual = "foo\nbar\nzap\nthis\nis\nsoo\nvery\nvery\nequal\ninsert\na\nline\n"
19
- expect(subject).to eq(<<-'EOD')
20
-
21
-
22
- @@ -1,6 +1,6 @@
23
- foo
24
- -zap
25
- bar
26
- +zap
27
- this
28
- is
29
- soo
30
- @@ -9,6 +9,5 @@
31
- equal
32
- insert
33
- a
34
- -another
35
- line
36
- EOD
37
-
38
- end
39
-
40
- if String.method_defined?(:encoding)
41
- it 'copes with encoded strings' do
42
- @expected = "Tu avec carte {count} item has".encode('UTF-16LE')
43
- @actual = "Tu avec carté {count} itém has".encode('UTF-16LE')
44
- expect(subject).to eql(<<-EOD.encode('UTF-16LE'))
45
-
46
- @@ -1,2 +1,2 @@
47
- -Tu avec carte {count} item has
48
- +Tu avec carté {count} itém has
49
- EOD
50
- end
51
-
52
- it 'handles differently encoded strings that are compatible' do
53
- @expected = "abc".encode('us-ascii')
54
- @actual = "강인철".encode('UTF-8')
55
- expect(subject).to eql "\n@@ -1,2 +1,2 @@\n-abc\n+강인철\n"
56
- end
57
-
58
- it 'uses the default external encoding when the two strings have incompatible encodings' do
59
- @expected = "Tu avec carte {count} item has"
60
- @actual = "Tu avec carté {count} itém has".encode('UTF-16LE')
61
- expect(subject).to eq("\n@@ -1,2 +1,2 @@\n-Tu avec carte {count} item has\n+Tu avec carté {count} itém has\n")
62
- expect(subject.encoding).to eq(Encoding.default_external)
63
- end
64
-
65
- it 'handles any encoding error that occurs with a helpful error message' do
66
- expect(Differ).to receive(:new).and_raise(Encoding::CompatibilityError)
67
- @expected = "Tu avec carte {count} item has".encode('us-ascii')
68
- @actual = "Tu avec carté {count} itém has"
69
- expect(subject).to match(/Could not produce a diff/)
70
- expect(subject).to match(/actual string \(UTF-8\)/)
71
- expect(subject).to match(/expected string \(US-ASCII\)/)
72
- end
73
- end
74
- end
75
-
76
- describe '#diff_as_object' do
77
- it "outputs unified diff message of two objects" do
78
- animal_class = Class.new do
79
- def initialize(name, species)
80
- @name, @species = name, species
81
- end
82
-
83
- def inspect
84
- <<-EOA
85
- <Animal
86
- name=#{@name},
87
- species=#{@species}
88
- >
89
- EOA
90
- end
91
- end
92
-
93
- expected = animal_class.new "bob", "giraffe"
94
- actual = animal_class.new "bob", "tortoise"
95
-
96
- expected_diff = <<'EOD'
97
-
98
- @@ -1,5 +1,5 @@
99
- <Animal
100
- name=bob,
101
- - species=tortoise
102
- + species=giraffe
103
- >
104
- EOD
105
-
106
- diff = differ.diff_as_object(expected,actual)
107
- expect(diff).to eq expected_diff
108
- end
109
-
110
- it "outputs unified diff message of two arrays" do
111
- expected = [ :foo, 'bar', :baz, 'quux', :metasyntactic, 'variable', :delta, 'charlie', :width, 'quite wide' ]
112
- actual = [ :foo, 'bar', :baz, 'quux', :metasyntactic, 'variable', :delta, 'tango' , :width, 'very wide' ]
113
-
114
- expected_diff = <<'EOD'
115
-
116
-
117
- @@ -5,7 +5,7 @@
118
- :metasyntactic,
119
- "variable",
120
- :delta,
121
- - "tango",
122
- + "charlie",
123
- :width,
124
- - "very wide"]
125
- + "quite wide"]
126
- EOD
127
-
128
- diff = differ.diff_as_object(expected,actual)
129
- expect(diff).to eq expected_diff
130
- end
131
-
132
- it "outputs unified diff message of two hashes" do
133
- expected = { :foo => 'bar', :baz => 'quux', :metasyntactic => 'variable', :delta => 'charlie', :width =>'quite wide' }
134
- actual = { :foo => 'bar', :metasyntactic => 'variable', :delta => 'charlotte', :width =>'quite wide' }
135
-
136
- expected_diff = <<'EOD'
137
-
138
- @@ -1,4 +1,5 @@
139
- -:delta => "charlotte",
140
- +:baz => "quux",
141
- +:delta => "charlie",
142
- :foo => "bar",
143
- :metasyntactic => "variable",
144
- :width => "quite wide",
145
- EOD
146
-
147
- diff = differ.diff_as_object(expected,actual)
148
- expect(diff).to eq expected_diff
149
- end
150
-
151
- it 'outputs unified diff message of two hashes with differing encoding' do
152
- expected_diff = %Q{
153
- @@ -1,2 +1,2 @@
154
- -"a" => "a",
155
- #{ (RUBY_VERSION.to_f > 1.8) ? %Q{+"ö" => "ö"} : '+"\303\266" => "\303\266"' },
156
- }
157
-
158
- diff = differ.diff_as_object({'ö' => 'ö'}, {'a' => 'a'})
159
- expect(diff).to eq expected_diff
160
- end
161
-
162
- it 'outputs unified diff message of two hashes with encoding different to key encoding' do
163
- expected_diff = %Q{
164
- @@ -1,2 +1,2 @@
165
- -:a => "a",
166
- #{ (RUBY_VERSION.to_f > 1.8) ? %Q{+\"한글\" => \"한글2\"} : '+"\355\225\234\352\270\200" => "\355\225\234\352\270\2002"' },
167
- }
168
-
169
- diff = differ.diff_as_object({ "한글" => "한글2"}, { :a => "a"})
170
- expect(diff).to eq expected_diff
171
- end
172
-
173
- it "outputs unified diff message of two hashes with object keys" do
174
- expected_diff = %Q{
175
- @@ -1,2 +1,2 @@
176
- -["a", "c"] => "b",
177
- +["d", "c"] => "b",
178
- }
179
-
180
- diff = differ.diff_as_object({ ['d','c'] => 'b'}, { ['a','c'] => 'b' })
181
- expect(diff).to eq expected_diff
182
- end
183
-
184
- it "outputs unified diff of single line strings" do
185
- expected = "this is one string"
186
- actual = "this is another string"
187
-
188
- expected_diff = <<'EOD'
189
-
190
- @@ -1,2 +1,2 @@
191
- -"this is another string"
192
- +"this is one string"
193
- EOD
194
-
195
- diff = differ.diff_as_object(expected,actual)
196
- expect(diff).to eq expected_diff
197
- end
198
-
199
- it "outputs unified diff of multi line strings" do
200
- expected = "this is:\n one string"
201
- actual = "this is:\n another string"
202
-
203
- expected_diff = <<'EOD'
204
-
205
- @@ -1,3 +1,3 @@
206
- this is:
207
- - another string
208
- + one string
209
- EOD
210
-
211
- diff = differ.diff_as_object(expected,actual)
212
- expect(diff).to eq expected_diff
213
- end
214
-
215
- it "uses matcher descriptions in place of matchers in diffs" do
216
- expected = [a_string_matching(/foo/), a_string_matching(/bar/)]
217
- actual = ["poo", "car"]
218
-
219
- expected_diff = dedent(<<-EOS)
220
- |
221
- |@@ -1,2 +1,2 @@
222
- |-["poo", "car"]
223
- |+[(a string matching /foo/), (a string matching /bar/)]
224
- |
225
- EOS
226
-
227
- diff = differ.diff_as_object(expected,actual)
228
- expect(diff).to eq expected_diff
229
- end
230
- end
231
- end
232
-
233
- context "with --color" do
234
- before { allow(RSpec::Matchers.configuration).to receive_messages(:color? => true) }
235
-
236
- it "outputs colored diffs" do
237
- expected = "foo bar baz"
238
- actual = "foo bang baz"
239
- expected_diff = "\e[0m\n\e[0m\e[34m@@ -1,2 +1,2 @@\n\e[0m\e[31m-foo bang baz\n\e[0m\e[32m+foo bar baz\n\e[0m"
240
-
241
-
242
- diff = differ.diff_as_string(expected,actual)
243
- expect(diff).to eq expected_diff
244
- end
245
- end
246
-
247
- end
248
- end
249
- end
@@ -1,74 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module RSpec::Expectations
4
- describe EncodedString do
5
- let(:target_encoding) { 'UTF-8' }
6
-
7
- if String.method_defined?(:encoding)
8
-
9
- describe '#source_encoding' do
10
- it 'knows the original encoding of the string' do
11
- str = EncodedString.new("abc".encode('ASCII-8BIT'), "UTF-8")
12
- expect( str.source_encoding.to_s ).to eq('ASCII-8BIT')
13
- end
14
- end
15
-
16
- describe '#<<' do
17
- context 'with strings that can be converted to the target encoding' do
18
- it 'encodes and appends the string' do
19
- valid_ascii_string = "abc".force_encoding("ASCII-8BIT")
20
- valid_unicode_string = "\xE2\x82\xAC".force_encoding('UTF-8')
21
-
22
- resulting_string = build_encoded_string(valid_unicode_string, target_encoding) << valid_ascii_string
23
- expect(resulting_string).to eq "\xE2\x82\xACabc".force_encoding('UTF-8')
24
- end
25
- end
26
-
27
- context 'with a string that cannot be converted to the target encoding' do
28
- it 'replaces undefined characters with either a ? or a unicode ?' do
29
- ascii_string = "\xAE".force_encoding("ASCII-8BIT")
30
- valid_unicode_string = "\xE2\x82\xAC".force_encoding('UTF-8')
31
-
32
- resulting_string = build_encoded_string(valid_unicode_string, target_encoding) << ascii_string
33
- expected_bytes = [226, 130, 172, "?".unpack("c").first]
34
- actual_bytes = resulting_string.each_byte.to_a
35
-
36
- expect(actual_bytes).to eq(expected_bytes)
37
- end
38
- end
39
-
40
- context 'with two ascii strings with a target encoding of UTF-8 ' do
41
- it 'has an encoding of UTF-8' do
42
- ascii_string = 'abc'.force_encoding("ASCII-8BIT")
43
- other_ascii_string = '123'.force_encoding("ASCII-8BIT")
44
-
45
- resulting_string = build_encoded_string(ascii_string, target_encoding) << other_ascii_string
46
- expect(resulting_string.encoding.to_s).to eq 'UTF-8'
47
- end
48
- end
49
- end
50
-
51
- describe '#split' do
52
- it 'splits the string based on the delimiter accounting for encoding' do
53
- wrapped_string = "aaaaaaaaaaa\xAEaaaaa".force_encoding("ASCII-8BIT")
54
-
55
- expect {
56
- build_encoded_string(wrapped_string, target_encoding).split("\xE2\x82\xAC".force_encoding("UTF-8"))
57
- }.not_to raise_error
58
- end
59
- end
60
-
61
- def build_encoded_string(string, target_encoding)
62
- EncodedString.new(string, target_encoding)
63
- end
64
- else
65
-
66
- describe '#source_encoding' do
67
- it 'defaults to US-ASCII' do
68
- str = EncodedString.new("abc", "UTF-8")
69
- expect( str.source_encoding ).to eq('US-ASCII')
70
- end
71
- end
72
- end
73
- end
74
- end
@@ -1,82 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module RSpec
4
- module Expectations
5
- # so our examples below can set expectations about the target
6
- ExpectationTarget.send(:attr_reader, :target)
7
-
8
- describe ExpectationTarget do
9
- context 'when constructed via #expect' do
10
- it 'constructs a new instance targetting the given argument' do
11
- expect(expect(7).target).to eq(7)
12
- end
13
-
14
- it 'constructs a new instance targetting the given block' do
15
- block = lambda {}
16
- expect(expect(&block).target).to be(block)
17
- end
18
-
19
- it 'raises an ArgumentError when given an argument and a block' do
20
- expect {
21
- expect(7) { }
22
- }.to raise_error(ArgumentError)
23
- end
24
-
25
- it 'raises an ArgumentError when given neither an argument nor a block' do
26
- expect {
27
- expect
28
- }.to raise_error(ArgumentError)
29
- end
30
-
31
- it 'can be passed nil' do
32
- expect(expect(nil).target).to be_nil
33
- end
34
-
35
- it 'passes a valid positive expectation' do
36
- expect(5).to eq(5)
37
- end
38
-
39
- it 'passes a valid negative expectation' do
40
- expect(5).not_to eq(4)
41
- end
42
-
43
- it 'passes a valid negative expectation with a split infinitive' do
44
- expect(5).to_not eq(4)
45
- end
46
-
47
- it 'fails an invalid positive expectation' do
48
- expect {
49
- expect(5).to eq(4)
50
- }.to fail_with(/expected: 4.*got: 5/m)
51
- end
52
-
53
- it 'fails an invalid negative expectation' do
54
- message = /expected 5 not to be a kind of Fixnum/
55
- expect {
56
- expect(5).not_to be_a(Fixnum)
57
- }.to fail_with(message)
58
- end
59
-
60
- it 'fails an invalid negative expectation with a split infinitive' do
61
- message = /expected 5 not to be a kind of Fixnum/
62
- expect {
63
- expect(5).to_not be_a(Fixnum)
64
- }.to fail_with(message)
65
- end
66
-
67
- it 'does not support operator matchers from #to' do
68
- expect {
69
- expect(3).to == 3
70
- }.to raise_error(ArgumentError)
71
- end
72
-
73
- it 'does not support operator matchers from #not_to' do
74
- expect {
75
- expect(3).not_to == 4
76
- }.to raise_error(ArgumentError)
77
- end
78
- end
79
- end
80
- end
81
- end
82
-