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,1337 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
class SelfObserver
|
|
4
|
-
def self.cache
|
|
5
|
-
@cache ||= []
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
def initialize
|
|
9
|
-
self.class.cache << self
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
module RSpec::Core
|
|
14
|
-
describe ExampleGroup do
|
|
15
|
-
it_behaves_like "metadata hash builder" do
|
|
16
|
-
def metadata_hash(*args)
|
|
17
|
-
group = ExampleGroup.describe('example description', *args)
|
|
18
|
-
group.metadata
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
context "when RSpec.configuration.format_docstrings is set to a block" do
|
|
23
|
-
it "formats the description with that block" do
|
|
24
|
-
RSpec.configuration.format_docstrings { |s| s.upcase }
|
|
25
|
-
group = ExampleGroup.describe(' an example ')
|
|
26
|
-
expect(group.description).to eq(' AN EXAMPLE ')
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
context 'when RSpec.configuration.treat_symbols_as_metadata_keys_with_true_values is set to false' do
|
|
31
|
-
before(:each) do
|
|
32
|
-
allow_deprecation
|
|
33
|
-
RSpec.configure { |c| c.treat_symbols_as_metadata_keys_with_true_values = false }
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
it 'processes string args as part of the description' do
|
|
37
|
-
group = ExampleGroup.describe("some", "separate", "strings")
|
|
38
|
-
expect(group.description).to eq("some separate strings")
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
it 'processes symbol args as part of the description' do
|
|
42
|
-
Kernel.stub(:warn) # to silence Symbols as args warning
|
|
43
|
-
group = ExampleGroup.describe(:some, :separate, :symbols)
|
|
44
|
-
expect(group.description).to eq("some separate symbols")
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
context 'when RSpec.configuration.treat_symbols_as_metadata_keys_with_true_values is set to true' do
|
|
49
|
-
let(:group) { ExampleGroup.describe(:symbol) }
|
|
50
|
-
|
|
51
|
-
before(:each) do
|
|
52
|
-
RSpec.configure { |c| c.treat_symbols_as_metadata_keys_with_true_values = true }
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
it 'does not treat the first argument as a metadata key even if it is a symbol' do
|
|
56
|
-
expect(group.metadata).not_to include(:symbol)
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
it 'treats the first argument as part of the description when it is a symbol' do
|
|
60
|
-
expect(group.description).to eq("symbol")
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
describe "top level group" do
|
|
65
|
-
it "runs its children" do
|
|
66
|
-
examples_run = []
|
|
67
|
-
group = ExampleGroup.describe("parent") do
|
|
68
|
-
describe("child") do
|
|
69
|
-
it "does something" do |ex|
|
|
70
|
-
examples_run << ex
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
group.run
|
|
76
|
-
expect(examples_run).to have(1).example
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
context "with a failure in the top level group" do
|
|
80
|
-
it "runs its children " do
|
|
81
|
-
examples_run = []
|
|
82
|
-
group = ExampleGroup.describe("parent") do
|
|
83
|
-
it "fails" do |ex|
|
|
84
|
-
examples_run << ex
|
|
85
|
-
raise "fail"
|
|
86
|
-
end
|
|
87
|
-
describe("child") do
|
|
88
|
-
it "does something" do |ex|
|
|
89
|
-
examples_run << ex
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
group.run
|
|
95
|
-
expect(examples_run).to have(2).examples
|
|
96
|
-
end
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
describe "descendants" do
|
|
100
|
-
it "returns self + all descendants" do
|
|
101
|
-
group = ExampleGroup.describe("parent") do
|
|
102
|
-
describe("child") do
|
|
103
|
-
describe("grandchild 1") {}
|
|
104
|
-
describe("grandchild 2") {}
|
|
105
|
-
end
|
|
106
|
-
end
|
|
107
|
-
expect(group.descendants.size).to eq(4)
|
|
108
|
-
end
|
|
109
|
-
end
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
describe "child" do
|
|
113
|
-
it "is known by parent" do
|
|
114
|
-
parent = ExampleGroup.describe
|
|
115
|
-
child = parent.describe
|
|
116
|
-
expect(parent.children).to eq([child])
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
it "is not registered in world" do
|
|
120
|
-
world = RSpec::Core::World.new
|
|
121
|
-
parent = ExampleGroup.describe
|
|
122
|
-
world.register(parent)
|
|
123
|
-
parent.describe
|
|
124
|
-
expect(world.example_groups).to eq([parent])
|
|
125
|
-
end
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
describe "filtering" do
|
|
129
|
-
let(:world) { World.new }
|
|
130
|
-
|
|
131
|
-
shared_examples "matching filters" do
|
|
132
|
-
context "inclusion" do
|
|
133
|
-
before do
|
|
134
|
-
filter_manager = FilterManager.new
|
|
135
|
-
filter_manager.include filter_metadata
|
|
136
|
-
world.stub(:filter_manager => filter_manager)
|
|
137
|
-
end
|
|
138
|
-
|
|
139
|
-
it "includes examples in groups matching filter" do
|
|
140
|
-
group = ExampleGroup.describe("does something", spec_metadata)
|
|
141
|
-
group.stub(:world) { world }
|
|
142
|
-
all_examples = [ group.example("first"), group.example("second") ]
|
|
143
|
-
|
|
144
|
-
expect(group.filtered_examples).to eq(all_examples)
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
it "includes examples directly matching filter" do
|
|
148
|
-
group = ExampleGroup.describe("does something")
|
|
149
|
-
group.stub(:world) { world }
|
|
150
|
-
filtered_examples = [
|
|
151
|
-
group.example("first", spec_metadata),
|
|
152
|
-
group.example("second", spec_metadata)
|
|
153
|
-
]
|
|
154
|
-
group.example("third (not-filtered)")
|
|
155
|
-
|
|
156
|
-
expect(group.filtered_examples).to eq(filtered_examples)
|
|
157
|
-
end
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
context "exclusion" do
|
|
161
|
-
before do
|
|
162
|
-
filter_manager = FilterManager.new
|
|
163
|
-
filter_manager.exclude filter_metadata
|
|
164
|
-
world.stub(:filter_manager => filter_manager)
|
|
165
|
-
end
|
|
166
|
-
|
|
167
|
-
it "excludes examples in groups matching filter" do
|
|
168
|
-
group = ExampleGroup.describe("does something", spec_metadata)
|
|
169
|
-
group.stub(:world) { world }
|
|
170
|
-
[ group.example("first"), group.example("second") ]
|
|
171
|
-
|
|
172
|
-
expect(group.filtered_examples).to be_empty
|
|
173
|
-
end
|
|
174
|
-
|
|
175
|
-
it "excludes examples directly matching filter" do
|
|
176
|
-
group = ExampleGroup.describe("does something")
|
|
177
|
-
group.stub(:world) { world }
|
|
178
|
-
[
|
|
179
|
-
group.example("first", spec_metadata),
|
|
180
|
-
group.example("second", spec_metadata)
|
|
181
|
-
]
|
|
182
|
-
unfiltered_example = group.example("third (not-filtered)")
|
|
183
|
-
|
|
184
|
-
expect(group.filtered_examples).to eq([unfiltered_example])
|
|
185
|
-
end
|
|
186
|
-
end
|
|
187
|
-
end
|
|
188
|
-
|
|
189
|
-
context "matching false" do
|
|
190
|
-
let(:spec_metadata) { { :awesome => false }}
|
|
191
|
-
|
|
192
|
-
context "against false" do
|
|
193
|
-
let(:filter_metadata) { { :awesome => false }}
|
|
194
|
-
include_examples "matching filters"
|
|
195
|
-
end
|
|
196
|
-
|
|
197
|
-
context "against 'false'" do
|
|
198
|
-
let(:filter_metadata) { { :awesome => 'false' }}
|
|
199
|
-
include_examples "matching filters"
|
|
200
|
-
end
|
|
201
|
-
|
|
202
|
-
context "against :false" do
|
|
203
|
-
let(:filter_metadata) { { :awesome => :false }}
|
|
204
|
-
include_examples "matching filters"
|
|
205
|
-
end
|
|
206
|
-
end
|
|
207
|
-
|
|
208
|
-
context "matching true" do
|
|
209
|
-
let(:spec_metadata) { { :awesome => true }}
|
|
210
|
-
|
|
211
|
-
context "against true" do
|
|
212
|
-
let(:filter_metadata) { { :awesome => true }}
|
|
213
|
-
include_examples "matching filters"
|
|
214
|
-
end
|
|
215
|
-
|
|
216
|
-
context "against 'true'" do
|
|
217
|
-
let(:filter_metadata) { { :awesome => 'true' }}
|
|
218
|
-
include_examples "matching filters"
|
|
219
|
-
end
|
|
220
|
-
|
|
221
|
-
context "against :true" do
|
|
222
|
-
let(:filter_metadata) { { :awesome => :true }}
|
|
223
|
-
include_examples "matching filters"
|
|
224
|
-
end
|
|
225
|
-
end
|
|
226
|
-
|
|
227
|
-
context "matching a string" do
|
|
228
|
-
let(:spec_metadata) { { :type => 'special' }}
|
|
229
|
-
|
|
230
|
-
context "against a string" do
|
|
231
|
-
let(:filter_metadata) { { :type => 'special' }}
|
|
232
|
-
include_examples "matching filters"
|
|
233
|
-
end
|
|
234
|
-
|
|
235
|
-
context "against a symbol" do
|
|
236
|
-
let(:filter_metadata) { { :type => :special }}
|
|
237
|
-
include_examples "matching filters"
|
|
238
|
-
end
|
|
239
|
-
end
|
|
240
|
-
|
|
241
|
-
context "matching a symbol" do
|
|
242
|
-
let(:spec_metadata) { { :type => :special }}
|
|
243
|
-
|
|
244
|
-
context "against a string" do
|
|
245
|
-
let(:filter_metadata) { { :type => 'special' }}
|
|
246
|
-
include_examples "matching filters"
|
|
247
|
-
end
|
|
248
|
-
|
|
249
|
-
context "against a symbol" do
|
|
250
|
-
let(:filter_metadata) { { :type => :special }}
|
|
251
|
-
include_examples "matching filters"
|
|
252
|
-
end
|
|
253
|
-
end
|
|
254
|
-
|
|
255
|
-
context "with no filters" do
|
|
256
|
-
it "returns all" do
|
|
257
|
-
group = ExampleGroup.describe
|
|
258
|
-
group.stub(:world) { world }
|
|
259
|
-
example = group.example("does something")
|
|
260
|
-
expect(group.filtered_examples).to eq([example])
|
|
261
|
-
end
|
|
262
|
-
end
|
|
263
|
-
|
|
264
|
-
context "with no examples or groups that match filters" do
|
|
265
|
-
it "returns none" do
|
|
266
|
-
filter_manager = FilterManager.new
|
|
267
|
-
filter_manager.include :awesome => false
|
|
268
|
-
world.stub(:filter_manager => filter_manager)
|
|
269
|
-
group = ExampleGroup.describe
|
|
270
|
-
group.stub(:world) { world }
|
|
271
|
-
group.example("does something")
|
|
272
|
-
expect(group.filtered_examples).to eq([])
|
|
273
|
-
end
|
|
274
|
-
end
|
|
275
|
-
end
|
|
276
|
-
|
|
277
|
-
describe '#described_class' do
|
|
278
|
-
|
|
279
|
-
context "with a constant as the first parameter" do
|
|
280
|
-
it "is that constant" do
|
|
281
|
-
expect(ExampleGroup.describe(Object) { }.described_class).to eq(Object)
|
|
282
|
-
end
|
|
283
|
-
end
|
|
284
|
-
|
|
285
|
-
context "with a string as the first parameter" do
|
|
286
|
-
it "is nil" do
|
|
287
|
-
expect(ExampleGroup.describe("i'm a computer") { }.described_class).to be_nil
|
|
288
|
-
end
|
|
289
|
-
end
|
|
290
|
-
|
|
291
|
-
context "with a constant in an outer group" do
|
|
292
|
-
context "and a string in an inner group" do
|
|
293
|
-
it "is the top level constant" do
|
|
294
|
-
group = ExampleGroup.describe(String) do
|
|
295
|
-
describe "some string" do
|
|
296
|
-
example "described_class is String" do
|
|
297
|
-
expect(described_class).to eq(String)
|
|
298
|
-
end
|
|
299
|
-
end
|
|
300
|
-
end
|
|
301
|
-
|
|
302
|
-
expect(group.run).to be_truthy
|
|
303
|
-
end
|
|
304
|
-
end
|
|
305
|
-
|
|
306
|
-
context "and metadata redefinition after `described_class` call" do
|
|
307
|
-
it "is the redefined level constant" do
|
|
308
|
-
group = ExampleGroup.describe(String) do
|
|
309
|
-
described_class
|
|
310
|
-
metadata[:example_group][:described_class] = Object
|
|
311
|
-
describe "inner" do
|
|
312
|
-
example "described_class is Object" do
|
|
313
|
-
expect(described_class).to eq(Object)
|
|
314
|
-
end
|
|
315
|
-
end
|
|
316
|
-
end
|
|
317
|
-
|
|
318
|
-
expect(group.run).to be_truthy
|
|
319
|
-
end
|
|
320
|
-
end
|
|
321
|
-
end
|
|
322
|
-
|
|
323
|
-
context "in a nested group" do
|
|
324
|
-
it "inherits the described class/module from the outer group" do
|
|
325
|
-
group = ExampleGroup.describe(String) do
|
|
326
|
-
describe Array do
|
|
327
|
-
example "describes is String" do
|
|
328
|
-
expect(described_class).to eq(String)
|
|
329
|
-
end
|
|
330
|
-
end
|
|
331
|
-
end
|
|
332
|
-
|
|
333
|
-
expect(group.run).to be_truthy, "expected examples in group to pass"
|
|
334
|
-
end
|
|
335
|
-
|
|
336
|
-
def capture_deprecation_options
|
|
337
|
-
warn_opts = nil
|
|
338
|
-
allow(RSpec.configuration.reporter).to receive(:deprecation) do |opts|
|
|
339
|
-
warn_opts = opts
|
|
340
|
-
end
|
|
341
|
-
|
|
342
|
-
yield
|
|
343
|
-
|
|
344
|
-
warn_opts
|
|
345
|
-
end
|
|
346
|
-
|
|
347
|
-
it "prints a deprecation warning since the semantics are changing in RSpec 3" do
|
|
348
|
-
warn_opts = capture_deprecation_options do
|
|
349
|
-
ExampleGroup.describe(String) do
|
|
350
|
-
describe Array do
|
|
351
|
-
example { described_class }
|
|
352
|
-
end
|
|
353
|
-
end.run
|
|
354
|
-
end
|
|
355
|
-
|
|
356
|
-
expect(warn_opts[:message]).to include("#{__FILE__}:#{__LINE__ - 5}")
|
|
357
|
-
expect(warn_opts[:message]).to include("described_class")
|
|
358
|
-
end
|
|
359
|
-
|
|
360
|
-
it "prints a deprecation even when `described_class` has already been referenced in the outer group" do
|
|
361
|
-
warn_opts = capture_deprecation_options do
|
|
362
|
-
outer_dc = inner_dc = nil
|
|
363
|
-
ExampleGroup.describe(String) do
|
|
364
|
-
outer_dc = described_class
|
|
365
|
-
describe Array do
|
|
366
|
-
example { inner_dc = described_class }
|
|
367
|
-
end
|
|
368
|
-
end.run
|
|
369
|
-
|
|
370
|
-
expect(outer_dc).to eq(String)
|
|
371
|
-
expect(inner_dc).to eq(String)
|
|
372
|
-
end
|
|
373
|
-
|
|
374
|
-
expect(warn_opts[:message]).to include("#{__FILE__}:#{__LINE__ - 8}")
|
|
375
|
-
expect(warn_opts[:message]).to include("described_class")
|
|
376
|
-
end
|
|
377
|
-
|
|
378
|
-
it "does not print a deprecation warning when the inner example group has no description args" do
|
|
379
|
-
dc = :unset
|
|
380
|
-
deprecations = []
|
|
381
|
-
allow(RSpec).to receive(:warn_deprecation) { |msg| deprecations << msg }
|
|
382
|
-
|
|
383
|
-
ExampleGroup.describe(String) do
|
|
384
|
-
describe do
|
|
385
|
-
example { dc = described_class }
|
|
386
|
-
end
|
|
387
|
-
end.run
|
|
388
|
-
|
|
389
|
-
expect(dc).to be(String)
|
|
390
|
-
expect(deprecations).to eq([])
|
|
391
|
-
end
|
|
392
|
-
end
|
|
393
|
-
|
|
394
|
-
context "for `describe(SomeClass)` within a `describe 'some string' group" do
|
|
395
|
-
def define_and_run_group(define_outer_example = false)
|
|
396
|
-
outer_described_class = inner_described_class = nil
|
|
397
|
-
|
|
398
|
-
ExampleGroup.describe("some string") do
|
|
399
|
-
example { outer_described_class = described_class } if define_outer_example
|
|
400
|
-
|
|
401
|
-
describe Array do
|
|
402
|
-
example { inner_described_class = described_class }
|
|
403
|
-
end
|
|
404
|
-
end.run
|
|
405
|
-
|
|
406
|
-
return outer_described_class, inner_described_class
|
|
407
|
-
end
|
|
408
|
-
|
|
409
|
-
it "has a `nil` described_class in the outer group" do
|
|
410
|
-
outer_described_class, _ = define_and_run_group(:define_outer_example)
|
|
411
|
-
expect(outer_described_class).to be(nil)
|
|
412
|
-
end
|
|
413
|
-
|
|
414
|
-
it "has the inner described class as the described_class of the inner group" do
|
|
415
|
-
_, inner_described_class = define_and_run_group
|
|
416
|
-
expect(inner_described_class).to be(Array)
|
|
417
|
-
|
|
418
|
-
# This is weird, but in RSpec 2.12 (and before, presumably),
|
|
419
|
-
# the `described_class` value would be incorrect if there was an
|
|
420
|
-
# example in the outer group, and correct if there was not one.
|
|
421
|
-
_, inner_described_class = define_and_run_group(:define_outer_example)
|
|
422
|
-
expect(inner_described_class).to be(Array)
|
|
423
|
-
end
|
|
424
|
-
end
|
|
425
|
-
end
|
|
426
|
-
|
|
427
|
-
describe '#described_class' do
|
|
428
|
-
it "is the same as described_class" do
|
|
429
|
-
expect(self.class.described_class).to eq(self.class.described_class)
|
|
430
|
-
end
|
|
431
|
-
end
|
|
432
|
-
|
|
433
|
-
describe '#description' do
|
|
434
|
-
it "grabs the description from the metadata" do
|
|
435
|
-
group = ExampleGroup.describe(Object, "my desc") { }
|
|
436
|
-
expect(group.description).to eq(group.metadata[:example_group][:description])
|
|
437
|
-
end
|
|
438
|
-
end
|
|
439
|
-
|
|
440
|
-
describe '#metadata' do
|
|
441
|
-
it "adds the third parameter to the metadata" do
|
|
442
|
-
expect(ExampleGroup.describe(Object, nil, 'foo' => 'bar') { }.metadata).to include({ "foo" => 'bar' })
|
|
443
|
-
end
|
|
444
|
-
|
|
445
|
-
it "adds the the file_path to metadata" do
|
|
446
|
-
expect(ExampleGroup.describe(Object) { }.metadata[:example_group][:file_path]).to eq(relative_path(__FILE__))
|
|
447
|
-
end
|
|
448
|
-
|
|
449
|
-
it "has a reader for file_path" do
|
|
450
|
-
expect(ExampleGroup.describe(Object) { }.file_path).to eq(relative_path(__FILE__))
|
|
451
|
-
end
|
|
452
|
-
|
|
453
|
-
it "adds the line_number to metadata" do
|
|
454
|
-
expect(ExampleGroup.describe(Object) { }.metadata[:example_group][:line_number]).to eq(__LINE__)
|
|
455
|
-
end
|
|
456
|
-
end
|
|
457
|
-
|
|
458
|
-
[:focus, :focused, :fit].each do |example_alias|
|
|
459
|
-
describe "##{example_alias}" do
|
|
460
|
-
let(:focused_example) { ExampleGroup.describe.send example_alias, "a focused example" }
|
|
461
|
-
|
|
462
|
-
it 'defines an example that can be filtered with :focused => true' do
|
|
463
|
-
expect(focused_example.metadata[:focused]).to be_truthy
|
|
464
|
-
end
|
|
465
|
-
|
|
466
|
-
it 'defines an example that can be filtered with :focus => true' do
|
|
467
|
-
expect(focused_example.metadata[:focus]).to be_truthy
|
|
468
|
-
end
|
|
469
|
-
end
|
|
470
|
-
end
|
|
471
|
-
|
|
472
|
-
describe "#before, after, and around hooks" do
|
|
473
|
-
it "runs the before alls in order" do
|
|
474
|
-
group = ExampleGroup.describe
|
|
475
|
-
order = []
|
|
476
|
-
group.before(:all) { order << 1 }
|
|
477
|
-
group.before(:all) { order << 2 }
|
|
478
|
-
group.before(:all) { order << 3 }
|
|
479
|
-
group.example("example") {}
|
|
480
|
-
|
|
481
|
-
group.run
|
|
482
|
-
|
|
483
|
-
expect(order).to eq([1,2,3])
|
|
484
|
-
end
|
|
485
|
-
|
|
486
|
-
it "does not set RSpec.wants_to_quit in case of an error in before all (without fail_fast?)" do
|
|
487
|
-
group = ExampleGroup.describe
|
|
488
|
-
group.before(:all) { raise "error in before all" }
|
|
489
|
-
group.example("example") {}
|
|
490
|
-
|
|
491
|
-
group.run
|
|
492
|
-
expect(RSpec.wants_to_quit).to be_falsey
|
|
493
|
-
end
|
|
494
|
-
|
|
495
|
-
it "runs the before eachs in order" do
|
|
496
|
-
group = ExampleGroup.describe
|
|
497
|
-
order = []
|
|
498
|
-
group.before(:each) { order << 1 }
|
|
499
|
-
group.before(:each) { order << 2 }
|
|
500
|
-
group.before(:each) { order << 3 }
|
|
501
|
-
group.example("example") {}
|
|
502
|
-
|
|
503
|
-
group.run
|
|
504
|
-
|
|
505
|
-
expect(order).to eq([1,2,3])
|
|
506
|
-
end
|
|
507
|
-
|
|
508
|
-
it "runs the after eachs in reverse order" do
|
|
509
|
-
group = ExampleGroup.describe
|
|
510
|
-
order = []
|
|
511
|
-
group.after(:each) { order << 1 }
|
|
512
|
-
group.after(:each) { order << 2 }
|
|
513
|
-
group.after(:each) { order << 3 }
|
|
514
|
-
group.example("example") {}
|
|
515
|
-
|
|
516
|
-
group.run
|
|
517
|
-
|
|
518
|
-
expect(order).to eq([3,2,1])
|
|
519
|
-
end
|
|
520
|
-
|
|
521
|
-
it "runs the after alls in reverse order" do
|
|
522
|
-
group = ExampleGroup.describe
|
|
523
|
-
order = []
|
|
524
|
-
group.after(:all) { order << 1 }
|
|
525
|
-
group.after(:all) { order << 2 }
|
|
526
|
-
group.after(:all) { order << 3 }
|
|
527
|
-
group.example("example") {}
|
|
528
|
-
|
|
529
|
-
group.run
|
|
530
|
-
|
|
531
|
-
expect(order).to eq([3,2,1])
|
|
532
|
-
end
|
|
533
|
-
|
|
534
|
-
it "only runs before/after(:all) hooks from example groups that have specs that run" do
|
|
535
|
-
hooks_run = []
|
|
536
|
-
|
|
537
|
-
RSpec.configure do |c|
|
|
538
|
-
c.filter_run :focus => true
|
|
539
|
-
end
|
|
540
|
-
|
|
541
|
-
unfiltered_group = ExampleGroup.describe "unfiltered" do
|
|
542
|
-
before(:all) { hooks_run << :unfiltered_before_all }
|
|
543
|
-
after(:all) { hooks_run << :unfiltered_after_all }
|
|
544
|
-
|
|
545
|
-
context "a subcontext" do
|
|
546
|
-
it("has an example") { }
|
|
547
|
-
end
|
|
548
|
-
end
|
|
549
|
-
|
|
550
|
-
filtered_group = ExampleGroup.describe "filtered", :focus => true do
|
|
551
|
-
before(:all) { hooks_run << :filtered_before_all }
|
|
552
|
-
after(:all) { hooks_run << :filtered_after_all }
|
|
553
|
-
|
|
554
|
-
context "a subcontext" do
|
|
555
|
-
it("has an example") { }
|
|
556
|
-
end
|
|
557
|
-
end
|
|
558
|
-
|
|
559
|
-
unfiltered_group.run
|
|
560
|
-
filtered_group.run
|
|
561
|
-
|
|
562
|
-
expect(hooks_run).to eq([:filtered_before_all, :filtered_after_all])
|
|
563
|
-
end
|
|
564
|
-
|
|
565
|
-
it "runs before_all_defined_in_config, before all, before each, example, after each, after all, after_all_defined_in_config in that order" do
|
|
566
|
-
order = []
|
|
567
|
-
|
|
568
|
-
RSpec.configure do |c|
|
|
569
|
-
c.before(:all) { order << :before_all_defined_in_config }
|
|
570
|
-
c.after(:all) { order << :after_all_defined_in_config }
|
|
571
|
-
end
|
|
572
|
-
|
|
573
|
-
group = ExampleGroup.describe
|
|
574
|
-
group.before(:all) { order << :top_level_before_all }
|
|
575
|
-
group.before(:each) { order << :before_each }
|
|
576
|
-
group.after(:each) { order << :after_each }
|
|
577
|
-
group.after(:all) { order << :top_level_after_all }
|
|
578
|
-
group.example("top level example") { order << :top_level_example }
|
|
579
|
-
|
|
580
|
-
context1 = group.describe("context 1")
|
|
581
|
-
context1.before(:all) { order << :nested_before_all }
|
|
582
|
-
context1.example("nested example 1") { order << :nested_example_1 }
|
|
583
|
-
|
|
584
|
-
context2 = group.describe("context 2")
|
|
585
|
-
context2.after(:all) { order << :nested_after_all }
|
|
586
|
-
context2.example("nested example 2") { order << :nested_example_2 }
|
|
587
|
-
|
|
588
|
-
group.run
|
|
589
|
-
|
|
590
|
-
expect(order).to eq([
|
|
591
|
-
:before_all_defined_in_config,
|
|
592
|
-
:top_level_before_all,
|
|
593
|
-
:before_each,
|
|
594
|
-
:top_level_example,
|
|
595
|
-
:after_each,
|
|
596
|
-
:nested_before_all,
|
|
597
|
-
:before_each,
|
|
598
|
-
:nested_example_1,
|
|
599
|
-
:after_each,
|
|
600
|
-
:before_each,
|
|
601
|
-
:nested_example_2,
|
|
602
|
-
:after_each,
|
|
603
|
-
:nested_after_all,
|
|
604
|
-
:top_level_after_all,
|
|
605
|
-
:after_all_defined_in_config
|
|
606
|
-
])
|
|
607
|
-
end
|
|
608
|
-
|
|
609
|
-
context "after(:all)" do
|
|
610
|
-
let(:outer) { ExampleGroup.describe }
|
|
611
|
-
let(:inner) { outer.describe }
|
|
612
|
-
|
|
613
|
-
it "has access to state defined before(:all)" do
|
|
614
|
-
outer.before(:all) { @outer = "outer" }
|
|
615
|
-
inner.before(:all) { @inner = "inner" }
|
|
616
|
-
|
|
617
|
-
outer.after(:all) do
|
|
618
|
-
expect(@outer).to eq("outer")
|
|
619
|
-
expect(@inner).to eq("inner")
|
|
620
|
-
end
|
|
621
|
-
inner.after(:all) do
|
|
622
|
-
expect(@inner).to eq("inner")
|
|
623
|
-
expect(@outer).to eq("outer")
|
|
624
|
-
end
|
|
625
|
-
|
|
626
|
-
outer.run
|
|
627
|
-
end
|
|
628
|
-
|
|
629
|
-
it "cleans up ivars in after(:all)" do
|
|
630
|
-
outer.before(:all) { @outer = "outer" }
|
|
631
|
-
inner.before(:all) { @inner = "inner" }
|
|
632
|
-
|
|
633
|
-
outer.run
|
|
634
|
-
|
|
635
|
-
expect(inner.before_all_ivars[:@inner]).to be_nil
|
|
636
|
-
expect(inner.before_all_ivars[:@outer]).to be_nil
|
|
637
|
-
expect(outer.before_all_ivars[:@inner]).to be_nil
|
|
638
|
-
expect(outer.before_all_ivars[:@outer]).to be_nil
|
|
639
|
-
end
|
|
640
|
-
end
|
|
641
|
-
|
|
642
|
-
it "treats an error in before(:each) as a failure" do
|
|
643
|
-
group = ExampleGroup.describe
|
|
644
|
-
group.before(:each) { raise "error in before each" }
|
|
645
|
-
example = group.example("equality") { expect(1).to eq(2) }
|
|
646
|
-
expect(group.run).to be(false)
|
|
647
|
-
|
|
648
|
-
expect(example.metadata[:execution_result][:exception].message).to eq("error in before each")
|
|
649
|
-
end
|
|
650
|
-
|
|
651
|
-
it "treats an error in before(:all) as a failure" do
|
|
652
|
-
group = ExampleGroup.describe
|
|
653
|
-
group.before(:all) { raise "error in before all" }
|
|
654
|
-
example = group.example("equality") { expect(1).to eq(2) }
|
|
655
|
-
expect(group.run).to be_falsey
|
|
656
|
-
|
|
657
|
-
expect(example.metadata).not_to be_nil
|
|
658
|
-
expect(example.metadata[:execution_result]).not_to be_nil
|
|
659
|
-
expect(example.metadata[:execution_result][:exception]).not_to be_nil
|
|
660
|
-
expect(example.metadata[:execution_result][:exception].message).to eq("error in before all")
|
|
661
|
-
end
|
|
662
|
-
|
|
663
|
-
it "exposes instance variables set in before(:all) from after(:all) even if a before(:all) error occurs" do
|
|
664
|
-
ivar_value_in_after_hook = nil
|
|
665
|
-
|
|
666
|
-
group = ExampleGroup.describe do
|
|
667
|
-
before(:all) do
|
|
668
|
-
@an_ivar = :set_in_before_all
|
|
669
|
-
raise "fail"
|
|
670
|
-
end
|
|
671
|
-
|
|
672
|
-
after(:all) { ivar_value_in_after_hook = @an_ivar }
|
|
673
|
-
|
|
674
|
-
it("has a spec") { }
|
|
675
|
-
end
|
|
676
|
-
|
|
677
|
-
group.run
|
|
678
|
-
expect(ivar_value_in_after_hook).to eq(:set_in_before_all)
|
|
679
|
-
end
|
|
680
|
-
|
|
681
|
-
it "treats an error in before(:all) as a failure for a spec in a nested group" do
|
|
682
|
-
example = nil
|
|
683
|
-
group = ExampleGroup.describe do
|
|
684
|
-
before(:all) { raise "error in before all" }
|
|
685
|
-
|
|
686
|
-
describe "nested" do
|
|
687
|
-
example = it("equality") { expect(1).to eq(2) }
|
|
688
|
-
end
|
|
689
|
-
end
|
|
690
|
-
group.run
|
|
691
|
-
|
|
692
|
-
expect(example.metadata).not_to be_nil
|
|
693
|
-
expect(example.metadata[:execution_result]).not_to be_nil
|
|
694
|
-
expect(example.metadata[:execution_result][:exception]).not_to be_nil
|
|
695
|
-
expect(example.metadata[:execution_result][:exception].message).to eq("error in before all")
|
|
696
|
-
end
|
|
697
|
-
|
|
698
|
-
context "when an error occurs in an after(:all) hook" do
|
|
699
|
-
hooks_run = []
|
|
700
|
-
|
|
701
|
-
before(:each) do
|
|
702
|
-
hooks_run = []
|
|
703
|
-
RSpec.configuration.reporter.stub(:message)
|
|
704
|
-
end
|
|
705
|
-
|
|
706
|
-
let(:group) do
|
|
707
|
-
ExampleGroup.describe do
|
|
708
|
-
after(:all) { hooks_run << :one; raise "An error in an after(:all) hook" }
|
|
709
|
-
after(:all) { hooks_run << :two; raise "A different hook raising an error" }
|
|
710
|
-
it("equality") { expect(1).to eq(1) }
|
|
711
|
-
end
|
|
712
|
-
end
|
|
713
|
-
|
|
714
|
-
it "allows the example to pass" do
|
|
715
|
-
group.run
|
|
716
|
-
example = group.examples.first
|
|
717
|
-
expect(example.metadata).not_to be_nil
|
|
718
|
-
expect(example.metadata[:execution_result]).not_to be_nil
|
|
719
|
-
expect(example.metadata[:execution_result][:status]).to eq("passed")
|
|
720
|
-
end
|
|
721
|
-
|
|
722
|
-
it "rescues any error(s) and prints them out" do
|
|
723
|
-
RSpec.configuration.reporter.should_receive(:message).with(/An error in an after\(:all\) hook/)
|
|
724
|
-
RSpec.configuration.reporter.should_receive(:message).with(/A different hook raising an error/)
|
|
725
|
-
group.run
|
|
726
|
-
end
|
|
727
|
-
|
|
728
|
-
it "still runs both after blocks" do
|
|
729
|
-
group.run
|
|
730
|
-
expect(hooks_run).to eq [:two,:one]
|
|
731
|
-
end
|
|
732
|
-
end
|
|
733
|
-
|
|
734
|
-
it "has access to example options within before(:each)" do
|
|
735
|
-
group = ExampleGroup.describe
|
|
736
|
-
option = nil
|
|
737
|
-
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /options/)
|
|
738
|
-
group.before(:each) {|ex| option = ex.options[:data] }
|
|
739
|
-
group.example("no-op", :data => :sample) { }
|
|
740
|
-
group.run
|
|
741
|
-
expect(option).to eq(:sample)
|
|
742
|
-
end
|
|
743
|
-
|
|
744
|
-
it "has access to example options within after(:each)" do
|
|
745
|
-
group = ExampleGroup.describe
|
|
746
|
-
option = nil
|
|
747
|
-
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /options/)
|
|
748
|
-
group.after(:each) {|ex| option = ex.options[:data] }
|
|
749
|
-
group.example("no-op", :data => :sample) { }
|
|
750
|
-
group.run
|
|
751
|
-
expect(option).to eq(:sample)
|
|
752
|
-
end
|
|
753
|
-
end
|
|
754
|
-
|
|
755
|
-
context 'skip in metadata' do
|
|
756
|
-
let(:group) { ExampleGroup.describe do
|
|
757
|
-
it 'is skipped', :skip => 'skip this' do
|
|
758
|
-
end
|
|
759
|
-
end
|
|
760
|
-
}
|
|
761
|
-
|
|
762
|
-
before { group.run }
|
|
763
|
-
|
|
764
|
-
it 'generates a pending example' do
|
|
765
|
-
expect(group.examples.first).to be_pending
|
|
766
|
-
end
|
|
767
|
-
|
|
768
|
-
it 'sets the pending message' do
|
|
769
|
-
expect(group.examples.first.metadata[:execution_result][:pending_message]).to eq('skip this')
|
|
770
|
-
end
|
|
771
|
-
end
|
|
772
|
-
|
|
773
|
-
%w[pending skip].each do |method_name|
|
|
774
|
-
describe ".#{method_name}" do
|
|
775
|
-
let(:group) { ExampleGroup.describe.tap {|x|
|
|
776
|
-
x.send(method_name, "is pending") { }
|
|
777
|
-
}}
|
|
778
|
-
|
|
779
|
-
before { group.run }
|
|
780
|
-
|
|
781
|
-
it "generates a pending example" do
|
|
782
|
-
expect(group.examples.first).to be_pending
|
|
783
|
-
end
|
|
784
|
-
|
|
785
|
-
it "sets the pending message" do
|
|
786
|
-
expect(group.examples.first.metadata[:execution_result][:pending_message]).to eq(RSpec::Core::Pending::NO_REASON_GIVEN)
|
|
787
|
-
end
|
|
788
|
-
end
|
|
789
|
-
end
|
|
790
|
-
|
|
791
|
-
%w[xit xspecify xexample].each do |method_name|
|
|
792
|
-
describe ".#{method_name}" do
|
|
793
|
-
let(:group) { ExampleGroup.describe.tap {|x|
|
|
794
|
-
x.send(method_name, "is pending") { }
|
|
795
|
-
}}
|
|
796
|
-
|
|
797
|
-
before { group.run }
|
|
798
|
-
|
|
799
|
-
it "generates a pending example" do
|
|
800
|
-
expect(group.examples.first).to be_pending
|
|
801
|
-
end
|
|
802
|
-
|
|
803
|
-
it "sets the pending message" do
|
|
804
|
-
expect(group.examples.first.metadata[:execution_result][:pending_message]).to eq("Temporarily disabled with #{method_name}")
|
|
805
|
-
end
|
|
806
|
-
end
|
|
807
|
-
end
|
|
808
|
-
|
|
809
|
-
describe '::pending' do
|
|
810
|
-
it 'shows upgrade warning' do
|
|
811
|
-
expect_warn_deprecation_with_call_site(
|
|
812
|
-
"example_group_spec.rb", __LINE__ + 3
|
|
813
|
-
)
|
|
814
|
-
group = ExampleGroup.describe
|
|
815
|
-
group.send(:pending, "is pending") { }
|
|
816
|
-
end
|
|
817
|
-
end
|
|
818
|
-
|
|
819
|
-
describe "adding examples" do
|
|
820
|
-
|
|
821
|
-
it "allows adding an example using 'it'" do
|
|
822
|
-
group = ExampleGroup.describe
|
|
823
|
-
group.it("should do something") { }
|
|
824
|
-
expect(group.examples.size).to eq(1)
|
|
825
|
-
end
|
|
826
|
-
|
|
827
|
-
it "exposes all examples at examples" do
|
|
828
|
-
group = ExampleGroup.describe
|
|
829
|
-
group.it("should do something 1") { }
|
|
830
|
-
group.it("should do something 2") { }
|
|
831
|
-
group.it("should do something 3") { }
|
|
832
|
-
expect(group).to have(3).examples
|
|
833
|
-
end
|
|
834
|
-
|
|
835
|
-
it "maintains the example order" do
|
|
836
|
-
group = ExampleGroup.describe
|
|
837
|
-
group.it("should 1") { }
|
|
838
|
-
group.it("should 2") { }
|
|
839
|
-
group.it("should 3") { }
|
|
840
|
-
expect(group.examples[0].description).to eq('should 1')
|
|
841
|
-
expect(group.examples[1].description).to eq('should 2')
|
|
842
|
-
expect(group.examples[2].description).to eq('should 3')
|
|
843
|
-
end
|
|
844
|
-
|
|
845
|
-
end
|
|
846
|
-
|
|
847
|
-
describe Object, "describing nested example_groups", :little_less_nested => 'yep' do
|
|
848
|
-
|
|
849
|
-
describe "A sample nested group", :nested_describe => "yep" do
|
|
850
|
-
it "sets the described class to the described class of the outer most group" do |ex|
|
|
851
|
-
expect(ex.example_group.described_class).to eq(ExampleGroup)
|
|
852
|
-
end
|
|
853
|
-
|
|
854
|
-
it "sets the description to 'A sample nested describe'" do |ex|
|
|
855
|
-
expect(ex.example_group.description).to eq('A sample nested group')
|
|
856
|
-
end
|
|
857
|
-
|
|
858
|
-
it "has top level metadata from the example_group and its parent groups" do |ex|
|
|
859
|
-
expect(ex.example_group.metadata).to include(:little_less_nested => 'yep', :nested_describe => 'yep')
|
|
860
|
-
end
|
|
861
|
-
|
|
862
|
-
it "exposes the parent metadata to the contained examples" do |ex|
|
|
863
|
-
expect(ex.metadata).to include(:little_less_nested => 'yep', :nested_describe => 'yep')
|
|
864
|
-
end
|
|
865
|
-
end
|
|
866
|
-
|
|
867
|
-
end
|
|
868
|
-
|
|
869
|
-
describe "#run_examples" do
|
|
870
|
-
|
|
871
|
-
let(:reporter) { double("reporter").as_null_object }
|
|
872
|
-
|
|
873
|
-
it "returns true if all examples pass" do
|
|
874
|
-
group = ExampleGroup.describe('group') do
|
|
875
|
-
example('ex 1') { expect(1).to eq(1) }
|
|
876
|
-
example('ex 2') { expect(1).to eq(1) }
|
|
877
|
-
end
|
|
878
|
-
group.stub(:filtered_examples) { group.examples.extend(Extensions::Ordered::Examples) }
|
|
879
|
-
expect(group.run(reporter)).to be_truthy
|
|
880
|
-
end
|
|
881
|
-
|
|
882
|
-
it "returns false if any of the examples fail" do
|
|
883
|
-
group = ExampleGroup.describe('group') do
|
|
884
|
-
example('ex 1') { expect(1).to eq(1) }
|
|
885
|
-
example('ex 2') { expect(1).to eq(2) }
|
|
886
|
-
end
|
|
887
|
-
group.stub(:filtered_examples) { group.examples.extend(Extensions::Ordered::Examples) }
|
|
888
|
-
expect(group.run(reporter)).to be_falsey
|
|
889
|
-
end
|
|
890
|
-
|
|
891
|
-
it "runs all examples, regardless of any of them failing" do
|
|
892
|
-
group = ExampleGroup.describe('group') do
|
|
893
|
-
example('ex 1') { expect(1).to eq(2) }
|
|
894
|
-
example('ex 2') { expect(1).to eq(1) }
|
|
895
|
-
end
|
|
896
|
-
group.stub(:filtered_examples) { group.examples.extend(Extensions::Ordered::Examples) }
|
|
897
|
-
group.filtered_examples.each do |example|
|
|
898
|
-
example.should_receive(:run)
|
|
899
|
-
end
|
|
900
|
-
expect(group.run(reporter)).to be_falsey
|
|
901
|
-
end
|
|
902
|
-
end
|
|
903
|
-
|
|
904
|
-
describe "how instance variables are inherited" do
|
|
905
|
-
before(:all) do
|
|
906
|
-
@before_all_top_level = 'before_all_top_level'
|
|
907
|
-
end
|
|
908
|
-
|
|
909
|
-
before(:each) do
|
|
910
|
-
@before_each_top_level = 'before_each_top_level'
|
|
911
|
-
end
|
|
912
|
-
|
|
913
|
-
it "can access a before each ivar at the same level" do
|
|
914
|
-
expect(@before_each_top_level).to eq('before_each_top_level')
|
|
915
|
-
end
|
|
916
|
-
|
|
917
|
-
it "can access a before all ivar at the same level" do
|
|
918
|
-
expect(@before_all_top_level).to eq('before_all_top_level')
|
|
919
|
-
end
|
|
920
|
-
|
|
921
|
-
it "can access the before all ivars in the before_all_ivars hash", :ruby => 1.8 do |ex|
|
|
922
|
-
expect(ex.example_group.before_all_ivars).to include('@before_all_top_level' => 'before_all_top_level')
|
|
923
|
-
end
|
|
924
|
-
|
|
925
|
-
it "can access the before all ivars in the before_all_ivars hash", :ruby => 1.9 do |ex|
|
|
926
|
-
expect(ex.example_group.before_all_ivars).to include(:@before_all_top_level => 'before_all_top_level')
|
|
927
|
-
end
|
|
928
|
-
|
|
929
|
-
describe "but now I am nested" do
|
|
930
|
-
it "can access a parent example groups before each ivar at a nested level" do
|
|
931
|
-
expect(@before_each_top_level).to eq('before_each_top_level')
|
|
932
|
-
end
|
|
933
|
-
|
|
934
|
-
it "can access a parent example groups before all ivar at a nested level" do
|
|
935
|
-
expect(@before_all_top_level).to eq("before_all_top_level")
|
|
936
|
-
end
|
|
937
|
-
|
|
938
|
-
it "changes to before all ivars from within an example do not persist outside the current describe" do
|
|
939
|
-
@before_all_top_level = "ive been changed"
|
|
940
|
-
end
|
|
941
|
-
|
|
942
|
-
describe "accessing a before_all ivar that was changed in a parent example_group" do
|
|
943
|
-
it "does not have access to the modified version" do
|
|
944
|
-
expect(@before_all_top_level).to eq('before_all_top_level')
|
|
945
|
-
end
|
|
946
|
-
end
|
|
947
|
-
end
|
|
948
|
-
|
|
949
|
-
end
|
|
950
|
-
|
|
951
|
-
describe "ivars are not shared across examples" do
|
|
952
|
-
it "(first example)" do
|
|
953
|
-
@a = 1
|
|
954
|
-
expect(defined?(@b)).to be_falsey
|
|
955
|
-
end
|
|
956
|
-
|
|
957
|
-
it "(second example)" do
|
|
958
|
-
@b = 2
|
|
959
|
-
expect(defined?(@a)).to be_falsey
|
|
960
|
-
end
|
|
961
|
-
end
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
describe "#top_level_description" do
|
|
965
|
-
it "returns the description from the outermost example group" do
|
|
966
|
-
group = nil
|
|
967
|
-
ExampleGroup.describe("top") do
|
|
968
|
-
context "middle" do
|
|
969
|
-
group = describe "bottom" do
|
|
970
|
-
end
|
|
971
|
-
end
|
|
972
|
-
end
|
|
973
|
-
|
|
974
|
-
expect(group.top_level_description).to eq("top")
|
|
975
|
-
end
|
|
976
|
-
end
|
|
977
|
-
|
|
978
|
-
describe "#run" do
|
|
979
|
-
let(:reporter) { double("reporter").as_null_object }
|
|
980
|
-
|
|
981
|
-
context "with fail_fast? => true" do
|
|
982
|
-
let(:group) do
|
|
983
|
-
group = RSpec::Core::ExampleGroup.describe
|
|
984
|
-
group.stub(:fail_fast?) { true }
|
|
985
|
-
group
|
|
986
|
-
end
|
|
987
|
-
|
|
988
|
-
it "does not run examples after the failed example" do
|
|
989
|
-
examples_run = []
|
|
990
|
-
group.example('example 1') { examples_run << self }
|
|
991
|
-
group.example('example 2') { examples_run << self; fail; }
|
|
992
|
-
group.example('example 3') { examples_run << self }
|
|
993
|
-
|
|
994
|
-
group.run
|
|
995
|
-
|
|
996
|
-
expect(examples_run.length).to eq(2)
|
|
997
|
-
end
|
|
998
|
-
|
|
999
|
-
it "sets RSpec.wants_to_quit flag if encountering an exception in before(:all)" do
|
|
1000
|
-
group.before(:all) { raise "error in before all" }
|
|
1001
|
-
group.example("equality") { expect(1).to eq(2) }
|
|
1002
|
-
expect(group.run).to be_falsey
|
|
1003
|
-
expect(RSpec.wants_to_quit).to be_truthy
|
|
1004
|
-
end
|
|
1005
|
-
end
|
|
1006
|
-
|
|
1007
|
-
context "with RSpec.wants_to_quit=true" do
|
|
1008
|
-
let(:group) { RSpec::Core::ExampleGroup.describe }
|
|
1009
|
-
|
|
1010
|
-
before do
|
|
1011
|
-
RSpec.stub(:wants_to_quit) { true }
|
|
1012
|
-
RSpec.stub(:clear_remaining_example_groups)
|
|
1013
|
-
end
|
|
1014
|
-
|
|
1015
|
-
it "returns without starting the group" do
|
|
1016
|
-
reporter.should_not_receive(:example_group_started)
|
|
1017
|
-
group.run(reporter)
|
|
1018
|
-
end
|
|
1019
|
-
|
|
1020
|
-
context "at top level" do
|
|
1021
|
-
it "purges remaining groups" do
|
|
1022
|
-
RSpec.should_receive(:clear_remaining_example_groups)
|
|
1023
|
-
group.run(reporter)
|
|
1024
|
-
end
|
|
1025
|
-
end
|
|
1026
|
-
|
|
1027
|
-
context "in a nested group" do
|
|
1028
|
-
it "does not purge remaining groups" do
|
|
1029
|
-
nested_group = group.describe
|
|
1030
|
-
RSpec.should_not_receive(:clear_remaining_example_groups)
|
|
1031
|
-
nested_group.run(reporter)
|
|
1032
|
-
end
|
|
1033
|
-
end
|
|
1034
|
-
end
|
|
1035
|
-
|
|
1036
|
-
context "with all examples passing" do
|
|
1037
|
-
it "returns true" do
|
|
1038
|
-
group = RSpec::Core::ExampleGroup.describe("something") do
|
|
1039
|
-
it "does something" do
|
|
1040
|
-
# pass
|
|
1041
|
-
end
|
|
1042
|
-
describe "nested" do
|
|
1043
|
-
it "does something else" do
|
|
1044
|
-
# pass
|
|
1045
|
-
end
|
|
1046
|
-
end
|
|
1047
|
-
end
|
|
1048
|
-
|
|
1049
|
-
expect(group.run(reporter)).to be_truthy
|
|
1050
|
-
end
|
|
1051
|
-
end
|
|
1052
|
-
|
|
1053
|
-
context "with top level example failing" do
|
|
1054
|
-
it "returns false" do
|
|
1055
|
-
group = RSpec::Core::ExampleGroup.describe("something") do
|
|
1056
|
-
it "does something (wrong - fail)" do
|
|
1057
|
-
raise "fail"
|
|
1058
|
-
end
|
|
1059
|
-
describe "nested" do
|
|
1060
|
-
it "does something else" do
|
|
1061
|
-
# pass
|
|
1062
|
-
end
|
|
1063
|
-
end
|
|
1064
|
-
end
|
|
1065
|
-
|
|
1066
|
-
expect(group.run(reporter)).to be_falsey
|
|
1067
|
-
end
|
|
1068
|
-
end
|
|
1069
|
-
|
|
1070
|
-
context "with nested example failing" do
|
|
1071
|
-
it "returns true" do
|
|
1072
|
-
group = RSpec::Core::ExampleGroup.describe("something") do
|
|
1073
|
-
it "does something" do
|
|
1074
|
-
# pass
|
|
1075
|
-
end
|
|
1076
|
-
describe "nested" do
|
|
1077
|
-
it "does something else (wrong -fail)" do
|
|
1078
|
-
raise "fail"
|
|
1079
|
-
end
|
|
1080
|
-
end
|
|
1081
|
-
end
|
|
1082
|
-
|
|
1083
|
-
expect(group.run(reporter)).to be_falsey
|
|
1084
|
-
end
|
|
1085
|
-
end
|
|
1086
|
-
end
|
|
1087
|
-
|
|
1088
|
-
%w[include_examples include_context].each do |name|
|
|
1089
|
-
describe "##{name}" do
|
|
1090
|
-
let(:group) { ExampleGroup.describe }
|
|
1091
|
-
before do
|
|
1092
|
-
group.shared_examples "named this" do
|
|
1093
|
-
example("does something") {}
|
|
1094
|
-
end
|
|
1095
|
-
end
|
|
1096
|
-
|
|
1097
|
-
it "includes the named examples" do
|
|
1098
|
-
group.send(name, "named this")
|
|
1099
|
-
expect(group.examples.first.description).to eq("does something")
|
|
1100
|
-
end
|
|
1101
|
-
|
|
1102
|
-
it "raises a helpful error message when shared content is not found" do
|
|
1103
|
-
expect do
|
|
1104
|
-
group.send(name, "shared stuff")
|
|
1105
|
-
end.to raise_error(ArgumentError, /Could not find .* "shared stuff"/)
|
|
1106
|
-
end
|
|
1107
|
-
|
|
1108
|
-
it "passes parameters to the shared content" do
|
|
1109
|
-
passed_params = {}
|
|
1110
|
-
group = ExampleGroup.describe
|
|
1111
|
-
|
|
1112
|
-
group.shared_examples "named this with params" do |param1, param2|
|
|
1113
|
-
it("has access to the given parameters") do
|
|
1114
|
-
passed_params[:param1] = param1
|
|
1115
|
-
passed_params[:param2] = param2
|
|
1116
|
-
end
|
|
1117
|
-
end
|
|
1118
|
-
|
|
1119
|
-
group.send(name, "named this with params", :value1, :value2)
|
|
1120
|
-
group.run
|
|
1121
|
-
|
|
1122
|
-
expect(passed_params).to eq({ :param1 => :value1, :param2 => :value2 })
|
|
1123
|
-
end
|
|
1124
|
-
|
|
1125
|
-
it "adds shared instance methods to the group" do
|
|
1126
|
-
group = ExampleGroup.describe('fake group')
|
|
1127
|
-
group.shared_examples "named this with params" do |param1|
|
|
1128
|
-
def foo; end
|
|
1129
|
-
end
|
|
1130
|
-
group.send(name, "named this with params", :a)
|
|
1131
|
-
expect(group.public_instance_methods.map{|m| m.to_s}).to include("foo")
|
|
1132
|
-
end
|
|
1133
|
-
|
|
1134
|
-
it "evals the shared example group only once" do
|
|
1135
|
-
eval_count = 0
|
|
1136
|
-
group = ExampleGroup.describe('fake group')
|
|
1137
|
-
group.shared_examples("named this with params") { |p| eval_count += 1 }
|
|
1138
|
-
group.send(name, "named this with params", :a)
|
|
1139
|
-
expect(eval_count).to eq(1)
|
|
1140
|
-
end
|
|
1141
|
-
|
|
1142
|
-
it "evals the block when given" do
|
|
1143
|
-
key = "#{__FILE__}:#{__LINE__}"
|
|
1144
|
-
group = ExampleGroup.describe do
|
|
1145
|
-
shared_examples(key) do
|
|
1146
|
-
it("does something") do
|
|
1147
|
-
expect(foo).to eq("bar")
|
|
1148
|
-
end
|
|
1149
|
-
end
|
|
1150
|
-
|
|
1151
|
-
send name, key do
|
|
1152
|
-
def foo; "bar"; end
|
|
1153
|
-
end
|
|
1154
|
-
end
|
|
1155
|
-
expect(group.run).to be_truthy
|
|
1156
|
-
end
|
|
1157
|
-
|
|
1158
|
-
it "warns when extra args are submitted to a zero-arity shared block", :if => RUBY_VERSION.to_f >= 1.9 do
|
|
1159
|
-
group = ExampleGroup.describe
|
|
1160
|
-
group.shared_examples("named this") {}
|
|
1161
|
-
|
|
1162
|
-
expect(group).to receive(:warn) {|message|
|
|
1163
|
-
expect(message).to match(/expected 0 args/)
|
|
1164
|
-
expect(message).to match(/called from #{__FILE__}:#{__LINE__ + 2}/)
|
|
1165
|
-
}
|
|
1166
|
-
group.send(name, "named this", "extra arg")
|
|
1167
|
-
end
|
|
1168
|
-
|
|
1169
|
-
it "warns with usage message when 2nd arg is the name of another shared group", :if => RUBY_VERSION.to_f >= 1.9 do
|
|
1170
|
-
group = ExampleGroup.describe
|
|
1171
|
-
group.shared_examples("named this") {}
|
|
1172
|
-
group.shared_examples("named that") {}
|
|
1173
|
-
|
|
1174
|
-
expect(group).to receive(:warn) {|message|
|
|
1175
|
-
expect(message).to match(/shared (context|examples) supports? the name of only one example group, received \["named this", "named that"\]/)
|
|
1176
|
-
expect(message).to match(/called from #{__FILE__}:#{__LINE__ + 2}/)
|
|
1177
|
-
}
|
|
1178
|
-
group.send(name, "named this", "named that")
|
|
1179
|
-
end
|
|
1180
|
-
|
|
1181
|
-
it 'does not warn when the shared example group has a default arg', :if => RUBY_VERSION.to_f >= 1.9 do
|
|
1182
|
-
group = ExampleGroup.describe
|
|
1183
|
-
|
|
1184
|
-
# 1.8.7 can't parse blocks with arg defaults, so we have to eval it
|
|
1185
|
-
# to delay when it is parsed.
|
|
1186
|
-
eval('group.shared_examples("named this") { |opts={}| }')
|
|
1187
|
-
|
|
1188
|
-
expect(group).not_to receive(:warn)
|
|
1189
|
-
|
|
1190
|
-
group.send(name, "named this", :foo => 1)
|
|
1191
|
-
end
|
|
1192
|
-
end
|
|
1193
|
-
end
|
|
1194
|
-
|
|
1195
|
-
describe "#it_should_behave_like" do
|
|
1196
|
-
it "creates a nested group" do
|
|
1197
|
-
group = ExampleGroup.describe('fake group')
|
|
1198
|
-
group.shared_examples_for("thing") {}
|
|
1199
|
-
group.it_should_behave_like("thing")
|
|
1200
|
-
expect(group).to have(1).children
|
|
1201
|
-
end
|
|
1202
|
-
|
|
1203
|
-
it "creates a nested group for a class" do
|
|
1204
|
-
klass = Class.new
|
|
1205
|
-
group = ExampleGroup.describe('fake group')
|
|
1206
|
-
group.shared_examples_for(klass) {}
|
|
1207
|
-
group.it_should_behave_like(klass)
|
|
1208
|
-
expect(group).to have(1).children
|
|
1209
|
-
end
|
|
1210
|
-
|
|
1211
|
-
it "adds shared examples to nested group" do
|
|
1212
|
-
group = ExampleGroup.describe('fake group')
|
|
1213
|
-
group.shared_examples_for("thing") do
|
|
1214
|
-
it("does something")
|
|
1215
|
-
end
|
|
1216
|
-
shared_group = group.it_should_behave_like("thing")
|
|
1217
|
-
expect(shared_group).to have(1).examples
|
|
1218
|
-
end
|
|
1219
|
-
|
|
1220
|
-
it "adds shared instance methods to nested group" do
|
|
1221
|
-
group = ExampleGroup.describe('fake group')
|
|
1222
|
-
group.shared_examples_for("thing") do
|
|
1223
|
-
def foo; end
|
|
1224
|
-
end
|
|
1225
|
-
shared_group = group.it_should_behave_like("thing")
|
|
1226
|
-
expect(shared_group.public_instance_methods.map{|m| m.to_s}).to include("foo")
|
|
1227
|
-
end
|
|
1228
|
-
|
|
1229
|
-
it "adds shared class methods to nested group" do
|
|
1230
|
-
group = ExampleGroup.describe('fake group')
|
|
1231
|
-
group.shared_examples_for("thing") do
|
|
1232
|
-
def self.foo; end
|
|
1233
|
-
end
|
|
1234
|
-
shared_group = group.it_should_behave_like("thing")
|
|
1235
|
-
expect(shared_group.methods.map{|m| m.to_s}).to include("foo")
|
|
1236
|
-
end
|
|
1237
|
-
|
|
1238
|
-
it "passes parameters to the shared example group" do
|
|
1239
|
-
passed_params = {}
|
|
1240
|
-
|
|
1241
|
-
group = ExampleGroup.describe("group") do
|
|
1242
|
-
shared_examples_for("thing") do |param1, param2|
|
|
1243
|
-
it("has access to the given parameters") do
|
|
1244
|
-
passed_params[:param1] = param1
|
|
1245
|
-
passed_params[:param2] = param2
|
|
1246
|
-
end
|
|
1247
|
-
end
|
|
1248
|
-
|
|
1249
|
-
it_should_behave_like "thing", :value1, :value2
|
|
1250
|
-
end
|
|
1251
|
-
|
|
1252
|
-
group.run
|
|
1253
|
-
|
|
1254
|
-
expect(passed_params).to eq({ :param1 => :value1, :param2 => :value2 })
|
|
1255
|
-
end
|
|
1256
|
-
|
|
1257
|
-
it "adds shared instance methods to nested group" do
|
|
1258
|
-
group = ExampleGroup.describe('fake group')
|
|
1259
|
-
group.shared_examples_for("thing") do |param1|
|
|
1260
|
-
def foo; end
|
|
1261
|
-
end
|
|
1262
|
-
shared_group = group.it_should_behave_like("thing", :a)
|
|
1263
|
-
expect(shared_group.public_instance_methods.map{|m| m.to_s}).to include("foo")
|
|
1264
|
-
end
|
|
1265
|
-
|
|
1266
|
-
it "evals the shared example group only once" do
|
|
1267
|
-
eval_count = 0
|
|
1268
|
-
group = ExampleGroup.describe('fake group')
|
|
1269
|
-
group.shared_examples_for("thing") { |p| eval_count += 1 }
|
|
1270
|
-
group.it_should_behave_like("thing", :a)
|
|
1271
|
-
expect(eval_count).to eq(1)
|
|
1272
|
-
end
|
|
1273
|
-
|
|
1274
|
-
context "given a block" do
|
|
1275
|
-
it "evaluates the block in nested group" do
|
|
1276
|
-
scopes = []
|
|
1277
|
-
group = ExampleGroup.describe("group") do
|
|
1278
|
-
shared_examples_for("thing") do
|
|
1279
|
-
it("gets run in the nested group") do
|
|
1280
|
-
scopes << self.class
|
|
1281
|
-
end
|
|
1282
|
-
end
|
|
1283
|
-
it_should_behave_like "thing" do
|
|
1284
|
-
it("gets run in the same nested group") do
|
|
1285
|
-
scopes << self.class
|
|
1286
|
-
end
|
|
1287
|
-
end
|
|
1288
|
-
end
|
|
1289
|
-
group.run
|
|
1290
|
-
|
|
1291
|
-
expect(scopes[0]).to be(scopes[1])
|
|
1292
|
-
end
|
|
1293
|
-
end
|
|
1294
|
-
|
|
1295
|
-
it "raises a helpful error message when shared context is not found" do
|
|
1296
|
-
expect do
|
|
1297
|
-
ExampleGroup.describe do
|
|
1298
|
-
it_should_behave_like "shared stuff"
|
|
1299
|
-
end
|
|
1300
|
-
end.to raise_error(ArgumentError,%q|Could not find shared examples "shared stuff"|)
|
|
1301
|
-
end
|
|
1302
|
-
end
|
|
1303
|
-
|
|
1304
|
-
describe "deprecated methods" do
|
|
1305
|
-
specify ".describes is deprecated" do
|
|
1306
|
-
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /describes/)
|
|
1307
|
-
expect(self.class.describes).to eq(self.class.described_class)
|
|
1308
|
-
end
|
|
1309
|
-
|
|
1310
|
-
specify ".display_name is deprecated" do
|
|
1311
|
-
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /display_name/)
|
|
1312
|
-
expect(self.class.display_name).to eq(self.class.description)
|
|
1313
|
-
end
|
|
1314
|
-
|
|
1315
|
-
specify ".alias_it_behaves_like_to is deprecated" do
|
|
1316
|
-
expect_deprecation_with_call_site(__FILE__, __LINE__ + 2, /alias_it_behaves_like_to/)
|
|
1317
|
-
expect {
|
|
1318
|
-
ExampleGroup.alias_it_behaves_like_to(:it_does_something, "it does something")
|
|
1319
|
-
}.to change { ExampleGroup.respond_to?(:it_does_something) }.from(false).to(true)
|
|
1320
|
-
end
|
|
1321
|
-
|
|
1322
|
-
specify ".alias_example_to is deprecated" do
|
|
1323
|
-
expect_deprecation_with_call_site(__FILE__, __LINE__ + 2, /alias_example_to/)
|
|
1324
|
-
expect {
|
|
1325
|
-
ExampleGroup.alias_example_to(:an_example)
|
|
1326
|
-
}.to change { ExampleGroup.respond_to?(:an_example) }.from(false).to(true)
|
|
1327
|
-
end
|
|
1328
|
-
|
|
1329
|
-
specify ".focused is deprecated" do
|
|
1330
|
-
expect_deprecation_with_call_site(__FILE__, __LINE__ + 2, /focused/)
|
|
1331
|
-
ExampleGroup.describe("group") do
|
|
1332
|
-
focused("example") { }
|
|
1333
|
-
end
|
|
1334
|
-
end
|
|
1335
|
-
end
|
|
1336
|
-
end
|
|
1337
|
-
end
|