rspec-core 3.0.0.beta2 → 3.0.0.rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/.yardopts +1 -0
- data/Changelog.md +297 -57
- data/README.md +16 -13
- data/lib/rspec/core.rb +55 -84
- data/lib/rspec/core/backport_random.rb +35 -3
- data/lib/rspec/core/backtrace_formatter.rb +4 -13
- data/lib/rspec/core/configuration.rb +330 -114
- data/lib/rspec/core/configuration_options.rb +38 -22
- data/lib/rspec/core/drb.rb +111 -0
- data/lib/rspec/core/dsl.rb +8 -2
- data/lib/rspec/core/example.rb +203 -94
- data/lib/rspec/core/example_group.rb +344 -316
- data/lib/rspec/core/filter_manager.rb +135 -90
- data/lib/rspec/core/flat_map.rb +1 -0
- data/lib/rspec/core/formatters.rb +50 -14
- data/lib/rspec/core/formatters/base_formatter.rb +32 -138
- data/lib/rspec/core/formatters/base_text_formatter.rb +32 -253
- data/lib/rspec/core/formatters/console_codes.rb +65 -0
- data/lib/rspec/core/formatters/deprecation_formatter.rb +24 -15
- data/lib/rspec/core/formatters/documentation_formatter.rb +7 -10
- data/lib/rspec/core/formatters/helpers.rb +15 -9
- data/lib/rspec/core/formatters/html_formatter.rb +17 -16
- data/lib/rspec/core/formatters/html_printer.rb +1 -0
- data/lib/rspec/core/formatters/json_formatter.rb +18 -20
- data/lib/rspec/core/formatters/profile_formatter.rb +67 -0
- data/lib/rspec/core/formatters/progress_formatter.rb +6 -7
- data/lib/rspec/core/formatters/snippet_extractor.rb +8 -6
- data/lib/rspec/core/hooks.rb +131 -125
- data/lib/rspec/core/memoized_helpers.rb +31 -26
- data/lib/rspec/core/metadata.rb +277 -184
- data/lib/rspec/core/metadata_filter.rb +86 -0
- data/lib/rspec/core/minitest_assertions_adapter.rb +28 -0
- data/lib/rspec/core/mocking_adapters/flexmock.rb +1 -1
- data/lib/rspec/core/mocking_adapters/mocha.rb +1 -1
- data/lib/rspec/core/mocking_adapters/null.rb +1 -1
- data/lib/rspec/core/mocking_adapters/rr.rb +2 -1
- data/lib/rspec/core/mocking_adapters/rspec.rb +1 -1
- data/lib/rspec/core/notifications.rb +435 -24
- data/lib/rspec/core/option_parser.rb +16 -25
- data/lib/rspec/core/ordering.rb +3 -1
- data/lib/rspec/core/pending.rb +57 -33
- data/lib/rspec/core/project_initializer.rb +2 -0
- data/lib/rspec/core/project_initializer/spec_helper.rb +5 -4
- data/lib/rspec/core/rake_task.rb +45 -20
- data/lib/rspec/core/reporter.rb +50 -22
- data/lib/rspec/core/ruby_project.rb +1 -0
- data/lib/rspec/core/runner.rb +93 -39
- data/lib/rspec/core/shared_context.rb +7 -5
- data/lib/rspec/core/shared_example_group.rb +85 -77
- data/lib/rspec/core/test_unit_assertions_adapter.rb +30 -0
- data/lib/rspec/core/version.rb +3 -1
- data/lib/rspec/core/warnings.rb +35 -17
- data/lib/rspec/core/world.rb +57 -5
- metadata +56 -369
- metadata.gz.sig +3 -3
- data/features/README.md +0 -13
- data/features/Upgrade.md +0 -352
- data/features/command_line/README.md +0 -25
- data/features/command_line/dry_run.feature +0 -29
- data/features/command_line/example_name_option.feature +0 -97
- data/features/command_line/exit_status.feature +0 -82
- data/features/command_line/fail_fast.feature +0 -26
- data/features/command_line/format_option.feature +0 -75
- data/features/command_line/init.feature +0 -57
- data/features/command_line/line_number_appended_to_path.feature +0 -140
- data/features/command_line/line_number_option.feature +0 -58
- data/features/command_line/order.feature +0 -25
- data/features/command_line/pattern_option.feature +0 -49
- data/features/command_line/rake_task.feature +0 -122
- data/features/command_line/randomization.feature +0 -63
- data/features/command_line/require_option.feature +0 -43
- data/features/command_line/ruby.feature +0 -23
- 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 -39
- data/features/configuration/backtrace_exclusion_patterns.feature +0 -105
- 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/enable_global_dsl.feature +0 -54
- 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/overriding_global_ordering.feature +0 -93
- 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/example_groups/aliasing.feature +0 -48
- 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 -286
- data/features/expectation_framework_integration/configure_expectation_framework.feature +0 -102
- data/features/filtering/exclusion_filters.feature +0 -135
- data/features/filtering/if_and_unless.feature +0 -138
- data/features/filtering/inclusion_filters.feature +0 -101
- data/features/formatters/configurable_colors.feature +0 -31
- data/features/formatters/custom_formatter.feature +0 -68
- data/features/formatters/json_formatter.feature +0 -30
- data/features/formatters/regression_tests.feature +0 -95
- 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 -146
- data/features/hooks/around_hooks.feature +0 -344
- data/features/hooks/before_and_after_hooks.feature +0 -427
- data/features/hooks/filtering.feature +0 -232
- data/features/metadata/current_example.feature +0 -56
- data/features/metadata/described_class.feature +0 -17
- data/features/metadata/user_defined.feature +0 -100
- data/features/mock_framework_integration/use_any_framework.feature +0 -106
- data/features/mock_framework_integration/use_flexmock.feature +0 -94
- data/features/mock_framework_integration/use_mocha.feature +0 -95
- data/features/mock_framework_integration/use_rr.feature +0 -96
- data/features/mock_framework_integration/use_rspec.feature +0 -95
- data/features/pending_and_skipped_examples/README.md +0 -3
- data/features/pending_and_skipped_examples/pending_examples.feature +0 -118
- data/features/pending_and_skipped_examples/skipped_examples.feature +0 -106
- data/features/spec_files/arbitrary_file_suffix.feature +0 -13
- data/features/step_definitions/additional_cli_steps.rb +0 -83
- 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 -21
- data/features/support/require_expect_syntax_in_aruba_specs.rb +0 -16
- data/features/support/rubinius.rb +0 -6
- data/lib/rspec/core/command_line.rb +0 -35
- data/lib/rspec/core/drb_command_line.rb +0 -26
- data/lib/rspec/core/drb_options.rb +0 -87
- data/lib/rspec/core/formatters/legacy_formatter.rb +0 -227
- data/lib/rspec/core/shared_example_group/collection.rb +0 -27
- data/spec/command_line/order_spec.rb +0 -211
- data/spec/rspec/core/backtrace_formatter_spec.rb +0 -230
- data/spec/rspec/core/command_line_spec.rb +0 -112
- data/spec/rspec/core/command_line_spec_output.txt +0 -0
- data/spec/rspec/core/configuration_options_spec.rb +0 -409
- data/spec/rspec/core/configuration_spec.rb +0 -1479
- 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 -88
- data/spec/rspec/core/example_group_spec.rb +0 -1533
- data/spec/rspec/core/example_spec.rb +0 -642
- data/spec/rspec/core/filter_manager_spec.rb +0 -229
- data/spec/rspec/core/formatters/base_formatter_spec.rb +0 -64
- data/spec/rspec/core/formatters/base_text_formatter_spec.rb +0 -303
- data/spec/rspec/core/formatters/deprecation_formatter_spec.rb +0 -208
- data/spec/rspec/core/formatters/documentation_formatter_spec.rb +0 -75
- data/spec/rspec/core/formatters/helpers_spec.rb +0 -104
- data/spec/rspec/core/formatters/html_formatted-2.1.0.html +0 -392
- data/spec/rspec/core/formatters/html_formatted.html +0 -397
- data/spec/rspec/core/formatters/html_formatter_spec.rb +0 -122
- data/spec/rspec/core/formatters/json_formatter_spec.rb +0 -206
- data/spec/rspec/core/formatters/legacy_formatter_spec.rb +0 -137
- data/spec/rspec/core/formatters/progress_formatter_spec.rb +0 -43
- data/spec/rspec/core/formatters/snippet_extractor_spec.rb +0 -26
- data/spec/rspec/core/formatters_spec.rb +0 -120
- data/spec/rspec/core/hooks_filtering_spec.rb +0 -227
- data/spec/rspec/core/hooks_spec.rb +0 -294
- data/spec/rspec/core/memoized_helpers_spec.rb +0 -495
- data/spec/rspec/core/metadata_spec.rb +0 -491
- data/spec/rspec/core/option_parser_spec.rb +0 -262
- data/spec/rspec/core/ordering_spec.rb +0 -102
- data/spec/rspec/core/pending_example_spec.rb +0 -117
- data/spec/rspec/core/pending_spec.rb +0 -8
- data/spec/rspec/core/project_initializer_spec.rb +0 -73
- data/spec/rspec/core/rake_task_spec.rb +0 -146
- data/spec/rspec/core/random_spec.rb +0 -47
- data/spec/rspec/core/reporter_spec.rb +0 -155
- 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 -58
- 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 -151
- data/spec/rspec/core/shared_context_spec.rb +0 -102
- data/spec/rspec/core/shared_example_group/collection_spec.rb +0 -57
- data/spec/rspec/core/shared_example_group_spec.rb +0 -114
- data/spec/rspec/core/warnings_spec.rb +0 -29
- data/spec/rspec/core/world_spec.rb +0 -142
- data/spec/rspec/core_spec.rb +0 -91
- data/spec/spec_helper.rb +0 -160
- data/spec/support/config_options_helper.rb +0 -13
- data/spec/support/formatter_support.rb +0 -83
- data/spec/support/helper_methods.rb +0 -26
- data/spec/support/isolate_load_path_mutation.rb +0 -5
- data/spec/support/isolated_directory.rb +0 -10
- data/spec/support/isolated_home_directory.rb +0 -16
- data/spec/support/legacy_formatter_using_sub_classing_example.rb +0 -87
- data/spec/support/matchers.rb +0 -85
- data/spec/support/mathn_integration_support.rb +0 -12
- data/spec/support/old_style_formatter_example.rb +0 -69
- data/spec/support/shared_example_groups.rb +0 -13
- data/spec/support/spec_files.rb +0 -44
- data/spec/support/stderr_splitter.rb +0 -36
@@ -1,491 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module RSpec
|
4
|
-
module Core
|
5
|
-
RSpec.describe Metadata do
|
6
|
-
|
7
|
-
describe '.relative_path' do
|
8
|
-
let(:here) { File.expand_path(".") }
|
9
|
-
it "transforms absolute paths to relative paths" do
|
10
|
-
expect(Metadata.relative_path(here)).to eq "."
|
11
|
-
end
|
12
|
-
it "transforms absolute paths to relative paths anywhere in its argument" do
|
13
|
-
expect(Metadata.relative_path("foo #{here} bar")).to eq "foo . bar"
|
14
|
-
end
|
15
|
-
it "returns nil if passed an unparseable file:line combo" do
|
16
|
-
expect(Metadata.relative_path("-e:1")).to be_nil
|
17
|
-
end
|
18
|
-
# I have no idea what line = line.sub(/\A([^:]+:\d+)$/, '\\1') is supposed to do
|
19
|
-
it "gracefully returns nil if run in a secure thread" do
|
20
|
-
safely do
|
21
|
-
value = Metadata.relative_path(".")
|
22
|
-
# on some rubies, File.expand_path is not a security error, so accept "." as well
|
23
|
-
expect([nil, "."]).to include(value)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
describe "#process" do
|
30
|
-
Metadata::RESERVED_KEYS.each do |key|
|
31
|
-
it "prohibits :#{key} as a hash key" do
|
32
|
-
m = Metadata.new
|
33
|
-
expect do
|
34
|
-
m.process('group', key => {})
|
35
|
-
end.to raise_error(/:#{key} is not allowed/)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
it "uses :caller if passed as part of the user metadata" do
|
40
|
-
m = Metadata.new
|
41
|
-
m.process('group', :caller => ['example_file:42'])
|
42
|
-
expect(m[:example_group][:location]).to eq("example_file:42")
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
describe "#filter_applies?" do
|
47
|
-
let(:parent_group_metadata) { Metadata.new.process('parent group', :caller => ["foo_spec.rb:#{__LINE__}"]) }
|
48
|
-
let(:group_metadata) { Metadata.new(parent_group_metadata).process('group', :caller => ["foo_spec.rb:#{__LINE__}"]) }
|
49
|
-
let(:example_metadata) { group_metadata.for_example('example', :caller => ["foo_spec.rb:#{__LINE__}"], :if => true) }
|
50
|
-
let(:next_example_metadata) { group_metadata.for_example('next_example', :caller => ["foo_spec.rb:#{example_line_number + 2}"]) }
|
51
|
-
let(:world) { World.new }
|
52
|
-
|
53
|
-
before { allow(RSpec).to receive(:world) { world } }
|
54
|
-
|
55
|
-
shared_examples_for "matching by line number" do
|
56
|
-
let(:preceeding_declaration_lines) {{
|
57
|
-
parent_group_metadata[:example_group][:line_number] => parent_group_metadata[:example_group][:line_number],
|
58
|
-
group_metadata[:example_group][:line_number] => group_metadata[:example_group][:line_number],
|
59
|
-
example_metadata[:line_number] => example_metadata[:line_number],
|
60
|
-
(example_metadata[:line_number] + 1) => example_metadata[:line_number],
|
61
|
-
(example_metadata[:line_number] + 2) => example_metadata[:line_number] + 2,
|
62
|
-
}}
|
63
|
-
before do
|
64
|
-
expect(world).to receive(:preceding_declaration_line).at_least(:once) do |v|
|
65
|
-
preceeding_declaration_lines[v]
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
it "matches the group when the line_number is the example group line number" do
|
70
|
-
# this call doesn't really make sense since filter_applies? is only called
|
71
|
-
# for example metadata not group metadata
|
72
|
-
expect(group_metadata.filter_applies?(condition_key, group_condition)).to be_truthy
|
73
|
-
end
|
74
|
-
|
75
|
-
it "matches the example when the line_number is the grandparent example group line number" do
|
76
|
-
expect(example_metadata.filter_applies?(condition_key, parent_group_condition)).to be_truthy
|
77
|
-
end
|
78
|
-
|
79
|
-
it "matches the example when the line_number is the parent example group line number" do
|
80
|
-
expect(example_metadata.filter_applies?(condition_key, group_condition)).to be_truthy
|
81
|
-
end
|
82
|
-
|
83
|
-
it "matches the example when the line_number is the example line number" do
|
84
|
-
expect(example_metadata.filter_applies?(condition_key, example_condition)).to be_truthy
|
85
|
-
end
|
86
|
-
|
87
|
-
it "matches when the line number is between this example and the next" do
|
88
|
-
expect(example_metadata.filter_applies?(condition_key, between_examples_condition)).to be_truthy
|
89
|
-
end
|
90
|
-
|
91
|
-
it "does not match when the line number matches the next example" do
|
92
|
-
expect(example_metadata.filter_applies?(condition_key, next_example_condition)).to be_falsey
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
context "with a single line number" do
|
97
|
-
let(:condition_key){ :line_numbers }
|
98
|
-
let(:parent_group_condition) { [parent_group_metadata[:example_group][:line_number]] }
|
99
|
-
let(:group_condition) { [group_metadata[:example_group][:line_number]] }
|
100
|
-
let(:example_condition) { [example_metadata[:line_number]] }
|
101
|
-
let(:between_examples_condition) { [group_metadata[:example_group][:line_number] + 1] }
|
102
|
-
let(:next_example_condition) { [example_metadata[:line_number] + 2] }
|
103
|
-
|
104
|
-
it_has_behavior "matching by line number"
|
105
|
-
end
|
106
|
-
|
107
|
-
context "with multiple line numbers" do
|
108
|
-
let(:condition_key){ :line_numbers }
|
109
|
-
let(:parent_group_condition) { [-1, parent_group_metadata[:example_group][:line_number]] }
|
110
|
-
let(:group_condition) { [-1, group_metadata[:example_group][:line_number]] }
|
111
|
-
let(:example_condition) { [-1, example_metadata[:line_number]] }
|
112
|
-
let(:between_examples_condition) { [-1, group_metadata[:example_group][:line_number] + 1] }
|
113
|
-
let(:next_example_condition) { [-1, example_metadata[:line_number] + 2] }
|
114
|
-
|
115
|
-
it_has_behavior "matching by line number"
|
116
|
-
end
|
117
|
-
|
118
|
-
context "with locations" do
|
119
|
-
let(:condition_key){ :locations }
|
120
|
-
let(:parent_group_condition) do
|
121
|
-
{File.expand_path(parent_group_metadata[:example_group][:file_path]) => [parent_group_metadata[:example_group][:line_number]]}
|
122
|
-
end
|
123
|
-
let(:group_condition) do
|
124
|
-
{File.expand_path(group_metadata[:example_group][:file_path]) => [group_metadata[:example_group][:line_number]]}
|
125
|
-
end
|
126
|
-
let(:example_condition) do
|
127
|
-
{File.expand_path(example_metadata[:file_path]) => [example_metadata[:line_number]]}
|
128
|
-
end
|
129
|
-
let(:between_examples_condition) do
|
130
|
-
{File.expand_path(group_metadata[:example_group][:file_path]) => [group_metadata[:example_group][:line_number] + 1]}
|
131
|
-
end
|
132
|
-
let(:next_example_condition) do
|
133
|
-
{File.expand_path(example_metadata[:file_path]) => [example_metadata[:line_number] + 2]}
|
134
|
-
end
|
135
|
-
|
136
|
-
it_has_behavior "matching by line number"
|
137
|
-
|
138
|
-
it "ignores location filters for other files" do
|
139
|
-
expect(example_metadata.filter_applies?(:locations, {"/path/to/other_spec.rb" => [3,5,7]})).to be_truthy
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
it "matches a proc with no arguments that evaluates to true" do
|
144
|
-
expect(example_metadata.filter_applies?(:if, lambda { true })).to be_truthy
|
145
|
-
end
|
146
|
-
|
147
|
-
it "matches a proc that evaluates to true" do
|
148
|
-
expect(example_metadata.filter_applies?(:if, lambda { |v| v })).to be_truthy
|
149
|
-
end
|
150
|
-
|
151
|
-
it "does not match a proc that evaluates to false" do
|
152
|
-
expect(example_metadata.filter_applies?(:if, lambda { |v| !v })).to be_falsey
|
153
|
-
end
|
154
|
-
|
155
|
-
it "matches a proc with an arity of 2" do
|
156
|
-
example_metadata[:foo] = nil
|
157
|
-
expect(example_metadata.filter_applies?(:foo, lambda { |v, m| m == example_metadata })).to be_truthy
|
158
|
-
end
|
159
|
-
|
160
|
-
it "raises an error when the proc has an incorrect arity" do
|
161
|
-
expect {
|
162
|
-
example_metadata.filter_applies?(:if, lambda { |a,b,c| true })
|
163
|
-
}.to raise_error(ArgumentError)
|
164
|
-
end
|
165
|
-
|
166
|
-
context "with an Array" do
|
167
|
-
let(:metadata_with_array) {
|
168
|
-
group_metadata.for_example('example_with_array', :tag => [:one, 2, 'three', /four/])
|
169
|
-
}
|
170
|
-
|
171
|
-
it "matches a symbol" do
|
172
|
-
expect(metadata_with_array.filter_applies?(:tag, 'one')).to be_truthy
|
173
|
-
expect(metadata_with_array.filter_applies?(:tag, :one)).to be_truthy
|
174
|
-
expect(metadata_with_array.filter_applies?(:tag, 'two')).to be_falsey
|
175
|
-
end
|
176
|
-
|
177
|
-
it "matches a string" do
|
178
|
-
expect(metadata_with_array.filter_applies?(:tag, 'three')).to be_truthy
|
179
|
-
expect(metadata_with_array.filter_applies?(:tag, :three)).to be_truthy
|
180
|
-
expect(metadata_with_array.filter_applies?(:tag, 'tree')).to be_falsey
|
181
|
-
end
|
182
|
-
|
183
|
-
it "matches an integer" do
|
184
|
-
expect(metadata_with_array.filter_applies?(:tag, '2')).to be_truthy
|
185
|
-
expect(metadata_with_array.filter_applies?(:tag, 2)).to be_truthy
|
186
|
-
expect(metadata_with_array.filter_applies?(:tag, 3)).to be_falsey
|
187
|
-
end
|
188
|
-
|
189
|
-
it "matches a regexp" do
|
190
|
-
expect(metadata_with_array.filter_applies?(:tag, 'four')).to be_truthy
|
191
|
-
expect(metadata_with_array.filter_applies?(:tag, 'fourtune')).to be_truthy
|
192
|
-
expect(metadata_with_array.filter_applies?(:tag, 'fortune')).to be_falsey
|
193
|
-
end
|
194
|
-
|
195
|
-
it "matches a proc that evaluates to true" do
|
196
|
-
expect(metadata_with_array.filter_applies?(:tag, lambda { |values| values.include? 'three' })).to be_truthy
|
197
|
-
end
|
198
|
-
|
199
|
-
it "does not match a proc that evaluates to false" do
|
200
|
-
expect(metadata_with_array.filter_applies?(:tag, lambda { |values| values.include? 'nothing' })).to be_falsey
|
201
|
-
end
|
202
|
-
end
|
203
|
-
end
|
204
|
-
|
205
|
-
describe "#for_example" do
|
206
|
-
let(:metadata) { Metadata.new.process("group description") }
|
207
|
-
let(:mfe) { metadata.for_example("example description", {:arbitrary => :options}) }
|
208
|
-
let(:line_number) { __LINE__ - 1 }
|
209
|
-
|
210
|
-
it "stores the description args" do
|
211
|
-
expect(mfe.fetch(:description_args)).to eq ["example description"]
|
212
|
-
expect(mfe[:description_args]).to eq ["example description"]
|
213
|
-
end
|
214
|
-
|
215
|
-
it "ignores nil description args" do
|
216
|
-
expect(metadata.for_example(nil, {}).fetch(:description_args)).to eq []
|
217
|
-
expect(metadata.for_example(nil, {})[:description_args]).to eq []
|
218
|
-
end
|
219
|
-
|
220
|
-
it "stores the full_description (group description + example description)" do
|
221
|
-
expect(mfe.fetch(:full_description)).to eq("group description example description")
|
222
|
-
expect(mfe[:full_description]).to eq("group description example description")
|
223
|
-
end
|
224
|
-
|
225
|
-
it "creates an empty execution result" do
|
226
|
-
expect(mfe.fetch(:execution_result)).to eq({})
|
227
|
-
expect(mfe[:execution_result]).to eq({})
|
228
|
-
end
|
229
|
-
|
230
|
-
it "extracts file path from caller" do
|
231
|
-
expect(mfe.fetch(:file_path)).to eq(relative_path(__FILE__))
|
232
|
-
expect(mfe[:file_path]).to eq(relative_path(__FILE__))
|
233
|
-
end
|
234
|
-
|
235
|
-
it "extracts line number from caller" do
|
236
|
-
expect(mfe.fetch(:line_number)).to eq(line_number)
|
237
|
-
expect(mfe[:line_number]).to eq(line_number)
|
238
|
-
end
|
239
|
-
|
240
|
-
it "extracts location from caller" do
|
241
|
-
expect(mfe.fetch(:location)).to eq("#{relative_path(__FILE__)}:#{line_number}")
|
242
|
-
expect(mfe[:location]).to eq("#{relative_path(__FILE__)}:#{line_number}")
|
243
|
-
end
|
244
|
-
|
245
|
-
it "uses :caller if passed as an option" do
|
246
|
-
example_metadata = metadata.for_example('example description', {:caller => ['example_file:42']})
|
247
|
-
expect(example_metadata[:location]).to eq("example_file:42")
|
248
|
-
end
|
249
|
-
|
250
|
-
it "merges arbitrary options" do
|
251
|
-
expect(mfe.fetch(:arbitrary)).to eq(:options)
|
252
|
-
expect(mfe[:arbitrary]).to eq(:options)
|
253
|
-
end
|
254
|
-
|
255
|
-
it "points :example_group to the same hash object" do
|
256
|
-
a = metadata.for_example("foo", {})[:example_group]
|
257
|
-
b = metadata.for_example("bar", {})[:example_group]
|
258
|
-
a[:description] = "new description"
|
259
|
-
expect(b[:description]).to eq("new description")
|
260
|
-
end
|
261
|
-
end
|
262
|
-
|
263
|
-
[:described_class, :describes].each do |key|
|
264
|
-
describe key do
|
265
|
-
context "with a String" do
|
266
|
-
it "returns nil" do
|
267
|
-
m = Metadata.new
|
268
|
-
m.process('group')
|
269
|
-
|
270
|
-
expect(m[:example_group][key]).to be_nil
|
271
|
-
end
|
272
|
-
end
|
273
|
-
|
274
|
-
context "with a Symbol" do
|
275
|
-
it "returns nil" do
|
276
|
-
m = Metadata.new
|
277
|
-
m.process(:group)
|
278
|
-
|
279
|
-
expect(m[:example_group][key]).to be_nil
|
280
|
-
end
|
281
|
-
end
|
282
|
-
|
283
|
-
context "with a class" do
|
284
|
-
it "returns the class" do
|
285
|
-
m = Metadata.new
|
286
|
-
m.process(String)
|
287
|
-
|
288
|
-
expect(m[:example_group][key]).to be(String)
|
289
|
-
end
|
290
|
-
end
|
291
|
-
|
292
|
-
context "in a nested group" do
|
293
|
-
it "returns the parent group's described class" do
|
294
|
-
sm = Metadata.new
|
295
|
-
sm.process(String)
|
296
|
-
|
297
|
-
m = Metadata.new(sm)
|
298
|
-
m.process(Array)
|
299
|
-
|
300
|
-
expect(m[:example_group][key]).to be(String)
|
301
|
-
end
|
302
|
-
|
303
|
-
it "returns own described class if parent doesn't have one" do
|
304
|
-
sm = Metadata.new
|
305
|
-
sm.process("foo")
|
306
|
-
|
307
|
-
m = Metadata.new(sm)
|
308
|
-
m.process(Array)
|
309
|
-
|
310
|
-
expect(m[:example_group][key]).to be(Array)
|
311
|
-
end
|
312
|
-
|
313
|
-
it "can override a parent group's described class" do
|
314
|
-
parent = Metadata.new
|
315
|
-
parent.process(String)
|
316
|
-
|
317
|
-
child = Metadata.new(parent)
|
318
|
-
child.process(Fixnum)
|
319
|
-
child[:example_group][key] = Hash
|
320
|
-
|
321
|
-
grandchild = Metadata.new(child)
|
322
|
-
grandchild.process(Array)
|
323
|
-
|
324
|
-
expect(grandchild[:example_group][key]).to be(Hash)
|
325
|
-
expect(child[:example_group][key]).to be(Hash)
|
326
|
-
expect(parent[:example_group][key]).to be(String)
|
327
|
-
end
|
328
|
-
end
|
329
|
-
end
|
330
|
-
end
|
331
|
-
|
332
|
-
describe ":description" do
|
333
|
-
it "just has the example description" do
|
334
|
-
m = Metadata.new
|
335
|
-
m.process("group")
|
336
|
-
|
337
|
-
m = m.for_example("example", {})
|
338
|
-
expect(m[:description]).to eq("example")
|
339
|
-
end
|
340
|
-
|
341
|
-
context "with a string" do
|
342
|
-
it "provides the submitted description" do
|
343
|
-
m = Metadata.new
|
344
|
-
m.process("group")
|
345
|
-
|
346
|
-
expect(m[:example_group][:description]).to eq("group")
|
347
|
-
end
|
348
|
-
end
|
349
|
-
|
350
|
-
context "with a non-string" do
|
351
|
-
it "provides the submitted description" do
|
352
|
-
m = Metadata.new
|
353
|
-
m.process("group")
|
354
|
-
|
355
|
-
expect(m[:example_group][:description]).to eq("group")
|
356
|
-
end
|
357
|
-
end
|
358
|
-
|
359
|
-
context "with a non-string and a string" do
|
360
|
-
it "concats the args" do
|
361
|
-
m = Metadata.new
|
362
|
-
m.process(Object, 'group')
|
363
|
-
|
364
|
-
expect(m[:example_group][:description]).to eq("Object group")
|
365
|
-
end
|
366
|
-
end
|
367
|
-
|
368
|
-
context "with empty args" do
|
369
|
-
it "returns empty string for [:example_group][:description]" do
|
370
|
-
m = Metadata.new
|
371
|
-
m.process()
|
372
|
-
|
373
|
-
expect(m[:example_group][:description]).to eq("")
|
374
|
-
end
|
375
|
-
end
|
376
|
-
end
|
377
|
-
|
378
|
-
describe ":full_description" do
|
379
|
-
it "concats example group name and description" do
|
380
|
-
group_metadata = Metadata.new
|
381
|
-
group_metadata.process('group')
|
382
|
-
|
383
|
-
example_metadata = group_metadata.for_example("example", {})
|
384
|
-
expect(example_metadata[:full_description]).to eq("group example")
|
385
|
-
end
|
386
|
-
|
387
|
-
it "concats nested example group descriptions" do
|
388
|
-
parent = Metadata.new
|
389
|
-
parent.process('parent')
|
390
|
-
|
391
|
-
child = Metadata.new(parent)
|
392
|
-
child.process('child')
|
393
|
-
|
394
|
-
expect(child[:example_group][:full_description]).to eq("parent child")
|
395
|
-
expect(child.for_example('example', child)[:full_description]).to eq("parent child example")
|
396
|
-
end
|
397
|
-
|
398
|
-
it "concats nested example group descriptions three deep" do
|
399
|
-
grandparent = Metadata.new
|
400
|
-
grandparent.process('grandparent')
|
401
|
-
|
402
|
-
parent = Metadata.new(grandparent)
|
403
|
-
parent.process('parent')
|
404
|
-
|
405
|
-
child = Metadata.new(parent)
|
406
|
-
child.process('child')
|
407
|
-
|
408
|
-
expect(grandparent[:example_group][:full_description]).to eq("grandparent")
|
409
|
-
expect(parent[:example_group][:full_description]).to eq("grandparent parent")
|
410
|
-
expect(child[:example_group][:full_description]).to eq("grandparent parent child")
|
411
|
-
expect(child.for_example('example', child)[:full_description]).to eq("grandparent parent child example")
|
412
|
-
end
|
413
|
-
|
414
|
-
%w[# . ::].each do |char|
|
415
|
-
context "with a 2nd arg starting with #{char}" do
|
416
|
-
it "removes the space" do
|
417
|
-
m = Metadata.new
|
418
|
-
m.process(Array, "#{char}method")
|
419
|
-
expect(m[:example_group][:full_description]).to eq("Array#{char}method")
|
420
|
-
end
|
421
|
-
end
|
422
|
-
|
423
|
-
context "with a description starting with #{char} nested under a module" do
|
424
|
-
it "removes the space" do
|
425
|
-
parent = Metadata.new
|
426
|
-
parent.process(Object)
|
427
|
-
child = Metadata.new(parent)
|
428
|
-
child.process("#{char}method")
|
429
|
-
expect(child[:example_group][:full_description]).to eq("Object#{char}method")
|
430
|
-
end
|
431
|
-
end
|
432
|
-
|
433
|
-
context "with a description starting with #{char} nested under a context string" do
|
434
|
-
it "does not remove the space" do
|
435
|
-
grandparent = Metadata.new
|
436
|
-
grandparent.process(Array)
|
437
|
-
parent = Metadata.new(grandparent)
|
438
|
-
parent.process("with 2 items")
|
439
|
-
child = Metadata.new(parent)
|
440
|
-
child.process("#{char}method")
|
441
|
-
expect(child[:example_group][:full_description]).to eq("Array with 2 items #{char}method")
|
442
|
-
end
|
443
|
-
end
|
444
|
-
end
|
445
|
-
end
|
446
|
-
|
447
|
-
describe ":file_path" do
|
448
|
-
it "finds the first non-rspec lib file in the caller array" do
|
449
|
-
m = Metadata.new
|
450
|
-
m.process(:caller => [
|
451
|
-
"./lib/rspec/core/foo.rb",
|
452
|
-
"#{__FILE__}:#{__LINE__}"
|
453
|
-
])
|
454
|
-
expect(m[:example_group][:file_path]).to eq(relative_path(__FILE__))
|
455
|
-
end
|
456
|
-
end
|
457
|
-
|
458
|
-
describe ":line_number" do
|
459
|
-
it "finds the line number with the first non-rspec lib file in the backtrace" do
|
460
|
-
m = Metadata.new
|
461
|
-
m.process({})
|
462
|
-
expect(m[:example_group][:line_number]).to eq(__LINE__ - 1)
|
463
|
-
end
|
464
|
-
|
465
|
-
it "finds the line number with the first spec file with drive letter" do
|
466
|
-
m = Metadata.new
|
467
|
-
m.process(:caller => [ "C:/path/to/file_spec.rb:#{__LINE__}" ])
|
468
|
-
expect(m[:example_group][:line_number]).to eq(__LINE__ - 1)
|
469
|
-
end
|
470
|
-
|
471
|
-
it "uses the number after the first : for ruby 1.9" do
|
472
|
-
m = Metadata.new
|
473
|
-
m.process(:caller => [ "#{__FILE__}:#{__LINE__}:999" ])
|
474
|
-
expect(m[:example_group][:line_number]).to eq(__LINE__ - 1)
|
475
|
-
end
|
476
|
-
end
|
477
|
-
|
478
|
-
describe "child example group" do
|
479
|
-
it "nests the parent's example group metadata" do
|
480
|
-
parent = Metadata.new
|
481
|
-
parent.process(Object, 'parent')
|
482
|
-
|
483
|
-
child = Metadata.new(parent)
|
484
|
-
child.process()
|
485
|
-
|
486
|
-
expect(child[:example_group][:example_group]).to eq(parent[:example_group])
|
487
|
-
end
|
488
|
-
end
|
489
|
-
end
|
490
|
-
end
|
491
|
-
end
|