rspec-core 2.99.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.
- checksums.yaml +8 -8
- checksums.yaml.gz.sig +0 -0
- data/.yardopts +1 -0
- data/Changelog.md +339 -1
- data/License.txt +1 -0
- data/README.md +19 -37
- data/exe/rspec +2 -23
- data/lib/rspec/core/backport_random.rb +336 -0
- data/lib/rspec/core/backtrace_formatter.rb +70 -0
- data/lib/rspec/core/configuration.rb +479 -577
- data/lib/rspec/core/configuration_options.rb +71 -54
- data/lib/rspec/core/drb.rb +111 -0
- data/lib/rspec/core/dsl.rb +86 -18
- data/lib/rspec/core/example.rb +267 -119
- data/lib/rspec/core/example_group.rb +381 -393
- data/lib/rspec/core/filter_manager.rb +133 -114
- data/lib/rspec/core/flat_map.rb +18 -0
- data/lib/rspec/core/formatters/base_formatter.rb +51 -125
- data/lib/rspec/core/formatters/base_text_formatter.rb +34 -286
- data/lib/rspec/core/formatters/console_codes.rb +24 -1
- data/lib/rspec/core/formatters/deprecation_formatter.rb +25 -26
- data/lib/rspec/core/formatters/documentation_formatter.rb +27 -25
- data/lib/rspec/core/formatters/helpers.rb +14 -36
- data/lib/rspec/core/formatters/html_formatter.rb +58 -65
- data/lib/rspec/core/formatters/html_printer.rb +12 -18
- data/lib/rspec/core/formatters/json_formatter.rb +54 -31
- data/lib/rspec/core/formatters/profile_formatter.rb +67 -0
- data/lib/rspec/core/formatters/progress_formatter.rb +11 -15
- data/lib/rspec/core/formatters/snippet_extractor.rb +22 -11
- data/lib/rspec/core/formatters.rb +90 -43
- data/lib/rspec/core/hooks.rb +325 -270
- data/lib/rspec/core/memoized_helpers.rb +45 -156
- data/lib/rspec/core/metadata.rb +284 -236
- data/lib/rspec/core/metadata_filter.rb +86 -0
- data/lib/rspec/core/mocking_adapters/flexmock.rb +29 -0
- data/lib/rspec/core/{mocking/with_mocha.rb → mocking_adapters/mocha.rb} +19 -16
- data/lib/rspec/core/mocking_adapters/null.rb +12 -0
- data/lib/rspec/core/mocking_adapters/rr.rb +29 -0
- data/lib/rspec/core/mocking_adapters/rspec.rb +30 -0
- data/lib/rspec/core/notifications.rb +511 -0
- data/lib/rspec/core/option_parser.rb +49 -74
- data/lib/rspec/core/ordering.rb +156 -0
- data/lib/rspec/core/pending.rb +94 -96
- data/lib/rspec/core/project_initializer/.rspec +3 -0
- data/lib/rspec/core/project_initializer/spec/spec_helper.rb +78 -0
- data/lib/rspec/core/project_initializer.rb +24 -64
- data/lib/rspec/core/rake_task.rb +44 -130
- data/lib/rspec/core/reporter.rb +76 -59
- data/lib/rspec/core/ruby_project.rb +2 -1
- data/lib/rspec/core/runner.rb +117 -52
- data/lib/rspec/core/shared_context.rb +10 -10
- data/lib/rspec/core/shared_example_group.rb +108 -121
- data/lib/rspec/core/version.rb +3 -1
- data/lib/rspec/core/warnings.rb +40 -0
- data/lib/rspec/core/world.rb +66 -10
- data/lib/rspec/core.rb +64 -104
- data.tar.gz.sig +3 -0
- metadata +75 -322
- metadata.gz.sig +1 -0
- data/exe/autospec +0 -13
- data/features/Autotest.md +0 -38
- data/features/README.md +0 -17
- data/features/Upgrade.md +0 -364
- data/features/command_line/README.md +0 -28
- data/features/command_line/example_name_option.feature +0 -97
- data/features/command_line/exit_status.feature +0 -82
- data/features/command_line/format_option.feature +0 -75
- data/features/command_line/init.feature +0 -18
- data/features/command_line/line_number_appended_to_path.feature +0 -140
- data/features/command_line/line_number_option.feature +0 -53
- data/features/command_line/order.feature +0 -26
- data/features/command_line/pattern_option.feature +0 -49
- data/features/command_line/rake_task.feature +0 -122
- data/features/command_line/require_option.feature +0 -43
- data/features/command_line/ruby.feature +0 -22
- data/features/command_line/tag.feature +0 -98
- data/features/command_line/warnings_option.feature +0 -29
- data/features/configuration/alias_example_to.feature +0 -48
- data/features/configuration/backtrace_clean_patterns.feature +0 -102
- data/features/configuration/custom_settings.feature +0 -84
- data/features/configuration/default_path.feature +0 -38
- data/features/configuration/deprecation_stream.feature +0 -58
- data/features/configuration/fail_fast.feature +0 -77
- data/features/configuration/failure_exit_code.feature +0 -36
- data/features/configuration/order_and_seed.feature +0 -3
- data/features/configuration/output_stream.feature +0 -24
- data/features/configuration/pattern.feature +0 -38
- data/features/configuration/profile.feature +0 -220
- data/features/configuration/read_options_from_file.feature +0 -90
- data/features/configuration/run_all_when_everything_filtered.feature +0 -76
- data/features/configuration/show_failures_in_pending_blocks.feature +0 -61
- data/features/configuration/treat_symbols_as_metadata_keys_with_true_values.feature +0 -52
- data/features/example_groups/basic_structure.feature +0 -55
- data/features/example_groups/shared_context.feature +0 -74
- data/features/example_groups/shared_examples.feature +0 -294
- data/features/expectation_framework_integration/configure_expectation_framework.feature +0 -197
- data/features/filtering/exclusion_filters.feature +0 -138
- data/features/filtering/if_and_unless.feature +0 -168
- data/features/filtering/inclusion_filters.feature +0 -105
- data/features/formatters/configurable_colors.feature +0 -31
- data/features/formatters/custom_formatter.feature +0 -36
- data/features/formatters/json_formatter.feature +0 -30
- data/features/formatters/text_formatter.feature +0 -46
- data/features/helper_methods/arbitrary_methods.feature +0 -40
- data/features/helper_methods/let.feature +0 -50
- data/features/helper_methods/modules.feature +0 -149
- data/features/hooks/around_hooks.feature +0 -343
- data/features/hooks/before_and_after_hooks.feature +0 -427
- data/features/hooks/filtering.feature +0 -234
- data/features/metadata/current_example.feature +0 -56
- data/features/metadata/described_class.feature +0 -17
- data/features/metadata/user_defined.feature +0 -113
- data/features/mock_framework_integration/use_any_framework.feature +0 -106
- data/features/mock_framework_integration/use_flexmock.feature +0 -96
- data/features/mock_framework_integration/use_mocha.feature +0 -97
- data/features/mock_framework_integration/use_rr.feature +0 -98
- data/features/mock_framework_integration/use_rspec.feature +0 -97
- data/features/pending/pending_examples.feature +0 -229
- data/features/spec_files/arbitrary_file_suffix.feature +0 -13
- data/features/step_definitions/additional_cli_steps.rb +0 -49
- data/features/subject/attribute_of_subject.feature +0 -124
- data/features/subject/explicit_subject.feature +0 -101
- data/features/subject/implicit_subject.feature +0 -63
- data/features/subject/one_liner_syntax.feature +0 -71
- data/features/support/env.rb +0 -14
- data/features/support/rubinius.rb +0 -6
- data/lib/autotest/discover.rb +0 -10
- data/lib/autotest/rspec2.rb +0 -77
- data/lib/rspec/core/backtrace_cleaner.rb +0 -46
- data/lib/rspec/core/backward_compatibility.rb +0 -55
- data/lib/rspec/core/caller_filter.rb +0 -60
- data/lib/rspec/core/command_line.rb +0 -47
- data/lib/rspec/core/deprecated_mutable_array_proxy.rb +0 -32
- data/lib/rspec/core/deprecation.rb +0 -26
- data/lib/rspec/core/drb_command_line.rb +0 -26
- data/lib/rspec/core/drb_options.rb +0 -87
- data/lib/rspec/core/extensions/instance_eval_with_args.rb +0 -44
- data/lib/rspec/core/extensions/kernel.rb +0 -9
- data/lib/rspec/core/extensions/module_eval_with_args.rb +0 -38
- data/lib/rspec/core/extensions/ordered.rb +0 -27
- data/lib/rspec/core/formatters/text_mate_formatter.rb +0 -34
- data/lib/rspec/core/metadata_hash_builder.rb +0 -97
- data/lib/rspec/core/mocking/with_absolutely_nothing.rb +0 -11
- data/lib/rspec/core/mocking/with_flexmock.rb +0 -27
- data/lib/rspec/core/mocking/with_rr.rb +0 -27
- data/lib/rspec/core/mocking/with_rspec.rb +0 -27
- data/lib/rspec/core/shared_example_group/collection.rb +0 -45
- data/spec/autotest/discover_spec.rb +0 -49
- data/spec/autotest/failed_results_re_spec.rb +0 -45
- data/spec/autotest/rspec_spec.rb +0 -133
- data/spec/command_line/order_spec.rb +0 -204
- data/spec/rspec/core/backtrace_cleaner_spec.rb +0 -68
- data/spec/rspec/core/caller_filter_spec.rb +0 -58
- data/spec/rspec/core/command_line_spec.rb +0 -127
- data/spec/rspec/core/command_line_spec_output.txt +0 -0
- data/spec/rspec/core/configuration_options_spec.rb +0 -417
- data/spec/rspec/core/configuration_spec.rb +0 -2072
- data/spec/rspec/core/deprecation_spec.rb +0 -27
- data/spec/rspec/core/deprecations_spec.rb +0 -59
- data/spec/rspec/core/drb_command_line_spec.rb +0 -102
- data/spec/rspec/core/drb_options_spec.rb +0 -193
- data/spec/rspec/core/dsl_spec.rb +0 -25
- data/spec/rspec/core/example_group_spec.rb +0 -1337
- data/spec/rspec/core/example_spec.rb +0 -502
- data/spec/rspec/core/filter_manager_spec.rb +0 -246
- data/spec/rspec/core/formatters/base_formatter_spec.rb +0 -108
- data/spec/rspec/core/formatters/base_text_formatter_spec.rb +0 -524
- data/spec/rspec/core/formatters/console_codes_spec.rb +0 -50
- data/spec/rspec/core/formatters/deprecation_formatter_spec.rb +0 -263
- data/spec/rspec/core/formatters/documentation_formatter_spec.rb +0 -89
- data/spec/rspec/core/formatters/helpers_spec.rb +0 -104
- data/spec/rspec/core/formatters/html_formatted.html +0 -397
- data/spec/rspec/core/formatters/html_formatter_spec.rb +0 -131
- data/spec/rspec/core/formatters/json_formatter_spec.rb +0 -115
- data/spec/rspec/core/formatters/progress_formatter_spec.rb +0 -30
- data/spec/rspec/core/formatters/snippet_extractor_spec.rb +0 -26
- data/spec/rspec/core/formatters/text_mate_formatted.html +0 -397
- data/spec/rspec/core/formatters/text_mate_formatter_spec.rb +0 -107
- data/spec/rspec/core/hooks_filtering_spec.rb +0 -227
- data/spec/rspec/core/hooks_spec.rb +0 -269
- data/spec/rspec/core/kernel_extensions_spec.rb +0 -9
- data/spec/rspec/core/memoized_helpers_spec.rb +0 -776
- data/spec/rspec/core/metadata_spec.rb +0 -514
- data/spec/rspec/core/option_parser_spec.rb +0 -297
- data/spec/rspec/core/pending_example_spec.rb +0 -260
- data/spec/rspec/core/pending_spec.rb +0 -27
- data/spec/rspec/core/project_initializer_spec.rb +0 -130
- data/spec/rspec/core/rake_task_spec.rb +0 -202
- data/spec/rspec/core/reporter_spec.rb +0 -167
- data/spec/rspec/core/resources/a_bar.rb +0 -0
- data/spec/rspec/core/resources/a_foo.rb +0 -0
- data/spec/rspec/core/resources/a_spec.rb +0 -1
- data/spec/rspec/core/resources/custom_example_group_runner.rb +0 -14
- data/spec/rspec/core/resources/formatter_specs.rb +0 -60
- data/spec/rspec/core/resources/utf8_encoded.rb +0 -8
- data/spec/rspec/core/rspec_matchers_spec.rb +0 -45
- data/spec/rspec/core/ruby_project_spec.rb +0 -26
- data/spec/rspec/core/runner_spec.rb +0 -82
- data/spec/rspec/core/shared_context_spec.rb +0 -114
- data/spec/rspec/core/shared_example_group/collection_spec.rb +0 -70
- data/spec/rspec/core/shared_example_group_spec.rb +0 -138
- data/spec/rspec/core/world_spec.rb +0 -142
- data/spec/rspec/core_spec.rb +0 -108
- data/spec/spec_helper.rb +0 -135
- data/spec/support/config_options_helper.rb +0 -15
- data/spec/support/helper_methods.rb +0 -55
- data/spec/support/in_sub_process.rb +0 -37
- data/spec/support/isolate_load_path_mutation.rb +0 -6
- data/spec/support/isolated_directory.rb +0 -10
- data/spec/support/isolated_home_directory.rb +0 -16
- data/spec/support/matchers.rb +0 -65
- data/spec/support/mathn_integration_support.rb +0 -12
- data/spec/support/sandboxed_mock_space.rb +0 -116
- data/spec/support/shared_example_groups.rb +0 -42
- data/spec/support/silence_dsl_deprecations.rb +0 -32
- data/spec/support/spec_files.rb +0 -44
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
module RSpec
|
|
2
2
|
module Core
|
|
3
|
+
# This module is included in {ExampleGroup}, making the methods
|
|
4
|
+
# available to be called from within example blocks.
|
|
5
|
+
#
|
|
6
|
+
# @see ClassMethods
|
|
3
7
|
module MemoizedHelpers
|
|
4
8
|
# @note `subject` was contributed by Joe Ferris to support the one-liner
|
|
5
9
|
# syntax embraced by shoulda matchers:
|
|
@@ -41,13 +45,13 @@ module RSpec
|
|
|
41
45
|
# end
|
|
42
46
|
#
|
|
43
47
|
# @note Because `subject` is designed to create state that is reset between
|
|
44
|
-
# each example, and `before(:
|
|
48
|
+
# each example, and `before(:context)` is designed to setup state that is
|
|
45
49
|
# shared across _all_ examples in an example group, `subject` is _not_
|
|
46
|
-
# intended to be used in a `before(:
|
|
47
|
-
# a warning when you reference a `subject` from `before(:all)` and we plan
|
|
48
|
-
# to have it raise an error in RSpec 3.
|
|
50
|
+
# intended to be used in a `before(:context)` hook.
|
|
49
51
|
#
|
|
50
52
|
# @see #should
|
|
53
|
+
# @see #should_not
|
|
54
|
+
# @see #is_expected
|
|
51
55
|
def subject
|
|
52
56
|
__memoized.fetch(:subject) do
|
|
53
57
|
__memoized[:subject] = begin
|
|
@@ -115,7 +119,7 @@ module RSpec
|
|
|
115
119
|
expect(subject)
|
|
116
120
|
end
|
|
117
121
|
|
|
118
|
-
|
|
122
|
+
private
|
|
119
123
|
|
|
120
124
|
# @private
|
|
121
125
|
def __memoized
|
|
@@ -123,99 +127,76 @@ module RSpec
|
|
|
123
127
|
end
|
|
124
128
|
|
|
125
129
|
# Used internally to customize the behavior of the
|
|
126
|
-
# memoized hash when used in a `before(:
|
|
130
|
+
# memoized hash when used in a `before(:context)` hook.
|
|
127
131
|
#
|
|
128
132
|
# @private
|
|
129
|
-
class
|
|
130
|
-
def self.
|
|
131
|
-
|
|
133
|
+
class ContextHookMemoizedHash
|
|
134
|
+
def self.isolate_for_context_hook(example_group_instance)
|
|
135
|
+
hash = self
|
|
132
136
|
|
|
133
|
-
example_group_instance.
|
|
134
|
-
@__memoized =
|
|
137
|
+
example_group_instance.instance_exec do
|
|
138
|
+
@__memoized = hash
|
|
135
139
|
|
|
136
140
|
begin
|
|
137
141
|
yield
|
|
138
142
|
ensure
|
|
139
|
-
@__memoized.preserve_accessed_lets
|
|
140
143
|
@__memoized = nil
|
|
141
144
|
end
|
|
142
145
|
end
|
|
143
146
|
end
|
|
144
147
|
|
|
145
|
-
def
|
|
146
|
-
@example_group_instance = example_group_instance
|
|
147
|
-
@hash = {}
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
def fetch(key, &block)
|
|
148
|
+
def self.fetch(key, &block)
|
|
151
149
|
description = if key == :subject
|
|
152
150
|
"subject"
|
|
153
151
|
else
|
|
154
152
|
"let declaration `#{key}`"
|
|
155
153
|
end
|
|
156
154
|
|
|
157
|
-
|
|
158
|
-
|
|
155
|
+
raise <<-EOS
|
|
156
|
+
#{description} accessed in #{article} #{hook_expression} hook at:
|
|
159
157
|
#{CallerFilter.first_non_rspec_line}
|
|
160
158
|
|
|
161
159
|
`let` and `subject` declarations are not intended to be called
|
|
162
160
|
in #{article} #{hook_expression} hook, as they exist to define state that
|
|
163
161
|
is reset between each example, while #{hook_expression} exists to
|
|
164
162
|
#{hook_intention}.
|
|
165
|
-
|
|
166
|
-
This is deprecated behavior that will not be supported in RSpec 3.
|
|
167
163
|
EOS
|
|
168
|
-
@hash.fetch(key, &block)
|
|
169
|
-
end
|
|
170
|
-
|
|
171
|
-
def []=(key, value)
|
|
172
|
-
@hash[key] = value
|
|
173
|
-
end
|
|
174
|
-
|
|
175
|
-
def preserve_accessed_lets
|
|
176
|
-
hash = @hash
|
|
177
|
-
|
|
178
|
-
@example_group_instance.class.class_eval do
|
|
179
|
-
hash.each do |key, value|
|
|
180
|
-
undef_method(key) if method_defined?(key)
|
|
181
|
-
define_method(key) { value }
|
|
182
|
-
end
|
|
183
|
-
end
|
|
184
164
|
end
|
|
185
165
|
|
|
166
|
+
# @private
|
|
186
167
|
class Before < self
|
|
187
|
-
def hook_expression
|
|
188
|
-
"`before(:
|
|
168
|
+
def self.hook_expression
|
|
169
|
+
"`before(:context)`"
|
|
189
170
|
end
|
|
190
171
|
|
|
191
|
-
def article
|
|
172
|
+
def self.article
|
|
192
173
|
"a"
|
|
193
174
|
end
|
|
194
175
|
|
|
195
|
-
def hook_intention
|
|
176
|
+
def self.hook_intention
|
|
196
177
|
"define state that is shared across examples in an example group"
|
|
197
178
|
end
|
|
198
179
|
end
|
|
199
180
|
|
|
181
|
+
# @private
|
|
200
182
|
class After < self
|
|
201
|
-
def hook_expression
|
|
202
|
-
"`after(:
|
|
183
|
+
def self.hook_expression
|
|
184
|
+
"`after(:context)`"
|
|
203
185
|
end
|
|
204
186
|
|
|
205
|
-
def article
|
|
187
|
+
def self.article
|
|
206
188
|
"an"
|
|
207
189
|
end
|
|
208
190
|
|
|
209
|
-
def hook_intention
|
|
191
|
+
def self.hook_intention
|
|
210
192
|
"cleanup state that is shared across examples in an example group"
|
|
211
193
|
end
|
|
212
194
|
end
|
|
213
195
|
end
|
|
214
196
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
197
|
+
# This module is extended onto {ExampleGroup}, making the methods
|
|
198
|
+
# available to be called from within example group blocks.
|
|
199
|
+
# You can think of them as being analagous to class macros.
|
|
219
200
|
module ClassMethods
|
|
220
201
|
# Generates a method whose return value is memoized after the first
|
|
221
202
|
# call. Useful for reducing duplication between examples that assign
|
|
@@ -230,11 +211,9 @@ EOS
|
|
|
230
211
|
# though we have yet to see this in practice. You've been warned.
|
|
231
212
|
#
|
|
232
213
|
# @note Because `let` is designed to create state that is reset between
|
|
233
|
-
# each example, and `before(:
|
|
214
|
+
# each example, and `before(:context)` is designed to setup state that is
|
|
234
215
|
# shared across _all_ examples in an example group, `let` is _not_
|
|
235
|
-
# intended to be used in a `before(:
|
|
236
|
-
# a warning when you reference a `let` from `before(:all)` and we plan
|
|
237
|
-
# to have it raise an error in RSpec 3.
|
|
216
|
+
# intended to be used in a `before(:context)` hook.
|
|
238
217
|
#
|
|
239
218
|
# @example
|
|
240
219
|
#
|
|
@@ -253,7 +232,7 @@ EOS
|
|
|
253
232
|
# We have to pass the block directly to `define_method` to
|
|
254
233
|
# allow it to use method constructs like `super` and `return`.
|
|
255
234
|
raise "#let or #subject called without a block" if block.nil?
|
|
256
|
-
MemoizedHelpers.module_for(self).
|
|
235
|
+
MemoizedHelpers.module_for(self).__send__(:define_method, name, &block)
|
|
257
236
|
|
|
258
237
|
# Apply the memoization. The method has been defined in an ancestor
|
|
259
238
|
# module so we can use `super` here to get the value.
|
|
@@ -289,7 +268,7 @@ EOS
|
|
|
289
268
|
# end
|
|
290
269
|
#
|
|
291
270
|
# describe Thing do
|
|
292
|
-
# after(:
|
|
271
|
+
# after(:example) { Thing.reset_count }
|
|
293
272
|
#
|
|
294
273
|
# context "using let" do
|
|
295
274
|
# let(:thing) { Thing.new }
|
|
@@ -331,7 +310,7 @@ EOS
|
|
|
331
310
|
# implicitly in one-liners and explicitly using an intention revealing
|
|
332
311
|
# name.
|
|
333
312
|
#
|
|
334
|
-
# @param [String,Symbol]
|
|
313
|
+
# @param name [String,Symbol] used to define an accessor with an
|
|
335
314
|
# intention revealing name
|
|
336
315
|
# @param block defines the value to be returned by `subject` in examples
|
|
337
316
|
#
|
|
@@ -352,12 +331,14 @@ EOS
|
|
|
352
331
|
# end
|
|
353
332
|
#
|
|
354
333
|
# @see MemoizedHelpers#should
|
|
334
|
+
# @see MemoizedHelpers#should_not
|
|
335
|
+
# @see MemoizedHelpers#is_expected
|
|
355
336
|
def subject(name=nil, &block)
|
|
356
337
|
if name
|
|
357
338
|
let(name, &block)
|
|
358
339
|
alias_method :subject, name
|
|
359
340
|
|
|
360
|
-
self::NamedSubjectPreventSuper.
|
|
341
|
+
self::NamedSubjectPreventSuper.__send__(:define_method, name) do
|
|
361
342
|
raise NotImplementedError, "`super` in named subjects is not supported"
|
|
362
343
|
end
|
|
363
344
|
else
|
|
@@ -390,7 +371,7 @@ EOS
|
|
|
390
371
|
# end
|
|
391
372
|
#
|
|
392
373
|
# describe Thing do
|
|
393
|
-
# after(:
|
|
374
|
+
# after(:example) { Thing.reset_count }
|
|
394
375
|
#
|
|
395
376
|
# context "using subject" do
|
|
396
377
|
# subject { Thing.new }
|
|
@@ -422,101 +403,9 @@ EOS
|
|
|
422
403
|
subject(name, &block)
|
|
423
404
|
before { subject }
|
|
424
405
|
end
|
|
425
|
-
|
|
426
|
-
# Creates a nested example group named by the submitted `attribute`,
|
|
427
|
-
# and then generates an example using the submitted block.
|
|
428
|
-
#
|
|
429
|
-
# @example
|
|
430
|
-
#
|
|
431
|
-
# # This ...
|
|
432
|
-
# describe Array do
|
|
433
|
-
# its(:size) { should eq(0) }
|
|
434
|
-
# end
|
|
435
|
-
#
|
|
436
|
-
# # ... generates the same runtime structure as this:
|
|
437
|
-
# describe Array do
|
|
438
|
-
# describe "size" do
|
|
439
|
-
# it "should eq(0)" do
|
|
440
|
-
# subject.size.should eq(0)
|
|
441
|
-
# end
|
|
442
|
-
# end
|
|
443
|
-
# end
|
|
444
|
-
#
|
|
445
|
-
# The attribute can be a `Symbol` or a `String`. Given a `String`
|
|
446
|
-
# with dots, the result is as though you concatenated that `String`
|
|
447
|
-
# onto the subject in an expression.
|
|
448
|
-
#
|
|
449
|
-
# @example
|
|
450
|
-
#
|
|
451
|
-
# describe Person do
|
|
452
|
-
# subject do
|
|
453
|
-
# Person.new.tap do |person|
|
|
454
|
-
# person.phone_numbers << "555-1212"
|
|
455
|
-
# end
|
|
456
|
-
# end
|
|
457
|
-
#
|
|
458
|
-
# its("phone_numbers.first") { should eq("555-1212") }
|
|
459
|
-
# end
|
|
460
|
-
#
|
|
461
|
-
# When the subject is a `Hash`, you can refer to the Hash keys by
|
|
462
|
-
# specifying a `Symbol` or `String` in an array.
|
|
463
|
-
#
|
|
464
|
-
# @example
|
|
465
|
-
#
|
|
466
|
-
# describe "a configuration Hash" do
|
|
467
|
-
# subject do
|
|
468
|
-
# { :max_users => 3,
|
|
469
|
-
# 'admin' => :all_permissions }
|
|
470
|
-
# end
|
|
471
|
-
#
|
|
472
|
-
# its([:max_users]) { should eq(3) }
|
|
473
|
-
# its(['admin']) { should eq(:all_permissions) }
|
|
474
|
-
#
|
|
475
|
-
# # You can still access to its regular methods this way:
|
|
476
|
-
# its(:keys) { should include(:max_users) }
|
|
477
|
-
# its(:count) { should eq(2) }
|
|
478
|
-
# end
|
|
479
|
-
#
|
|
480
|
-
# Note that this method does not modify `subject` in any way, so if you
|
|
481
|
-
# refer to `subject` in `let` or `before` blocks, you're still
|
|
482
|
-
# referring to the outer subject.
|
|
483
|
-
#
|
|
484
|
-
# @example
|
|
485
|
-
#
|
|
486
|
-
# describe Person do
|
|
487
|
-
# subject { Person.new }
|
|
488
|
-
# before { subject.age = 25 }
|
|
489
|
-
# its(:age) { should eq(25) }
|
|
490
|
-
# end
|
|
491
|
-
def its(attribute, &block)
|
|
492
|
-
RSpec.deprecate("Use of rspec-core's `its` method", :replacement => 'the rspec-its gem')
|
|
493
|
-
|
|
494
|
-
describe(attribute.to_s) do
|
|
495
|
-
if Array === attribute
|
|
496
|
-
let(:__its_subject) { subject[*attribute] }
|
|
497
|
-
else
|
|
498
|
-
let(:__its_subject) do
|
|
499
|
-
attribute_chain = attribute.to_s.split('.')
|
|
500
|
-
attribute_chain.inject(subject) do |inner_subject, attr|
|
|
501
|
-
inner_subject.send(attr)
|
|
502
|
-
end
|
|
503
|
-
end
|
|
504
|
-
end
|
|
505
|
-
|
|
506
|
-
def should(matcher=nil, message=nil)
|
|
507
|
-
RSpec::Expectations::PositiveExpectationHandler.handle_matcher(__its_subject, matcher, message)
|
|
508
|
-
end
|
|
509
|
-
|
|
510
|
-
def should_not(matcher=nil, message=nil)
|
|
511
|
-
RSpec::Expectations::NegativeExpectationHandler.handle_matcher(__its_subject, matcher, message)
|
|
512
|
-
end
|
|
513
|
-
|
|
514
|
-
example(&block)
|
|
515
|
-
end
|
|
516
|
-
end
|
|
517
406
|
end
|
|
518
407
|
|
|
519
|
-
# @
|
|
408
|
+
# @private
|
|
520
409
|
#
|
|
521
410
|
# Gets the LetDefinitions module. The module is mixed into
|
|
522
411
|
# the example group and is used to hold all let definitions.
|
|
@@ -541,13 +430,13 @@ EOS
|
|
|
541
430
|
end
|
|
542
431
|
end
|
|
543
432
|
|
|
544
|
-
# @
|
|
433
|
+
# @private
|
|
545
434
|
def self.define_helpers_on(example_group)
|
|
546
|
-
example_group.
|
|
435
|
+
example_group.__send__(:include, module_for(example_group))
|
|
547
436
|
end
|
|
548
437
|
|
|
549
438
|
if Module.method(:const_defined?).arity == 1 # for 1.8
|
|
550
|
-
# @
|
|
439
|
+
# @private
|
|
551
440
|
#
|
|
552
441
|
# Gets the named constant or yields.
|
|
553
442
|
# On 1.8, const_defined? / const_get do not take into
|
|
@@ -560,7 +449,7 @@ EOS
|
|
|
560
449
|
end
|
|
561
450
|
end
|
|
562
451
|
else
|
|
563
|
-
# @
|
|
452
|
+
# @private
|
|
564
453
|
#
|
|
565
454
|
# Gets the named constant or yields.
|
|
566
455
|
# On 1.9, const_defined? / const_get take into account the
|