rspec-core 2.11.1 → 3.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data/.document +1 -1
- data/.yardopts +3 -1
- data/Changelog.md +1814 -29
- data/{License.txt → LICENSE.md} +6 -4
- data/README.md +197 -48
- data/exe/rspec +2 -23
- data/lib/rspec/autorun.rb +1 -0
- data/lib/rspec/core/backtrace_formatter.rb +65 -0
- data/lib/rspec/core/bisect/coordinator.rb +62 -0
- data/lib/rspec/core/bisect/example_minimizer.rb +173 -0
- data/lib/rspec/core/bisect/fork_runner.rb +138 -0
- data/lib/rspec/core/bisect/server.rb +61 -0
- data/lib/rspec/core/bisect/shell_command.rb +126 -0
- data/lib/rspec/core/bisect/shell_runner.rb +73 -0
- data/lib/rspec/core/bisect/utilities.rb +69 -0
- data/lib/rspec/core/configuration.rb +1846 -407
- data/lib/rspec/core/configuration_options.rb +154 -50
- data/lib/rspec/core/did_you_mean.rb +46 -0
- data/lib/rspec/core/drb.rb +120 -0
- data/lib/rspec/core/dsl.rb +90 -18
- data/lib/rspec/core/example.rb +488 -152
- data/lib/rspec/core/example_group.rb +733 -294
- data/lib/rspec/core/example_status_persister.rb +235 -0
- data/lib/rspec/core/filter_manager.rb +175 -147
- data/lib/rspec/core/flat_map.rb +20 -0
- data/lib/rspec/core/formatters/base_bisect_formatter.rb +45 -0
- data/lib/rspec/core/formatters/base_formatter.rb +32 -130
- data/lib/rspec/core/formatters/base_text_formatter.rb +62 -190
- data/lib/rspec/core/formatters/bisect_drb_formatter.rb +29 -0
- data/lib/rspec/core/formatters/bisect_progress_formatter.rb +157 -0
- data/lib/rspec/core/formatters/console_codes.rb +76 -0
- data/lib/rspec/core/formatters/deprecation_formatter.rb +223 -0
- data/lib/rspec/core/formatters/documentation_formatter.rb +62 -27
- data/lib/rspec/core/formatters/exception_presenter.rb +521 -0
- data/lib/rspec/core/formatters/failure_list_formatter.rb +23 -0
- data/lib/rspec/core/formatters/fallback_message_formatter.rb +28 -0
- data/lib/rspec/core/formatters/helpers.rb +93 -14
- data/lib/rspec/core/formatters/html_formatter.rb +104 -415
- data/lib/rspec/core/formatters/html_printer.rb +414 -0
- data/lib/rspec/core/formatters/html_snippet_extractor.rb +120 -0
- data/lib/rspec/core/formatters/json_formatter.rb +102 -0
- data/lib/rspec/core/formatters/profile_formatter.rb +68 -0
- data/lib/rspec/core/formatters/progress_formatter.rb +12 -15
- data/lib/rspec/core/formatters/protocol.rb +182 -0
- data/lib/rspec/core/formatters/snippet_extractor.rb +115 -39
- data/lib/rspec/core/formatters/syntax_highlighter.rb +91 -0
- data/lib/rspec/core/formatters.rb +279 -0
- data/lib/rspec/core/hooks.rb +451 -300
- data/lib/rspec/core/invocations.rb +87 -0
- data/lib/rspec/core/memoized_helpers.rb +580 -0
- data/lib/rspec/core/metadata.rb +395 -173
- data/lib/rspec/core/metadata_filter.rb +255 -0
- data/lib/rspec/core/minitest_assertions_adapter.rb +31 -0
- data/lib/rspec/core/mocking_adapters/flexmock.rb +31 -0
- data/lib/rspec/core/mocking_adapters/mocha.rb +57 -0
- data/lib/rspec/core/mocking_adapters/null.rb +14 -0
- data/lib/rspec/core/mocking_adapters/rr.rb +31 -0
- data/lib/rspec/core/mocking_adapters/rspec.rb +32 -0
- data/lib/rspec/core/notifications.rb +521 -0
- data/lib/rspec/core/option_parser.rb +208 -64
- data/lib/rspec/core/ordering.rb +169 -0
- data/lib/rspec/core/output_wrapper.rb +29 -0
- data/lib/rspec/core/pending.rb +115 -59
- data/lib/rspec/core/profiler.rb +34 -0
- data/lib/rspec/core/project_initializer/.rspec +1 -0
- data/lib/rspec/core/project_initializer/spec/spec_helper.rb +98 -0
- data/lib/rspec/core/project_initializer.rb +26 -65
- data/lib/rspec/core/rake_task.rb +140 -131
- data/lib/rspec/core/reporter.rb +207 -44
- data/lib/rspec/core/ruby_project.rb +15 -6
- data/lib/rspec/core/runner.rb +180 -44
- data/lib/rspec/core/sandbox.rb +37 -0
- data/lib/rspec/core/set.rb +54 -0
- data/lib/rspec/core/shared_context.rb +25 -19
- data/lib/rspec/core/shared_example_group.rb +229 -54
- data/lib/rspec/core/shell_escape.rb +49 -0
- data/lib/rspec/core/test_unit_assertions_adapter.rb +30 -0
- data/lib/rspec/core/version.rb +3 -1
- data/lib/rspec/core/warnings.rb +40 -0
- data/lib/rspec/core/world.rb +208 -49
- data/lib/rspec/core.rb +166 -80
- data.tar.gz.sig +0 -0
- metadata +230 -445
- metadata.gz.sig +0 -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 -101
- data/features/command_line/exit_status.feature +0 -83
- data/features/command_line/format_option.feature +0 -81
- 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 -58
- data/features/command_line/order.feature +0 -29
- data/features/command_line/pattern_option.feature +0 -31
- data/features/command_line/rake_task.feature +0 -68
- data/features/command_line/ruby.feature +0 -22
- data/features/command_line/tag.feature +0 -91
- data/features/configuration/alias_example_to.feature +0 -48
- data/features/configuration/custom_settings.feature +0 -84
- data/features/configuration/default_path.feature +0 -38
- data/features/configuration/fail_fast.feature +0 -77
- data/features/configuration/read_options_from_file.feature +0 -87
- 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 -204
- data/features/expectation_framework_integration/configure_expectation_framework.feature +0 -102
- data/features/filtering/exclusion_filters.feature +0 -139
- data/features/filtering/if_and_unless.feature +0 -168
- data/features/filtering/inclusion_filters.feature +0 -105
- data/features/filtering/run_all_when_everything_filtered.feature +0 -46
- data/features/formatters/custom_formatter.feature +0 -36
- 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 -423
- data/features/hooks/filtering.feature +0 -234
- data/features/metadata/current_example.feature +0 -17
- 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 -30
- data/features/subject/attribute_of_subject.feature +0 -124
- data/features/subject/explicit_subject.feature +0 -82
- data/features/subject/implicit_receiver.feature +0 -29
- data/features/subject/implicit_subject.feature +0 -63
- data/features/support/env.rb +0 -12
- data/lib/autotest/discover.rb +0 -1
- data/lib/autotest/rspec2.rb +0 -73
- data/lib/rspec/core/backward_compatibility.rb +0 -65
- data/lib/rspec/core/command_line.rb +0 -36
- data/lib/rspec/core/deprecation.rb +0 -36
- 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 -21
- data/lib/rspec/core/extensions.rb +0 -4
- data/lib/rspec/core/formatters/text_mate_formatter.rb +0 -34
- data/lib/rspec/core/let.rb +0 -110
- data/lib/rspec/core/load_path.rb +0 -3
- 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_mocha.rb +0 -29
- data/lib/rspec/core/mocking/with_rr.rb +0 -27
- data/lib/rspec/core/mocking/with_rspec.rb +0 -23
- data/lib/rspec/core/subject.rb +0 -219
- data/spec/autotest/discover_spec.rb +0 -19
- data/spec/autotest/failed_results_re_spec.rb +0 -45
- data/spec/autotest/rspec_spec.rb +0 -123
- data/spec/command_line/order_spec.rb +0 -137
- data/spec/rspec/core/command_line_spec.rb +0 -108
- data/spec/rspec/core/command_line_spec_output.txt +0 -0
- data/spec/rspec/core/configuration_options_spec.rb +0 -377
- data/spec/rspec/core/configuration_spec.rb +0 -1196
- data/spec/rspec/core/deprecations_spec.rb +0 -66
- data/spec/rspec/core/drb_command_line_spec.rb +0 -108
- data/spec/rspec/core/drb_options_spec.rb +0 -180
- data/spec/rspec/core/dsl_spec.rb +0 -17
- data/spec/rspec/core/example_group_spec.rb +0 -1098
- data/spec/rspec/core/example_spec.rb +0 -370
- data/spec/rspec/core/filter_manager_spec.rb +0 -256
- data/spec/rspec/core/formatters/base_formatter_spec.rb +0 -80
- data/spec/rspec/core/formatters/base_text_formatter_spec.rb +0 -363
- data/spec/rspec/core/formatters/documentation_formatter_spec.rb +0 -88
- data/spec/rspec/core/formatters/helpers_spec.rb +0 -66
- data/spec/rspec/core/formatters/html_formatted-1.8.7-jruby.html +0 -410
- data/spec/rspec/core/formatters/html_formatted-1.8.7.html +0 -409
- data/spec/rspec/core/formatters/html_formatted-1.9.2.html +0 -416
- data/spec/rspec/core/formatters/html_formatted-1.9.3.html +0 -416
- data/spec/rspec/core/formatters/html_formatter_spec.rb +0 -82
- data/spec/rspec/core/formatters/progress_formatter_spec.rb +0 -30
- data/spec/rspec/core/formatters/snippet_extractor_spec.rb +0 -18
- data/spec/rspec/core/formatters/text_mate_formatted-1.8.7-jruby.html +0 -410
- data/spec/rspec/core/formatters/text_mate_formatted-1.8.7.html +0 -409
- data/spec/rspec/core/formatters/text_mate_formatted-1.9.2.html +0 -416
- data/spec/rspec/core/formatters/text_mate_formatted-1.9.3.html +0 -416
- data/spec/rspec/core/formatters/text_mate_formatter_spec.rb +0 -83
- data/spec/rspec/core/hooks_filtering_spec.rb +0 -227
- data/spec/rspec/core/hooks_spec.rb +0 -250
- data/spec/rspec/core/kernel_extensions_spec.rb +0 -9
- data/spec/rspec/core/let_spec.rb +0 -55
- data/spec/rspec/core/metadata_spec.rb +0 -447
- data/spec/rspec/core/option_parser_spec.rb +0 -166
- data/spec/rspec/core/pending_example_spec.rb +0 -220
- data/spec/rspec/core/project_initializer_spec.rb +0 -130
- data/spec/rspec/core/rake_task_spec.rb +0 -138
- data/spec/rspec/core/reporter_spec.rb +0 -103
- 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 -24
- data/spec/rspec/core/runner_spec.rb +0 -81
- data/spec/rspec/core/shared_context_spec.rb +0 -67
- data/spec/rspec/core/shared_example_group_spec.rb +0 -84
- data/spec/rspec/core/subject_spec.rb +0 -244
- data/spec/rspec/core/world_spec.rb +0 -144
- data/spec/rspec/core_spec.rb +0 -35
- data/spec/spec_helper.rb +0 -98
- data/spec/support/config_options_helper.rb +0 -24
- data/spec/support/helper_methods.rb +0 -5
- data/spec/support/matchers.rb +0 -65
- data/spec/support/shared_example_groups.rb +0 -41
- data/spec/support/spec_files.rb +0 -44
@@ -1,96 +1,271 @@
|
|
1
|
+
RSpec::Support.require_rspec_support "with_keywords_when_needed"
|
2
|
+
|
1
3
|
module RSpec
|
2
4
|
module Core
|
5
|
+
# Represents some functionality that is shared with multiple example groups.
|
6
|
+
# The functionality is defined by the provided block, which is lazily
|
7
|
+
# eval'd when the `SharedExampleGroupModule` instance is included in an example
|
8
|
+
# group.
|
9
|
+
class SharedExampleGroupModule < Module
|
10
|
+
# @private
|
11
|
+
attr_reader :definition
|
12
|
+
|
13
|
+
def initialize(description, definition, metadata)
|
14
|
+
@description = description
|
15
|
+
@definition = definition
|
16
|
+
@metadata = metadata
|
17
|
+
end
|
18
|
+
|
19
|
+
# Provides a human-readable representation of this module.
|
20
|
+
def inspect
|
21
|
+
"#<#{self.class.name} #{@description.inspect}>"
|
22
|
+
end
|
23
|
+
alias to_s inspect
|
24
|
+
|
25
|
+
# Ruby callback for when a module is included in another module is class.
|
26
|
+
# Our definition evaluates the shared group block in the context of the
|
27
|
+
# including example group.
|
28
|
+
def included(klass)
|
29
|
+
inclusion_line = klass.metadata[:location]
|
30
|
+
include_in klass, inclusion_line, [], nil
|
31
|
+
end
|
32
|
+
|
33
|
+
# @private
|
34
|
+
def include_in(klass, inclusion_line, args, customization_block)
|
35
|
+
klass.update_inherited_metadata(@metadata) unless @metadata.empty?
|
36
|
+
|
37
|
+
SharedExampleGroupInclusionStackFrame.with_frame(@description, inclusion_line) do
|
38
|
+
RSpec::Support::WithKeywordsWhenNeeded.class_exec(klass, *args, &@definition)
|
39
|
+
klass.class_exec(&customization_block) if customization_block
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# Shared example groups let you define common context and/or common
|
45
|
+
# examples that you wish to use in multiple example groups.
|
46
|
+
#
|
47
|
+
# When defined, the shared group block is stored for later evaluation.
|
48
|
+
# It can later be included in an example group either explicitly
|
49
|
+
# (using `include_examples`, `include_context` or `it_behaves_like`)
|
50
|
+
# or implicitly (via matching metadata).
|
51
|
+
#
|
52
|
+
# Named shared example groups are scoped based on where they are
|
53
|
+
# defined. Shared groups defined in an example group are available
|
54
|
+
# for inclusion in that example group or any child example groups,
|
55
|
+
# but not in any parent or sibling example groups. Shared example
|
56
|
+
# groups defined at the top level can be included from any example group.
|
3
57
|
module SharedExampleGroup
|
4
58
|
# @overload shared_examples(name, &block)
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
59
|
+
# @param name [String, Symbol, Module] identifer to use when looking up
|
60
|
+
# this shared group
|
61
|
+
# @param block The block to be eval'd
|
62
|
+
# @overload shared_examples(name, metadata, &block)
|
63
|
+
# @param name [String, Symbol, Module] identifer to use when looking up
|
64
|
+
# this shared group
|
65
|
+
# @param metadata [Array<Symbol>, Hash] metadata to attach to this
|
66
|
+
# group; any example group or example with matching metadata will
|
67
|
+
# automatically include this shared example group.
|
68
|
+
# @param block The block to be eval'd
|
10
69
|
#
|
11
|
-
#
|
12
|
-
#
|
70
|
+
# Stores the block for later use. The block will be evaluated
|
71
|
+
# in the context of an example group via `include_examples`,
|
72
|
+
# `include_context`, or `it_behaves_like`.
|
13
73
|
#
|
14
74
|
# @example
|
15
|
-
#
|
16
75
|
# shared_examples "auditable" do
|
17
76
|
# it "stores an audit record on save!" do
|
18
|
-
#
|
77
|
+
# expect { auditable.save! }.to change(Audit, :count).by(1)
|
19
78
|
# end
|
20
79
|
# end
|
21
80
|
#
|
22
|
-
#
|
81
|
+
# RSpec.describe Account do
|
23
82
|
# it_behaves_like "auditable" do
|
24
|
-
#
|
83
|
+
# let(:auditable) { Account.new }
|
25
84
|
# end
|
26
85
|
# end
|
27
86
|
#
|
28
87
|
# @see ExampleGroup.it_behaves_like
|
29
88
|
# @see ExampleGroup.include_examples
|
30
89
|
# @see ExampleGroup.include_context
|
31
|
-
def shared_examples *args, &block
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
90
|
+
def shared_examples(name, *args, &block)
|
91
|
+
top_level = self == ExampleGroup
|
92
|
+
if top_level && RSpec::Support.thread_local_data[:in_example_group]
|
93
|
+
raise "Creating isolated shared examples from within a context is " \
|
94
|
+
"not allowed. Remove `RSpec.` prefix or move this to a " \
|
95
|
+
"top-level scope."
|
36
96
|
end
|
37
97
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
98
|
+
RSpec.world.shared_example_group_registry.add(self, name, *args, &block)
|
99
|
+
end
|
100
|
+
alias shared_context shared_examples
|
101
|
+
alias shared_examples_for shared_examples
|
102
|
+
|
103
|
+
# @api private
|
104
|
+
#
|
105
|
+
# Shared examples top level DSL.
|
106
|
+
module TopLevelDSL
|
107
|
+
# @private
|
108
|
+
def self.definitions
|
109
|
+
proc do
|
110
|
+
def shared_examples(name, *args, &block)
|
111
|
+
RSpec.world.shared_example_group_registry.add(:main, name, *args, &block)
|
112
|
+
end
|
113
|
+
alias shared_context shared_examples
|
114
|
+
alias shared_examples_for shared_examples
|
42
115
|
end
|
43
|
-
RSpec.configuration.extend mod, *args
|
44
116
|
end
|
45
|
-
end
|
46
117
|
|
47
|
-
|
48
|
-
|
49
|
-
|
118
|
+
# @private
|
119
|
+
def self.exposed_globally?
|
120
|
+
@exposed_globally ||= false
|
121
|
+
end
|
122
|
+
|
123
|
+
# @api private
|
124
|
+
#
|
125
|
+
# Adds the top level DSL methods to Module and the top level binding.
|
126
|
+
def self.expose_globally!
|
127
|
+
return if exposed_globally?
|
128
|
+
Core::DSL.change_global_dsl(&definitions)
|
129
|
+
@exposed_globally = true
|
130
|
+
end
|
131
|
+
|
132
|
+
# @api private
|
133
|
+
#
|
134
|
+
# Removes the top level DSL methods to Module and the top level binding.
|
135
|
+
def self.remove_globally!
|
136
|
+
return unless exposed_globally?
|
137
|
+
|
138
|
+
Core::DSL.change_global_dsl do
|
139
|
+
undef shared_examples
|
140
|
+
undef shared_context
|
141
|
+
undef shared_examples_for
|
142
|
+
end
|
50
143
|
|
51
|
-
|
52
|
-
if Object.const_defined?(name)
|
53
|
-
mod = Object.const_get(name)
|
54
|
-
raise_name_error unless mod.created_from_caller(caller)
|
144
|
+
@exposed_globally = false
|
55
145
|
end
|
146
|
+
end
|
147
|
+
|
148
|
+
# @private
|
149
|
+
class Registry
|
150
|
+
def add(context, name, *metadata_args, &block)
|
151
|
+
unless block
|
152
|
+
RSpec.warning "Shared example group #{name} was defined without a "\
|
153
|
+
"block and will have no effect. Please define a "\
|
154
|
+
"block or remove the definition."
|
155
|
+
end
|
56
156
|
|
57
|
-
|
58
|
-
|
59
|
-
|
157
|
+
if RSpec.configuration.shared_context_metadata_behavior == :trigger_inclusion
|
158
|
+
return legacy_add(context, name, *metadata_args, &block)
|
159
|
+
end
|
60
160
|
|
61
|
-
|
62
|
-
|
161
|
+
unless valid_name?(name)
|
162
|
+
raise ArgumentError, "Shared example group names can only be a string, " \
|
163
|
+
"symbol or module but got: #{name.inspect}"
|
63
164
|
end
|
64
165
|
|
65
|
-
|
66
|
-
|
67
|
-
|
166
|
+
ensure_block_has_source_location(block) { CallerFilter.first_non_rspec_line }
|
167
|
+
warn_if_key_taken context, name, block
|
168
|
+
|
169
|
+
metadata = Metadata.build_hash_from(metadata_args)
|
170
|
+
shared_module = SharedExampleGroupModule.new(name, block, metadata)
|
171
|
+
shared_example_groups[context][name] = shared_module
|
172
|
+
end
|
173
|
+
|
174
|
+
def find(lookup_contexts, name)
|
175
|
+
lookup_contexts.each do |context|
|
176
|
+
found = shared_example_groups[context][name]
|
177
|
+
return found if found
|
68
178
|
end
|
179
|
+
|
180
|
+
shared_example_groups[:main][name]
|
69
181
|
end
|
70
182
|
|
71
|
-
|
72
|
-
RSpec.world.shared_example_groups[shared_const] = block
|
73
|
-
end
|
183
|
+
private
|
74
184
|
|
75
|
-
|
185
|
+
# TODO: remove this in RSpec 4. This exists only to support
|
186
|
+
# `config.shared_context_metadata_behavior == :trigger_inclusion`,
|
187
|
+
# the legacy behavior of shared context metadata, which we do
|
188
|
+
# not want to support in RSpec 4.
|
189
|
+
def legacy_add(context, name, *metadata_args, &block)
|
190
|
+
ensure_block_has_source_location(block) { CallerFilter.first_non_rspec_line }
|
191
|
+
shared_module = SharedExampleGroupModule.new(name, block, {})
|
76
192
|
|
77
|
-
|
78
|
-
|
79
|
-
|
193
|
+
if valid_name?(name)
|
194
|
+
warn_if_key_taken context, name, block
|
195
|
+
shared_example_groups[context][name] = shared_module
|
196
|
+
else
|
197
|
+
metadata_args.unshift name
|
198
|
+
end
|
80
199
|
|
81
|
-
|
82
|
-
|
83
|
-
|
200
|
+
return if metadata_args.empty?
|
201
|
+
RSpec.configuration.include shared_module, *metadata_args
|
202
|
+
end
|
84
203
|
|
85
|
-
|
86
|
-
|
87
|
-
|
204
|
+
def shared_example_groups
|
205
|
+
@shared_example_groups ||= Hash.new { |hash, context| hash[context] = {} }
|
206
|
+
end
|
207
|
+
|
208
|
+
def valid_name?(candidate)
|
209
|
+
case candidate
|
210
|
+
when String, Symbol, Module then true
|
211
|
+
else false
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
def warn_if_key_taken(context, key, new_block)
|
216
|
+
existing_module = shared_example_groups[context][key]
|
217
|
+
return unless existing_module
|
218
|
+
|
219
|
+
old_definition_location = formatted_location existing_module.definition
|
220
|
+
new_definition_location = formatted_location new_block
|
221
|
+
loaded_spec_files = RSpec.configuration.loaded_spec_files
|
222
|
+
|
223
|
+
if loaded_spec_files.include?(new_definition_location) && old_definition_location == new_definition_location
|
224
|
+
RSpec.warn_with <<-WARNING.gsub(/^ +\|/, ''), :call_site => nil
|
225
|
+
|WARNING: Your shared example group, '#{key}', defined at:
|
226
|
+
| #{old_definition_location}
|
227
|
+
|was automatically loaded by RSpec because the file name
|
228
|
+
|matches the configured autoloading pattern (#{RSpec.configuration.pattern}),
|
229
|
+
|and is also being required from somewhere else. To fix this
|
230
|
+
|warning, either rename the file to not match the pattern, or
|
231
|
+
|do not explicitly require the file.
|
232
|
+
WARNING
|
233
|
+
else
|
234
|
+
RSpec.warn_with <<-WARNING.gsub(/^ +\|/, ''), :call_site => nil
|
235
|
+
|WARNING: Shared example group '#{key}' has been previously defined at:
|
236
|
+
| #{old_definition_location}
|
237
|
+
|...and you are now defining it at:
|
238
|
+
| #{new_definition_location}
|
239
|
+
|The new definition will overwrite the original one.
|
240
|
+
WARNING
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
if RUBY_VERSION.to_f >= 1.9
|
245
|
+
def formatted_location(block)
|
246
|
+
block.source_location.join(":")
|
247
|
+
end
|
248
|
+
else # 1.8.7
|
249
|
+
# :nocov:
|
250
|
+
def formatted_location(block)
|
251
|
+
block.source_location.join(":").gsub(/:in.*$/, '')
|
252
|
+
end
|
253
|
+
# :nocov:
|
254
|
+
end
|
88
255
|
|
89
|
-
|
90
|
-
|
256
|
+
if Proc.method_defined?(:source_location)
|
257
|
+
def ensure_block_has_source_location(_block); end
|
258
|
+
else # for 1.8.7
|
259
|
+
# :nocov:
|
260
|
+
def ensure_block_has_source_location(block)
|
261
|
+
source_location = yield.split(':')
|
262
|
+
block.extend(Module.new { define_method(:source_location) { source_location } })
|
263
|
+
end
|
264
|
+
# :nocov:
|
265
|
+
end
|
91
266
|
end
|
92
267
|
end
|
93
268
|
end
|
94
|
-
end
|
95
269
|
|
96
|
-
|
270
|
+
instance_exec(&Core::SharedExampleGroup::TopLevelDSL.definitions)
|
271
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Core
|
3
|
+
# @private
|
4
|
+
# Deals with the fact that `shellwords` only works on POSIX systems.
|
5
|
+
module ShellEscape
|
6
|
+
module_function
|
7
|
+
|
8
|
+
def quote(argument)
|
9
|
+
"'#{argument.to_s.gsub("'", "\\\\'")}'"
|
10
|
+
end
|
11
|
+
|
12
|
+
if RSpec::Support::OS.windows?
|
13
|
+
# :nocov:
|
14
|
+
alias escape quote
|
15
|
+
# :nocov:
|
16
|
+
else
|
17
|
+
require 'shellwords'
|
18
|
+
|
19
|
+
def escape(shell_command)
|
20
|
+
Shellwords.escape(shell_command.to_s)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Known shells that require quoting: zsh, csh, tcsh.
|
25
|
+
#
|
26
|
+
# Feel free to add other shells to this list that are known to
|
27
|
+
# allow `rspec ./some_spec.rb[1:1]` syntax without quoting the id.
|
28
|
+
#
|
29
|
+
# @private
|
30
|
+
SHELLS_ALLOWING_UNQUOTED_IDS = %w[ bash ksh fish ]
|
31
|
+
|
32
|
+
def conditionally_quote(id)
|
33
|
+
return id if shell_allows_unquoted_ids?
|
34
|
+
quote(id)
|
35
|
+
end
|
36
|
+
|
37
|
+
def shell_allows_unquoted_ids?
|
38
|
+
# Note: ENV['SHELL'] isn't necessarily the shell the user is currently running.
|
39
|
+
# According to http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html:
|
40
|
+
# "This variable shall represent a pathname of the user's preferred command language interpreter."
|
41
|
+
#
|
42
|
+
# It's the best we can easily do, though. We err on the side of safety (quoting
|
43
|
+
# the id when not actually needed) so it's not a big deal if the user is actually
|
44
|
+
# using a different shell.
|
45
|
+
SHELLS_ALLOWING_UNQUOTED_IDS.include?(ENV['SHELL'].to_s.split('/').last)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'test/unit/assertions'
|
2
|
+
|
3
|
+
module RSpec
|
4
|
+
module Core
|
5
|
+
# @private
|
6
|
+
module TestUnitAssertionsAdapter
|
7
|
+
include ::Test::Unit::Assertions
|
8
|
+
|
9
|
+
# If using test/unit from Ruby core with Ruby 1.9+, it includes
|
10
|
+
# MiniTest::Assertions by default. Note the upcasing of 'Test'.
|
11
|
+
#
|
12
|
+
# If the test/unit gem is being loaded, it will not include any minitest
|
13
|
+
# assertions.
|
14
|
+
#
|
15
|
+
# Only if Minitest 5.x is included / loaded do we need to worry about
|
16
|
+
# adding a shim for the new updates. Thus instead of checking on the
|
17
|
+
# RUBY_VERSION we need to check ancestors.
|
18
|
+
begin
|
19
|
+
# MiniTest is 4.x.
|
20
|
+
# Minitest is 5.x.
|
21
|
+
if ancestors.include?(::Minitest::Assertions)
|
22
|
+
require 'rspec/core/minitest_assertions_adapter'
|
23
|
+
include ::RSpec::Core::MinitestAssertionsAdapter
|
24
|
+
end
|
25
|
+
rescue NameError
|
26
|
+
# No-op. Minitest 5.x was not loaded.
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/rspec/core/version.rb
CHANGED
@@ -0,0 +1,40 @@
|
|
1
|
+
require "rspec/support/warnings"
|
2
|
+
|
3
|
+
module RSpec
|
4
|
+
module Core
|
5
|
+
# @private
|
6
|
+
module Warnings
|
7
|
+
# @private
|
8
|
+
#
|
9
|
+
# Used internally to print deprecation warnings.
|
10
|
+
def deprecate(deprecated, data={})
|
11
|
+
RSpec.configuration.reporter.deprecation(
|
12
|
+
{
|
13
|
+
:deprecated => deprecated,
|
14
|
+
:call_site => CallerFilter.first_non_rspec_line
|
15
|
+
}.merge(data)
|
16
|
+
)
|
17
|
+
end
|
18
|
+
|
19
|
+
# @private
|
20
|
+
#
|
21
|
+
# Used internally to print deprecation warnings.
|
22
|
+
def warn_deprecation(message, opts={})
|
23
|
+
RSpec.configuration.reporter.deprecation opts.merge(:message => message)
|
24
|
+
end
|
25
|
+
|
26
|
+
# @private
|
27
|
+
def warn_with(message, options={})
|
28
|
+
if options[:use_spec_location_as_call_site]
|
29
|
+
message += "." unless message.end_with?(".")
|
30
|
+
|
31
|
+
if RSpec.current_example
|
32
|
+
message += " Warning generated from spec at `#{RSpec.current_example.location}`."
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
super(message, options)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|