rspec-core 2.99.2 → 3.0.0.beta1
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 +14 -6
- checksums.yaml.gz.sig +2 -0
- data.tar.gz.sig +0 -0
- data/Changelog.md +103 -191
- data/License.txt +1 -0
- data/README.md +4 -25
- data/features/Upgrade.md +2 -14
- data/features/command_line/dry_run.feature +29 -0
- data/features/command_line/example_name_option.feature +1 -1
- data/features/command_line/fail_fast.feature +26 -0
- data/features/command_line/format_option.feature +3 -3
- data/features/command_line/line_number_option.feature +16 -11
- data/features/command_line/order.feature +2 -3
- data/features/command_line/pattern_option.feature +3 -3
- data/features/command_line/randomization.feature +63 -0
- data/features/command_line/require_option.feature +2 -2
- data/features/command_line/ruby.feature +1 -1
- data/features/configuration/alias_example_to.feature +13 -22
- data/features/configuration/{backtrace_clean_patterns.feature → backtrace_exclusion_patterns.feature} +17 -14
- data/features/configuration/custom_settings.feature +11 -11
- data/features/configuration/overriding_global_ordering.feature +93 -0
- data/features/configuration/profile.feature +13 -13
- data/features/configuration/read_options_from_file.feature +7 -7
- data/features/example_groups/basic_structure.feature +1 -1
- data/features/example_groups/shared_context.feature +8 -8
- data/features/example_groups/shared_examples.feature +6 -14
- data/features/expectation_framework_integration/configure_expectation_framework.feature +27 -122
- data/features/filtering/exclusion_filters.feature +2 -5
- data/features/filtering/inclusion_filters.feature +1 -5
- data/features/formatters/json_formatter.feature +2 -2
- data/features/formatters/text_formatter.feature +4 -4
- data/features/helper_methods/arbitrary_methods.feature +2 -2
- data/features/helper_methods/let.feature +5 -5
- data/features/helper_methods/modules.feature +5 -8
- data/features/hooks/around_hooks.feature +2 -2
- data/features/hooks/before_and_after_hooks.feature +14 -14
- data/features/hooks/filtering.feature +12 -14
- data/features/metadata/described_class.feature +1 -1
- data/features/metadata/user_defined.feature +16 -29
- data/features/mock_framework_integration/use_flexmock.feature +1 -1
- data/features/mock_framework_integration/use_mocha.feature +1 -1
- data/features/mock_framework_integration/use_rr.feature +1 -1
- data/features/mock_framework_integration/use_rspec.feature +5 -5
- data/features/pending/pending_examples.feature +5 -5
- data/features/spec_files/arbitrary_file_suffix.feature +1 -1
- data/features/step_definitions/additional_cli_steps.rb +3 -3
- data/features/subject/explicit_subject.feature +8 -8
- data/features/subject/implicit_receiver.feature +29 -0
- data/features/subject/implicit_subject.feature +4 -4
- data/features/support/env.rb +10 -3
- data/features/support/require_expect_syntax_in_aruba_specs.rb +16 -0
- data/lib/rspec/core.rb +11 -48
- data/lib/rspec/core/backport_random.rb +302 -0
- data/lib/rspec/core/backtrace_formatter.rb +65 -0
- data/lib/rspec/core/command_line.rb +7 -18
- data/lib/rspec/core/configuration.rb +202 -507
- data/lib/rspec/core/configuration_options.rb +17 -30
- data/lib/rspec/core/example.rb +29 -39
- data/lib/rspec/core/example_group.rb +166 -259
- data/lib/rspec/core/filter_manager.rb +30 -47
- data/lib/rspec/core/flat_map.rb +17 -0
- data/lib/rspec/core/formatters.rb +0 -138
- data/lib/rspec/core/formatters/base_formatter.rb +46 -1
- data/lib/rspec/core/formatters/base_text_formatter.rb +38 -61
- data/lib/rspec/core/formatters/deprecation_formatter.rb +21 -52
- data/lib/rspec/core/formatters/helpers.rb +0 -28
- data/lib/rspec/core/formatters/html_formatter.rb +1 -1
- data/lib/rspec/core/formatters/json_formatter.rb +38 -9
- data/lib/rspec/core/formatters/snippet_extractor.rb +14 -5
- data/lib/rspec/core/hooks.rb +55 -39
- data/lib/rspec/core/memoized_helpers.rb +17 -167
- data/lib/rspec/core/metadata.rb +16 -64
- data/lib/rspec/core/option_parser.rb +30 -39
- data/lib/rspec/core/ordering.rb +154 -0
- data/lib/rspec/core/pending.rb +12 -69
- data/lib/rspec/core/project_initializer.rb +12 -10
- data/lib/rspec/core/rake_task.rb +5 -108
- data/lib/rspec/core/reporter.rb +15 -18
- data/lib/rspec/core/runner.rb +16 -30
- data/lib/rspec/core/shared_context.rb +3 -5
- data/lib/rspec/core/shared_example_group.rb +3 -51
- data/lib/rspec/core/shared_example_group/collection.rb +1 -19
- data/lib/rspec/core/version.rb +1 -1
- data/lib/rspec/core/warnings.rb +22 -0
- data/lib/rspec/core/world.rb +12 -8
- data/spec/command_line/order_spec.rb +20 -23
- data/spec/rspec/core/backtrace_formatter_spec.rb +216 -0
- data/spec/rspec/core/command_line_spec.rb +32 -48
- data/spec/rspec/core/configuration_options_spec.rb +19 -50
- data/spec/rspec/core/configuration_spec.rb +142 -713
- data/spec/rspec/core/drb_command_line_spec.rb +2 -0
- data/spec/rspec/core/dsl_spec.rb +0 -1
- data/spec/rspec/core/example_group_spec.rb +192 -223
- data/spec/rspec/core/example_spec.rb +40 -16
- data/spec/rspec/core/filter_manager_spec.rb +2 -2
- data/spec/rspec/core/formatters/base_formatter_spec.rb +0 -41
- data/spec/rspec/core/formatters/base_text_formatter_spec.rb +5 -123
- data/spec/rspec/core/formatters/deprecation_formatter_spec.rb +2 -87
- data/spec/rspec/core/formatters/documentation_formatter_spec.rb +2 -3
- data/spec/rspec/core/formatters/{text_mate_formatted.html → html_formatted-1.8.7-jruby.html} +44 -25
- data/spec/rspec/core/formatters/html_formatted-1.8.7-rbx.html +477 -0
- data/spec/rspec/core/formatters/{html_formatted.html → html_formatted-1.8.7.html} +42 -25
- data/spec/rspec/core/formatters/html_formatted-1.9.2.html +425 -0
- data/spec/rspec/core/formatters/html_formatted-1.9.3-jruby.html +416 -0
- data/spec/rspec/core/formatters/html_formatted-1.9.3-rbx.html +477 -0
- data/spec/rspec/core/formatters/html_formatted-1.9.3.html +419 -0
- data/spec/rspec/core/formatters/html_formatted-2.0.0.html +425 -0
- data/spec/rspec/core/formatters/html_formatter_spec.rb +21 -46
- data/spec/rspec/core/formatters/json_formatter_spec.rb +97 -8
- data/spec/rspec/core/hooks_filtering_spec.rb +5 -5
- data/spec/rspec/core/hooks_spec.rb +61 -47
- data/spec/rspec/core/memoized_helpers_spec.rb +20 -322
- data/spec/rspec/core/metadata_spec.rb +1 -24
- data/spec/rspec/core/option_parser_spec.rb +20 -62
- data/spec/rspec/core/ordering_spec.rb +102 -0
- data/spec/rspec/core/pending_example_spec.rb +0 -40
- data/spec/rspec/core/project_initializer_spec.rb +1 -25
- data/spec/rspec/core/rake_task_spec.rb +5 -72
- data/spec/rspec/core/random_spec.rb +47 -0
- data/spec/rspec/core/reporter_spec.rb +23 -48
- data/spec/rspec/core/runner_spec.rb +31 -39
- data/spec/rspec/core/shared_context_spec.rb +3 -15
- data/spec/rspec/core/shared_example_group/collection_spec.rb +4 -17
- data/spec/rspec/core/shared_example_group_spec.rb +12 -45
- data/spec/rspec/core/{deprecation_spec.rb → warnings_spec.rb} +3 -1
- data/spec/rspec/core_spec.rb +4 -21
- data/spec/spec_helper.rb +41 -5
- data/spec/support/helper_methods.rb +0 -29
- data/spec/support/sandboxed_mock_space.rb +0 -16
- data/spec/support/shared_example_groups.rb +7 -36
- data/spec/support/stderr_splitter.rb +36 -0
- metadata +163 -157
- metadata.gz.sig +1 -0
- data/exe/autospec +0 -13
- data/features/Autotest.md +0 -38
- data/features/configuration/treat_symbols_as_metadata_keys_with_true_values.feature +0 -52
- data/features/subject/attribute_of_subject.feature +0 -124
- data/features/subject/one_liner_syntax.feature +0 -71
- 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/deprecated_mutable_array_proxy.rb +0 -32
- data/lib/rspec/core/deprecation.rb +0 -26
- 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/console_codes.rb +0 -42
- 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/minitest_assertions_adapter.rb +0 -28
- data/lib/rspec/core/test_unit_assertions_adapter.rb +0 -30
- 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/rspec/core/backtrace_cleaner_spec.rb +0 -68
- data/spec/rspec/core/caller_filter_spec.rb +0 -58
- data/spec/rspec/core/deprecations_spec.rb +0 -59
- data/spec/rspec/core/formatters/console_codes_spec.rb +0 -50
- data/spec/rspec/core/formatters/text_mate_formatter_spec.rb +0 -107
- data/spec/rspec/core/kernel_extensions_spec.rb +0 -9
- data/spec/rspec/core/pending_spec.rb +0 -27
- data/spec/support/silence_dsl_deprecations.rb +0 -32
|
@@ -6,46 +6,32 @@ require 'nokogiri'
|
|
|
6
6
|
module RSpec
|
|
7
7
|
module Core
|
|
8
8
|
module Formatters
|
|
9
|
-
describe HtmlFormatter do
|
|
9
|
+
describe HtmlFormatter, :if => RUBY_VERSION =~ /^(1.8.7|1.9.2|1.9.3|2.0.0)$/ do
|
|
10
|
+
let(:suffix) {
|
|
11
|
+
if ::RUBY_PLATFORM == 'java'
|
|
12
|
+
"-jruby"
|
|
13
|
+
elsif defined?(Rubinius)
|
|
14
|
+
"-rbx"
|
|
15
|
+
else
|
|
16
|
+
""
|
|
17
|
+
end
|
|
18
|
+
}
|
|
10
19
|
|
|
11
20
|
let(:root) { File.expand_path("#{File.dirname(__FILE__)}/../../../..") }
|
|
12
21
|
let(:expected_file) do
|
|
13
|
-
"#{File.dirname(__FILE__)}/html_formatted.html"
|
|
22
|
+
"#{File.dirname(__FILE__)}/html_formatted-#{::RUBY_VERSION}#{suffix}.html"
|
|
14
23
|
end
|
|
15
24
|
|
|
16
25
|
let(:generated_html) do
|
|
17
|
-
options =
|
|
18
|
-
%w[spec/rspec/core/resources/formatter_specs.rb --format html --order defined]
|
|
19
|
-
)
|
|
20
|
-
options.parse_options
|
|
26
|
+
options = %w[spec/rspec/core/resources/formatter_specs.rb --format html --order defined]
|
|
21
27
|
|
|
22
28
|
err, out = StringIO.new, StringIO.new
|
|
23
29
|
err.set_encoding("utf-8") if err.respond_to?(:set_encoding)
|
|
24
|
-
out.set_encoding("utf-8") if out.respond_to?(:set_encoding)
|
|
25
|
-
|
|
26
|
-
runner = RSpec::Core::Runner.new(options)
|
|
27
|
-
configuration = runner.instance_variable_get(:@configuration)
|
|
28
|
-
|
|
29
|
-
configuration.backtrace_formatter.inclusion_patterns = []
|
|
30
|
-
configuration.output_stream = out
|
|
31
|
-
configuration.deprecation_stream = err
|
|
32
|
-
|
|
33
|
-
runner.run(err, out)
|
|
34
|
-
|
|
35
|
-
html = out.string.gsub(/\d+\.\d+(s| seconds)/, "n.nnnn\\1")
|
|
36
30
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
backtrace = elem.inner_html.lines.
|
|
42
|
-
select {|e| e =~ /formatter_specs\.rb/ }.
|
|
43
|
-
map {|x| x.chomp.split(":")[0..1].join(':') }.
|
|
44
|
-
join("\n")
|
|
45
|
-
|
|
46
|
-
elem.inner_html = backtrace
|
|
47
|
-
end
|
|
48
|
-
actual_doc.inner_html
|
|
31
|
+
command_line = RSpec::Core::CommandLine.new(options)
|
|
32
|
+
command_line.instance_variable_get("@configuration").backtrace_formatter.inclusion_patterns = []
|
|
33
|
+
command_line.run(err, out)
|
|
34
|
+
out.string.gsub(/\d+\.\d+(s| seconds)/, "n.nnnn\\1")
|
|
49
35
|
end
|
|
50
36
|
|
|
51
37
|
let(:expected_html) do
|
|
@@ -56,7 +42,7 @@ module RSpec
|
|
|
56
42
|
end
|
|
57
43
|
|
|
58
44
|
before do
|
|
59
|
-
RSpec.configuration.
|
|
45
|
+
allow(RSpec.configuration).to receive(:load_spec_files) do
|
|
60
46
|
RSpec.configuration.files_to_run.map {|f| load File.expand_path(f) }
|
|
61
47
|
end
|
|
62
48
|
end
|
|
@@ -78,18 +64,7 @@ module RSpec
|
|
|
78
64
|
select {|e| e =~ /formatter_specs\.rb/}
|
|
79
65
|
end
|
|
80
66
|
|
|
81
|
-
describe 'produced HTML'
|
|
82
|
-
# Rubies before 2 are a wild west of different outputs, and it's not
|
|
83
|
-
# worth the effort to maintain accurate fixtures for all of them.
|
|
84
|
-
# Since we are verifying fixtures on other rubies, if this code at
|
|
85
|
-
# least runs we can be reasonably confident the output is right since
|
|
86
|
-
# behaviour variances that we care about across versions is neglible.
|
|
87
|
-
it 'is present' do
|
|
88
|
-
expect(generated_html).to be
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
describe 'produced HTML', :slow, :if => RUBY_VERSION >= '2.0.0' do
|
|
67
|
+
describe 'produced HTML' do
|
|
93
68
|
def build_and_verify_formatter_output
|
|
94
69
|
Dir.chdir(root) do
|
|
95
70
|
actual_doc = Nokogiri::HTML(generated_html)
|
|
@@ -113,15 +88,15 @@ module RSpec
|
|
|
113
88
|
end
|
|
114
89
|
end
|
|
115
90
|
|
|
116
|
-
it "
|
|
91
|
+
it "produces HTML identical to the one we designed manually" do
|
|
117
92
|
build_and_verify_formatter_output
|
|
118
93
|
end
|
|
119
94
|
|
|
120
95
|
context 'with mathn loaded' do
|
|
121
96
|
include MathnIntegrationSupport
|
|
122
97
|
|
|
123
|
-
it "
|
|
124
|
-
with_mathn_loaded
|
|
98
|
+
it "produces HTML identical to the one we designed manually" do
|
|
99
|
+
with_mathn_loaded{ build_and_verify_formatter_output }
|
|
125
100
|
end
|
|
126
101
|
end
|
|
127
102
|
end
|
|
@@ -14,7 +14,8 @@ require 'rspec/core/reporter'
|
|
|
14
14
|
describe RSpec::Core::Formatters::JsonFormatter do
|
|
15
15
|
let(:output) { StringIO.new }
|
|
16
16
|
let(:formatter) { RSpec::Core::Formatters::JsonFormatter.new(output) }
|
|
17
|
-
let(:
|
|
17
|
+
let(:config) { RSpec::Core::Configuration.new }
|
|
18
|
+
let(:reporter) { RSpec::Core::Reporter.new(config, formatter) }
|
|
18
19
|
|
|
19
20
|
it "outputs json (brittle high level functional test)" do
|
|
20
21
|
group = RSpec::Core::ExampleGroup.describe("one apiece") do
|
|
@@ -97,19 +98,107 @@ describe RSpec::Core::Formatters::JsonFormatter do
|
|
|
97
98
|
|
|
98
99
|
describe "#dump_summary" do
|
|
99
100
|
it "adds summary info to the output hash" do
|
|
100
|
-
|
|
101
|
-
formatter.dump_summary(duration, example_count, failure_count, pending_count)
|
|
101
|
+
values = { :duration => 1.0, :example_count => 2, :failure_count => 1, :pending_count => 1 }
|
|
102
|
+
formatter.dump_summary(values[:duration], values[:example_count], values[:failure_count], values[:pending_count])
|
|
102
103
|
summary = formatter.output_hash[:summary]
|
|
103
|
-
|
|
104
|
-
expect(summary[key
|
|
104
|
+
values.each do |key,value|
|
|
105
|
+
expect(summary[key]).to eq value
|
|
105
106
|
end
|
|
106
107
|
summary_line = formatter.output_hash[:summary_line]
|
|
107
108
|
expect(summary_line).to eq "2 examples, 1 failure, 1 pending"
|
|
108
109
|
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
describe "#dump_profile_slowest_examples" do
|
|
113
|
+
|
|
114
|
+
before do
|
|
115
|
+
group = RSpec::Core::ExampleGroup.describe("group") do
|
|
116
|
+
# Use a sleep so there is some measurable time, to ensure
|
|
117
|
+
# the reported percent is 100%, not 0%.
|
|
118
|
+
example("example") { sleep 0.001 }
|
|
119
|
+
end
|
|
120
|
+
group.run(double('reporter').as_null_object)
|
|
121
|
+
|
|
122
|
+
formatter.stub(:examples) { group.examples }
|
|
123
|
+
RSpec.configuration.stub(:profile_examples) { 10 }
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
it "names the example" do
|
|
127
|
+
formatter.dump_profile_slowest_examples
|
|
128
|
+
expect(formatter.output_hash[:profile][:examples].first[:full_description]).to eq("group example")
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
it "provides example execution time" do
|
|
132
|
+
formatter.dump_profile_slowest_examples
|
|
133
|
+
expect(formatter.output_hash[:profile][:examples].first[:run_time]).not_to be_nil
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
it "has the summary of profile information" do
|
|
137
|
+
formatter.dump_profile_slowest_examples
|
|
138
|
+
expect(formatter.output_hash[:profile].keys).to match_array([:examples, :slowest, :total])
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
describe "#dump_profile_slowest_example_groups" do
|
|
143
|
+
let(:group) do
|
|
144
|
+
RSpec::Core::ExampleGroup.describe("slow group") do
|
|
145
|
+
# Use a sleep so there is some measurable time, to ensure
|
|
146
|
+
# the reported percent is 100%, not 0%.
|
|
147
|
+
example("example") { sleep 0.01 }
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
let(:rpt) { double('reporter').as_null_object }
|
|
151
|
+
|
|
152
|
+
before do
|
|
153
|
+
RSpec.configuration.stub(:profile_examples) { 10 }
|
|
154
|
+
group.run(rpt)
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
context "with one example group" do
|
|
158
|
+
before { formatter.stub(:examples) { group.examples } }
|
|
159
|
+
|
|
160
|
+
it "doesn't profile a single example group" do
|
|
161
|
+
formatter.dump_profile_slowest_example_groups
|
|
162
|
+
expect(formatter.output_hash[:profile][:groups]).to be_empty
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
context "with multiple example groups" do
|
|
167
|
+
before do
|
|
168
|
+
group2 = RSpec::Core::ExampleGroup.describe("fast group") do
|
|
169
|
+
example("example 1") { sleep 0.004 }
|
|
170
|
+
example("example 2") { sleep 0.007 }
|
|
171
|
+
end
|
|
172
|
+
group2.run(rpt)
|
|
173
|
+
|
|
174
|
+
formatter.stub(:examples) { group.examples + group2.examples }
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
it "provides the slowest example groups" do
|
|
178
|
+
formatter.dump_profile_slowest_example_groups
|
|
179
|
+
expect(formatter.output_hash).not_to be_empty
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
it "provides information" do
|
|
183
|
+
formatter.dump_profile_slowest_example_groups
|
|
184
|
+
expect(formatter.output_hash[:profile][:groups].first.keys).to match_array([:total_time, :count, :description, :average, :location])
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
it "ranks the example groups by average time" do
|
|
188
|
+
formatter.dump_profile_slowest_example_groups
|
|
189
|
+
expect(formatter.output_hash[:profile][:groups].first[:description]).to eq("slow group")
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
it "depends on parent_groups to get the top level example group" do
|
|
194
|
+
ex = ""
|
|
195
|
+
group.describe("group 2") do
|
|
196
|
+
describe "group 3" do
|
|
197
|
+
ex = example("nested example 1")
|
|
198
|
+
end
|
|
199
|
+
end
|
|
109
200
|
|
|
110
|
-
|
|
111
|
-
allow(RSpec.configuration).to receive(:profile_examples).and_return(true)
|
|
112
|
-
formatter.dump_summary(1.0, 2, 1, 1)
|
|
201
|
+
expect(ex.example_group.parent_groups.last).to eq(group)
|
|
113
202
|
end
|
|
114
203
|
end
|
|
115
204
|
end
|
|
@@ -35,7 +35,7 @@ module RSpec::Core
|
|
|
35
35
|
c.before(:match => true) { filters << "before each in config"}
|
|
36
36
|
c.after(:match => true) { filters << "after each in config"}
|
|
37
37
|
end
|
|
38
|
-
group = ExampleGroup.describe(
|
|
38
|
+
group = ExampleGroup.describe(:match => true)
|
|
39
39
|
group.example("example") {}
|
|
40
40
|
group.run
|
|
41
41
|
expect(filters).to eq([
|
|
@@ -55,7 +55,7 @@ module RSpec::Core
|
|
|
55
55
|
c.after(:each, :match => true) { filters << "after each in config"}
|
|
56
56
|
c.after(:all, :match => true) { filters << "after all in config"}
|
|
57
57
|
end
|
|
58
|
-
group = ExampleGroup.describe(
|
|
58
|
+
group = ExampleGroup.describe(:match => true)
|
|
59
59
|
group.example("example") {}
|
|
60
60
|
group.run
|
|
61
61
|
expect(filters).to eq([
|
|
@@ -125,7 +125,7 @@ module RSpec::Core
|
|
|
125
125
|
c.after(:each, :match => false) { filters << "after each in config"}
|
|
126
126
|
c.after(:all, :match => false) { filters << "after all in config"}
|
|
127
127
|
end
|
|
128
|
-
group = ExampleGroup.describe(
|
|
128
|
+
group = ExampleGroup.describe(:match => true)
|
|
129
129
|
group.example("example") {}
|
|
130
130
|
group.run
|
|
131
131
|
expect(filters).to eq([])
|
|
@@ -196,7 +196,7 @@ module RSpec::Core
|
|
|
196
196
|
c.after(:each, :one => 1, :two => 2, :three => 3) { filters << "after each in config"}
|
|
197
197
|
c.after(:all, :one => 1, :three => 3) { filters << "after all in config"}
|
|
198
198
|
end
|
|
199
|
-
group = ExampleGroup.describe(
|
|
199
|
+
group = ExampleGroup.describe(:one => 1, :two => 2, :three => 3)
|
|
200
200
|
group.example("example") {}
|
|
201
201
|
group.run
|
|
202
202
|
expect(filters).to eq([
|
|
@@ -217,7 +217,7 @@ module RSpec::Core
|
|
|
217
217
|
c.after(:each, :one => 1, :two => 2, :three => 3, :four => 4) { filters << "after each in config"}
|
|
218
218
|
c.after(:all, :one => 1, :three => 3, :four => 4) { filters << "after all in config"}
|
|
219
219
|
end
|
|
220
|
-
group = ExampleGroup.describe(
|
|
220
|
+
group = ExampleGroup.describe(:one => 1, :two => 2, :three => 3)
|
|
221
221
|
group.example("example") {}
|
|
222
222
|
group.run
|
|
223
223
|
expect(filters).to eq([])
|
|
@@ -4,6 +4,10 @@ module RSpec::Core
|
|
|
4
4
|
describe Hooks do
|
|
5
5
|
class HooksHost
|
|
6
6
|
include Hooks
|
|
7
|
+
|
|
8
|
+
def parent_groups
|
|
9
|
+
[]
|
|
10
|
+
end
|
|
7
11
|
end
|
|
8
12
|
|
|
9
13
|
[:before, :after, :around].each do |type|
|
|
@@ -22,61 +26,51 @@ module RSpec::Core
|
|
|
22
26
|
end
|
|
23
27
|
end
|
|
24
28
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
before(:each) do
|
|
28
|
-
Kernel.stub(:warn)
|
|
29
|
-
allow_deprecation unless config_value
|
|
30
|
-
RSpec.configure { |c| c.treat_symbols_as_metadata_keys_with_true_values = config_value }
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
describe "##{type}(no scope)" do
|
|
34
|
-
let(:instance) { HooksHost.new }
|
|
29
|
+
describe "##{type}(no scope)" do
|
|
30
|
+
let(:instance) { HooksHost.new }
|
|
35
31
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
32
|
+
it "defaults to :each scope if no arguments are given" do
|
|
33
|
+
hooks = instance.send(type) {}
|
|
34
|
+
hook = hooks.first
|
|
35
|
+
expect(instance.hooks[type][:each]).to include(hook)
|
|
36
|
+
end
|
|
41
37
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
38
|
+
it "defaults to :each scope if the only argument is a metadata hash" do
|
|
39
|
+
hooks = instance.send(type, :foo => :bar) {}
|
|
40
|
+
hook = hooks.first
|
|
41
|
+
expect(instance.hooks[type][:each]).to include(hook)
|
|
42
|
+
end
|
|
47
43
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
end
|
|
51
|
-
end
|
|
44
|
+
it "raises an error if only metadata symbols are given as arguments" do
|
|
45
|
+
expect { instance.send(type, :foo, :bar) {} }.to raise_error(ArgumentError)
|
|
52
46
|
end
|
|
53
47
|
end
|
|
54
48
|
end
|
|
55
49
|
|
|
56
50
|
[:before, :after].each do |type|
|
|
57
51
|
[:each, :all, :suite].each do |scope|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
52
|
+
describe "##{type}(#{scope.inspect})" do
|
|
53
|
+
let(:instance) { HooksHost.new }
|
|
54
|
+
let!(:hook) do
|
|
55
|
+
hooks = instance.send(type, scope) {}
|
|
56
|
+
hooks.first
|
|
57
|
+
end
|
|
64
58
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
hooks = instance.send(type, scope) {}
|
|
69
|
-
hooks.first
|
|
70
|
-
end
|
|
59
|
+
it "does not make #{scope.inspect} a metadata key" do
|
|
60
|
+
expect(hook.options).to be_empty
|
|
61
|
+
end
|
|
71
62
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
63
|
+
it "is scoped to #{scope.inspect}" do
|
|
64
|
+
expect(instance.hooks[type][scope]).to include(hook)
|
|
65
|
+
end
|
|
75
66
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
67
|
+
it 'does not run when in dry run mode' do
|
|
68
|
+
RSpec.configuration.dry_run = true
|
|
69
|
+
|
|
70
|
+
expect { |b|
|
|
71
|
+
instance.send(type, scope, &b)
|
|
72
|
+
instance.run_hook(type, scope)
|
|
73
|
+
}.not_to yield_control
|
|
80
74
|
end
|
|
81
75
|
end
|
|
82
76
|
end
|
|
@@ -87,14 +81,14 @@ module RSpec::Core
|
|
|
87
81
|
it "does not run the example" do
|
|
88
82
|
examples = []
|
|
89
83
|
group = ExampleGroup.describe do
|
|
90
|
-
around do
|
|
84
|
+
around do
|
|
91
85
|
end
|
|
92
86
|
it "foo" do
|
|
93
87
|
examples << self
|
|
94
88
|
end
|
|
95
89
|
end
|
|
96
90
|
group.run
|
|
97
|
-
expect(examples).to
|
|
91
|
+
expect(examples).to eq([])
|
|
98
92
|
end
|
|
99
93
|
end
|
|
100
94
|
|
|
@@ -110,7 +104,26 @@ module RSpec::Core
|
|
|
110
104
|
end
|
|
111
105
|
end
|
|
112
106
|
group.run
|
|
113
|
-
expect(examples).to
|
|
107
|
+
expect(examples.count).to eq(1)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
it "exposes example metadata to each around hook" do
|
|
111
|
+
foos = {}
|
|
112
|
+
group = ExampleGroup.describe do
|
|
113
|
+
around do |ex|
|
|
114
|
+
foos[:first] = ex.metadata[:foo]
|
|
115
|
+
ex.run
|
|
116
|
+
end
|
|
117
|
+
around do |ex|
|
|
118
|
+
foos[:second] = ex.metadata[:foo]
|
|
119
|
+
ex.run
|
|
120
|
+
end
|
|
121
|
+
it "does something", :foo => :bar do
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
group.run
|
|
126
|
+
expect(foos).to eq({:first => :bar, :second => :bar})
|
|
114
127
|
end
|
|
115
128
|
end
|
|
116
129
|
|
|
@@ -125,12 +138,13 @@ module RSpec::Core
|
|
|
125
138
|
around do |example|
|
|
126
139
|
yielder { example.run }
|
|
127
140
|
end
|
|
141
|
+
|
|
128
142
|
it "foo" do
|
|
129
143
|
examples << self
|
|
130
144
|
end
|
|
131
145
|
end
|
|
132
146
|
group.run
|
|
133
|
-
expect(examples).to
|
|
147
|
+
expect(examples.count).to eq(1)
|
|
134
148
|
end
|
|
135
149
|
end
|
|
136
150
|
end
|
|
@@ -37,44 +37,6 @@ module RSpec::Core
|
|
|
37
37
|
end
|
|
38
38
|
end
|
|
39
39
|
|
|
40
|
-
describe "with a symbol" do
|
|
41
|
-
it "returns the string form and issues a deprecation warning" do
|
|
42
|
-
the_subject = :unset
|
|
43
|
-
deprecations = []
|
|
44
|
-
allow(RSpec).to receive(:warn_deprecation) { |msg| deprecations << msg }
|
|
45
|
-
|
|
46
|
-
line = __LINE__ + 1
|
|
47
|
-
ExampleGroup.describe :symbol do
|
|
48
|
-
example { the_subject = subject }
|
|
49
|
-
end.run
|
|
50
|
-
|
|
51
|
-
expect(the_subject).to eq("symbol")
|
|
52
|
-
expect(deprecations.size).to eq(1)
|
|
53
|
-
deprecation = deprecations.first
|
|
54
|
-
expect(deprecation).to match(/describe <a Symbol>/)
|
|
55
|
-
expect(deprecation).to include("#{__FILE__}:#{line}")
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
describe "with a hash" do
|
|
60
|
-
it "returns a blank string and issues a deprecation warning" do
|
|
61
|
-
the_subject = :unset
|
|
62
|
-
deprecations = []
|
|
63
|
-
allow(RSpec).to receive(:warn_deprecation) { |msg| deprecations << msg }
|
|
64
|
-
|
|
65
|
-
line = __LINE__ + 1
|
|
66
|
-
ExampleGroup.describe :foo => 3 do
|
|
67
|
-
example { the_subject = subject }
|
|
68
|
-
end.run
|
|
69
|
-
|
|
70
|
-
expect(the_subject).to eq("")
|
|
71
|
-
expect(deprecations.size).to eq(1)
|
|
72
|
-
deprecation = deprecations.first
|
|
73
|
-
expect(deprecation).to match(/describe <a Hash>/)
|
|
74
|
-
expect(deprecation).to include("#{__FILE__}:#{line}")
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
|
|
78
40
|
it "can be overriden and super'd to from a nested group" do
|
|
79
41
|
outer_subject_value = inner_subject_value = nil
|
|
80
42
|
|
|
@@ -106,18 +68,6 @@ module RSpec::Core
|
|
|
106
68
|
expect(example_yielded_to_subject).to eq example_yielded_to_example
|
|
107
69
|
end
|
|
108
70
|
|
|
109
|
-
context "doesn't issue a deprecation when used with doubles" do
|
|
110
|
-
subject do
|
|
111
|
-
Struct.new(:value) do
|
|
112
|
-
def working_with?(double)
|
|
113
|
-
double.value >= value
|
|
114
|
-
end
|
|
115
|
-
end.new 1
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
it { should be_working_with double(:value => 10) }
|
|
119
|
-
end
|
|
120
|
-
|
|
121
71
|
[false, nil].each do |falsy_value|
|
|
122
72
|
context "with a value of #{falsy_value.inspect}" do
|
|
123
73
|
it "is evaluated once per example" do
|
|
@@ -183,64 +133,19 @@ module RSpec::Core
|
|
|
183
133
|
expect(subject_value).to eq([4, 5, 6, :override])
|
|
184
134
|
end
|
|
185
135
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
end
|
|
191
|
-
|
|
192
|
-
def define_and_run_group
|
|
193
|
-
values = { :reference_lines => [] }
|
|
136
|
+
[:before, :after].each do |hook|
|
|
137
|
+
it "raises an error when referenced from `#{hook}(:all)`" do
|
|
138
|
+
result = nil
|
|
139
|
+
line = nil
|
|
194
140
|
|
|
195
141
|
ExampleGroup.describe do
|
|
196
|
-
subject {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
before(:all) do
|
|
200
|
-
subject << 3; values[:reference_lines] << __LINE__
|
|
201
|
-
values[:final_subject_value_in_before_all] = subject; values[:reference_lines] << __LINE__
|
|
202
|
-
end
|
|
203
|
-
|
|
204
|
-
example do
|
|
205
|
-
list << '1'
|
|
206
|
-
values[:list_in_ex_1] = list
|
|
207
|
-
values[:subject_value_in_example] = subject
|
|
208
|
-
end
|
|
209
|
-
|
|
210
|
-
example do
|
|
211
|
-
list << '2'
|
|
212
|
-
values[:list_in_ex_2] = list
|
|
213
|
-
end
|
|
142
|
+
subject { nil }
|
|
143
|
+
send(hook, :all) { result = (subject rescue $!) }; line = __LINE__
|
|
144
|
+
example { }
|
|
214
145
|
end.run
|
|
215
146
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
it 'memoizes the value within the before(:all) hook' do
|
|
220
|
-
values = define_and_run_group
|
|
221
|
-
expect(values.fetch(:final_subject_value_in_before_all)).to eq([1, 2, 3])
|
|
222
|
-
end
|
|
223
|
-
|
|
224
|
-
it 'preserves the memoization into the individual examples' do
|
|
225
|
-
values = define_and_run_group
|
|
226
|
-
expect(values.fetch(:subject_value_in_example)).to eq([1, 2, 3])
|
|
227
|
-
end
|
|
228
|
-
|
|
229
|
-
it 'does not cause other lets to be shared across examples' do
|
|
230
|
-
values = define_and_run_group
|
|
231
|
-
expect(values.fetch(:list_in_ex_1)).to eq(%w[ a b 1 ])
|
|
232
|
-
expect(values.fetch(:list_in_ex_2)).to eq(%w[ a b 2 ])
|
|
233
|
-
end
|
|
234
|
-
|
|
235
|
-
it 'prints a warning since `subject` declarations are not intended to be used in :all hooks' do
|
|
236
|
-
msgs = []
|
|
237
|
-
::RSpec.stub(:warn_deprecation) { |msg| msgs << msg }
|
|
238
|
-
|
|
239
|
-
values = define_and_run_group
|
|
240
|
-
|
|
241
|
-
expect(msgs).to include(*values[:reference_lines].map { |line|
|
|
242
|
-
match(/subject accessed.*#{__FILE__}:#{line}/m)
|
|
243
|
-
})
|
|
147
|
+
expect(result).to be_an(Exception)
|
|
148
|
+
expect(result.message).to match(/subject accessed.*#{hook}\(:all\).*#{__FILE__}:#{line}/m)
|
|
244
149
|
end
|
|
245
150
|
end
|
|
246
151
|
end
|
|
@@ -393,169 +298,7 @@ module RSpec::Core
|
|
|
393
298
|
it { should_not be_not_ok }
|
|
394
299
|
end
|
|
395
300
|
|
|
396
|
-
expect(group.run).to
|
|
397
|
-
end
|
|
398
|
-
|
|
399
|
-
it 'supports a new expect-based syntax' do
|
|
400
|
-
group = ExampleGroup.describe([1, 2, 3]) do
|
|
401
|
-
it { is_expected.to be_an Array }
|
|
402
|
-
it { is_expected.not_to include 4 }
|
|
403
|
-
end
|
|
404
|
-
|
|
405
|
-
expect(group.run).to be true
|
|
406
|
-
end
|
|
407
|
-
end
|
|
408
|
-
|
|
409
|
-
describe "#its" do
|
|
410
|
-
extend SilenceDSLDeprecations
|
|
411
|
-
silence_dsl_deprecations do
|
|
412
|
-
it "should issue deprecation warning" do
|
|
413
|
-
expect_deprecation_with_call_site(__FILE__, __LINE__+1, '`its` method')
|
|
414
|
-
RSpec::Core::ExampleGroup.its(nil) {}
|
|
415
|
-
end
|
|
416
|
-
|
|
417
|
-
subject do
|
|
418
|
-
Class.new do
|
|
419
|
-
def initialize
|
|
420
|
-
@call_count = 0
|
|
421
|
-
end
|
|
422
|
-
|
|
423
|
-
def call_count
|
|
424
|
-
@call_count += 1
|
|
425
|
-
end
|
|
426
|
-
end.new
|
|
427
|
-
end
|
|
428
|
-
|
|
429
|
-
context "with a call counter" do
|
|
430
|
-
its(:call_count) { should eq(1) }
|
|
431
|
-
end
|
|
432
|
-
|
|
433
|
-
context "with nil value" do
|
|
434
|
-
subject do
|
|
435
|
-
Class.new do
|
|
436
|
-
def nil_value
|
|
437
|
-
nil
|
|
438
|
-
end
|
|
439
|
-
end.new
|
|
440
|
-
end
|
|
441
|
-
its(:nil_value) { should be_nil }
|
|
442
|
-
end
|
|
443
|
-
|
|
444
|
-
context "with nested attributes" do
|
|
445
|
-
subject do
|
|
446
|
-
Class.new do
|
|
447
|
-
def name
|
|
448
|
-
"John"
|
|
449
|
-
end
|
|
450
|
-
end.new
|
|
451
|
-
end
|
|
452
|
-
its("name") { should eq("John") }
|
|
453
|
-
its("name.size") { should eq(4) }
|
|
454
|
-
its("name.size.class") { should eq(Fixnum) }
|
|
455
|
-
end
|
|
456
|
-
|
|
457
|
-
context "when it responds to #[]" do
|
|
458
|
-
subject do
|
|
459
|
-
Class.new do
|
|
460
|
-
def [](*objects)
|
|
461
|
-
objects.map do |object|
|
|
462
|
-
"#{object.class}: #{object.to_s}"
|
|
463
|
-
end.join("; ")
|
|
464
|
-
end
|
|
465
|
-
|
|
466
|
-
def name
|
|
467
|
-
"George"
|
|
468
|
-
end
|
|
469
|
-
end.new
|
|
470
|
-
end
|
|
471
|
-
its([:a]) { should eq("Symbol: a") }
|
|
472
|
-
its(['a']) { should eq("String: a") }
|
|
473
|
-
its([:b, 'c', 4]) { should eq("Symbol: b; String: c; Fixnum: 4") }
|
|
474
|
-
its(:name) { should eq("George") }
|
|
475
|
-
context "when referring to an attribute without the proper array syntax" do
|
|
476
|
-
context "it raises an error" do
|
|
477
|
-
its(:age) do
|
|
478
|
-
expect do
|
|
479
|
-
should eq(64)
|
|
480
|
-
end.to raise_error(NoMethodError)
|
|
481
|
-
end
|
|
482
|
-
end
|
|
483
|
-
end
|
|
484
|
-
end
|
|
485
|
-
|
|
486
|
-
context "when it does not respond to #[]" do
|
|
487
|
-
subject { Object.new }
|
|
488
|
-
|
|
489
|
-
context "it raises an error" do
|
|
490
|
-
its([:a]) do
|
|
491
|
-
expect do
|
|
492
|
-
should eq("Symbol: a")
|
|
493
|
-
end.to raise_error(NoMethodError)
|
|
494
|
-
end
|
|
495
|
-
end
|
|
496
|
-
end
|
|
497
|
-
|
|
498
|
-
context "calling and overriding super" do
|
|
499
|
-
it "calls to the subject defined in the parent group" do
|
|
500
|
-
group = ExampleGroup.describe(Array) do
|
|
501
|
-
subject { [1, 'a'] }
|
|
502
|
-
|
|
503
|
-
its(:last) { should eq("a") }
|
|
504
|
-
|
|
505
|
-
describe '.first' do
|
|
506
|
-
def subject; super().first; end
|
|
507
|
-
|
|
508
|
-
its(:next) { should eq(2) }
|
|
509
|
-
end
|
|
510
|
-
end
|
|
511
|
-
|
|
512
|
-
expect(group.run).to be_truthy
|
|
513
|
-
end
|
|
514
|
-
end
|
|
515
|
-
|
|
516
|
-
context "with nil subject" do
|
|
517
|
-
subject do
|
|
518
|
-
Class.new do
|
|
519
|
-
def initialize
|
|
520
|
-
@counter = -1
|
|
521
|
-
end
|
|
522
|
-
def nil_if_first_time
|
|
523
|
-
@counter += 1
|
|
524
|
-
@counter == 0 ? nil : true
|
|
525
|
-
end
|
|
526
|
-
end.new
|
|
527
|
-
end
|
|
528
|
-
its(:nil_if_first_time) { should be(nil) }
|
|
529
|
-
end
|
|
530
|
-
|
|
531
|
-
context "with false subject" do
|
|
532
|
-
subject do
|
|
533
|
-
Class.new do
|
|
534
|
-
def initialize
|
|
535
|
-
@counter = -1
|
|
536
|
-
end
|
|
537
|
-
def false_if_first_time
|
|
538
|
-
@counter += 1
|
|
539
|
-
@counter > 0
|
|
540
|
-
end
|
|
541
|
-
end.new
|
|
542
|
-
end
|
|
543
|
-
its(:false_if_first_time) { should be(false) }
|
|
544
|
-
end
|
|
545
|
-
|
|
546
|
-
describe 'accessing `subject` in `before` and `let`' do
|
|
547
|
-
subject { 'my subject' }
|
|
548
|
-
before { @subject_in_before = subject }
|
|
549
|
-
let(:subject_in_let) { subject }
|
|
550
|
-
let!(:eager_loaded_subject_in_let) { subject }
|
|
551
|
-
|
|
552
|
-
# These examples read weird, because we're actually
|
|
553
|
-
# specifying the behaviour of `its` itself
|
|
554
|
-
its(nil) { expect(subject).to eq('my subject') }
|
|
555
|
-
its(nil) { expect(@subject_in_before).to eq('my subject') }
|
|
556
|
-
its(nil) { expect(subject_in_let).to eq('my subject') }
|
|
557
|
-
its(nil) { expect(eager_loaded_subject_in_let).to eq('my subject') }
|
|
558
|
-
end
|
|
301
|
+
expect(group.run).to be_truthy
|
|
559
302
|
end
|
|
560
303
|
end
|
|
561
304
|
|
|
@@ -656,64 +399,19 @@ module RSpec::Core
|
|
|
656
399
|
end
|
|
657
400
|
end
|
|
658
401
|
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
end
|
|
664
|
-
|
|
665
|
-
def define_and_run_group
|
|
666
|
-
values = { :reference_lines => [] }
|
|
402
|
+
[:before, :after].each do |hook|
|
|
403
|
+
it "raises an error when referenced from `#{hook}(:all)`" do
|
|
404
|
+
result = nil
|
|
405
|
+
line = nil
|
|
667
406
|
|
|
668
407
|
ExampleGroup.describe do
|
|
669
|
-
let(:
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
before(:all) do
|
|
673
|
-
list << 3; values[:reference_lines] << __LINE__
|
|
674
|
-
values[:final_list_value_in_before_all] = list; values[:reference_lines] << __LINE__
|
|
675
|
-
end
|
|
676
|
-
|
|
677
|
-
example do
|
|
678
|
-
subject << "1"
|
|
679
|
-
values[:subject_in_ex_1] = subject
|
|
680
|
-
values[:list_value_in_example] = list
|
|
681
|
-
end
|
|
682
|
-
|
|
683
|
-
example do
|
|
684
|
-
subject << "2"
|
|
685
|
-
values[:subject_in_ex_2] = subject
|
|
686
|
-
end
|
|
408
|
+
let(:foo) { nil }
|
|
409
|
+
send(hook, :all) { result = (foo rescue $!) }; line = __LINE__
|
|
410
|
+
example { }
|
|
687
411
|
end.run
|
|
688
412
|
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
it 'memoizes the value within the before(:all) hook' do
|
|
693
|
-
values = define_and_run_group
|
|
694
|
-
expect(values.fetch(:final_list_value_in_before_all)).to eq([1, 2, 3])
|
|
695
|
-
end
|
|
696
|
-
|
|
697
|
-
it 'preserves the memoized value into the examples' do
|
|
698
|
-
values = define_and_run_group
|
|
699
|
-
expect(values.fetch(:list_value_in_example)).to eq([1, 2, 3])
|
|
700
|
-
end
|
|
701
|
-
|
|
702
|
-
it 'does not cause the subject to be shared across examples' do
|
|
703
|
-
values = define_and_run_group
|
|
704
|
-
expect(values.fetch(:subject_in_ex_1)).to eq(%w[ a b 1 ])
|
|
705
|
-
expect(values.fetch(:subject_in_ex_2)).to eq(%w[ a b 2 ])
|
|
706
|
-
end
|
|
707
|
-
|
|
708
|
-
it 'prints a warning since `let` declarations are not intended to be used in :all hooks' do
|
|
709
|
-
msgs = []
|
|
710
|
-
::RSpec.stub(:warn_deprecation) { |msg| msgs << msg }
|
|
711
|
-
|
|
712
|
-
values = define_and_run_group
|
|
713
|
-
|
|
714
|
-
expect(msgs).to include(*values[:reference_lines].map { |line|
|
|
715
|
-
match(/let declaration `list` accessed.*#{__FILE__}:#{line}/m)
|
|
716
|
-
})
|
|
413
|
+
expect(result).to be_an(Exception)
|
|
414
|
+
expect(result.message).to match(/let declaration `foo` accessed.*#{hook}\(:all\).*#{__FILE__}:#{line}/m)
|
|
717
415
|
end
|
|
718
416
|
end
|
|
719
417
|
|
|
@@ -758,7 +456,7 @@ module RSpec::Core
|
|
|
758
456
|
expect(subject_id_in_let).to eq(@subject_id_in_before)
|
|
759
457
|
end
|
|
760
458
|
|
|
761
|
-
it {
|
|
459
|
+
it { should eq(subject) }
|
|
762
460
|
end
|
|
763
461
|
|
|
764
462
|
describe Object do
|